0% found this document useful (0 votes)
14 views3 pages

Document

Uploaded by

m.anindita020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Document

Uploaded by

m.anindita020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1)

import java.util.*;

class movieMagic

int year; String title; float rating; //these are data members or variables of class

movieMagic() // default constructor begins

year =0; rating=0.0f; title=""; // data members are initializes here

void accept( ) // function begins here

Scanner sc=new Scanner(System.in); //making scanner

System.out.print("Enter the title of the movie : ");

title = sc.nextLine();

System.out.print("Enter the year of its release : ");

year = sc.nextInt();

System.out.print("Enter the movie rating : ");

rating= sc.nextFloat();

}// function accept() ends here

void display()// function starts here

System.out.println("The name of the movie is : "+title);

if (rating >= 0.0 && rating <= 2.0 )

System.out.println(" Flop");

else if (rating >= 2.1 && rating <= 3.4)

System.out.println("Semi-hit");

else if (rating >= 3.5 && rating <= 4.5 )

System.out.println(" Hit");

else // this is the condition if ( rating >= 4.6 && rating <= 5.0 )
System.out.println("Super Hit");

}//function display ends here

public static void main() // the main function starts here

movieMagic obj = new movieMagic() ; // creating or making object 'obj' of the class movie Magic

obj.accept(); // calling function of the class to input data

obj.display();// calling function of the class to decide the status and print data

}// end of function main()

}// end of class

2)

import java.io.*;

class overloadArea

//following function find and returns area of a scalene triangle

double area(double a, double b, double c )

{ // this is 1st overloaded function

double s = (a+b+c)/2;

double Area= Math.sqrt(s*(s-a)*(s-b)*(s-c));

return Area;

}//end of 1st overloaded function area()

//following function find and returns area of a trapezium

double area( int a, int b, int height ) // this is 2nd overloaded function

return( (double)(height * (a + b) ) /2 ); //see that the return type is 'double' so type casting is must

}//end of 2nd overloaded function area()


//following function find and returns area of a rhombus

double area( double diagonal1, double diagonal2 ) // this is 3rd overloaded function

double Area= ( diagonal1*diagonal2) / 2; //you may also write: return (( diagonal 1 * diagonal 2) / 2 );

return Area;

//end of 3rdoverloaded function area()

// The main() function starts below. You may OMIT this because as per the question the main() is NOT
needed

public void main()

double Area_triangle= area(15.0, 12.0, 8.0); //calling 1st overloaded function

double Area_trapiziun= area( 10, 7, 11); //calling 2ndoverloaded function

double Area_rhombus= area(21.0, 27.0); //calling 3rd overloaded function

System.out.println("Area of a scalene triangle: " +Area_triangle);

System.out.println("Area of a trapezium: " +Area_trapiziun);

System.out.println("Area of a rhombus: " +Area_rhombus);

}//end of main( ) function

}//end of class

You might also like