Page 296 - CA_Blue( J )_Class10
P. 296
vno = sc.nextInt();
System.out.print("Hours: ");
hours = sc.nextInt();
}
void calculate()
{
if(hours <= 1)
bill = 3.0;
else
bill = 3.0 + 1.5 * Math.ceil(hours - 1);
}
void display() {
System.out.println("Vehicle Number: " + vno);
System.out.println("Hours: " + hours);
System.out.println("Bill: Rs. " + bill);
}
public static void main(String args[])
{
ParkingLot obj = new ParkingLot();
obj.input();
obj.calculate();
obj.display();
}
}
17. Identify the statements listed below as assignment, increment, method invocation or object creation statements. [2014]
(i) System.out.println("Java"); (ii) costPrice = 457.50;
(iii) Car hybrid = new Car(); (iv) petrolPrice++;
Ans. (i) Method invocation (ii) Assignment
(iii) Object creation (iv) Increment
18. Consider the following class: [2014]
public class myClass{
public static int x = 3, y = 4;
public int a = 2, b = 3;
}
(i) Name the variables for which each object of the class will have its own distinct copy.
(ii) Name the variables that are common to all objects of the class.
Ans. (i) a and b (ii) x and y
19. Define a class named MovieMagic with the following description: [2014]
Instance variables/data members
int year : to store the year of release of a movie.
String title : to store the title of the movie.
float rating : to store the popularity rating of the movie (minimum rating = 0.0 and maximum rating = 5.0)
Member Methods
MovieMagic() : default constructor to initialize numeric data members to 0 and String data member to "".
void accept () : to input and store year, title and rating.
void display () : to display the title of a movie and a message based on the rating as per the table below:
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi-hit
3.5 to 4.5 Hit
4.6 to 5.0 Super Hit
Write a main method to create an object of the class and call the above member methods.
294294 Touchpad Computer Applications-X

