lab exam 5_5_15

2
LAB Exam SET A 1. Write a Java class named Bill to store information about bills. The UML representation of the class is shown below. The class contains: 4 private attributes: (.5 marks) o itemNo (string) : to store the item number s of the item in the bill. o qty (int): to store the quantity of the item. o itemPrice (double): to store the price of the item in the bill. o amount(double): to store the total amount of the bill A method readInfo() that initializes itemNo, qty , and itemPrice to values entered by the user.( 1 marks) A method calculateAmount () that calculates and returns the total amount of the bill.( ; total amount of the bill = qty*itemPrice.) (1 marks) Write another Java class called TestClass with a main() method that will create two Bill object, named bill1 and bill2. Test all methods of the class Bill in the main() method. (1 marks) 2. Fill the blanks to get given output (.5 marks for each blank) Bill - itemNo: String -qty: int -itemPrice:double - amount : double + Bill() + readInfo(): void + calculateAmount(): double

Upload: daman-toor

Post on 07-Aug-2015

381 views

Category:

Education


3 download

TRANSCRIPT

Page 1: Lab exam 5_5_15

LAB Exam SET A

1. Write a Java class named Bill to store information about bills. The UML representation of the class is shown below.

The class contains: 4 private attributes: (.5 marks)

o itemNo (string) : to store the item number s of the item in the bill.o qty (int): to store the quantity of the item.o itemPrice (double): to store the price of the item in the bill.o amount(double): to store the total amount of the bill

A method readInfo() that initializes itemNo, qty , and itemPrice to values entered by the user.( 1 marks)A method calculateAmount () that calculates and returns the total amount of the bill.( ; total amount of the bill = qty*itemPrice.) (1 marks)

Write another Java class called TestClass with a main() method that will create two Bill object, named bill1 and bill2. Test all methods of the class Bill in the main() method.

(1 marks)

2. Fill the blanks to get given output (.5 marks for each blank)

class Rowboat extends Boat{ public void rowTheBoat() { System.out.print("stroke natasha"); } }class Sailboat extends Boat {public void move() {System.out.println("hoist sail"); } }

class Boat {private int length;public void setLength ( int len ) {length = len;}public int getLength() {return length;}public void move ( ) {System. out. println("drift ");}}

public class TestBoats {public static void main(String[ ] args) { Boat bl = new Boat();Sailboat b2 = new Sailboat() ;// create the object of RowboatRowboat b3 = ____________;

b2.setLength(32);bl.move() ;b3._________ // use the object of Rowboat__________}}

Output : drift drift hoist sail

Bill

- itemNo: String-qty: int-itemPrice:double- amount : double+ Bill()+ readInfo(): void+ calculateAmount(): double

Page 2: Lab exam 5_5_15