0% found this document useful (0 votes)
67 views5 pages

PRO192 Lab4

This document contains instructions to create a Java project with 3 packages - Q1, Q2, and Q3. Q1 involves creating a class to search for flights and hotels and book/cancel reservations. Q2 involves implementing a hierarchy of Sweets with classes like Candy, Lollipop, Cookie, and a Present class to add, filter, and get Sweets. Q3 involves an interface and test method to test devices with basic and advanced remotes. Sample test code is provided.

Uploaded by

Phúc Hồng
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)
67 views5 pages

PRO192 Lab4

This document contains instructions to create a Java project with 3 packages - Q1, Q2, and Q3. Q1 involves creating a class to search for flights and hotels and book/cancel reservations. Q2 involves implementing a hierarchy of Sweets with classes like Candy, Lollipop, Cookie, and a Present class to add, filter, and get Sweets. Q3 involves an interface and test method to test devices with basic and advanced remotes. Sample test code is provided.

Uploaded by

Phúc Hồng
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/ 5

PRO192_LAB4

Tạo project PRO192_MASV_LOP với 3 package Q1, Q2, và Q3 thực hiện:


 <package>Q1: Write a Java program to create a class with methods to search for
flights and hotels, and to book and cancel reservations.
Sample test:

 <package>Q2: Implement console program which will meet the following


requirements:
0. Implement a hierarchy of Sweets. All Sweets should have next properties:
name, weight and sugarWeight. Weight is a weight of the specific sweet in
kilograms. sugarWeight is a weight of sugar in this sweet in kilograms.

I don’t want to give you specific directions here to give you an opportunity
to decide what will work the best here to start describing the Sweet
hierarchy: an interface or an abstract class?

a. Candy, Lollipop and Cookie - three other types from Sweet hierarchy.

b. Create class Present. Present has next behavior:

// the method filters sweets by sugar weight inclusively


public Sweet[] filterSweetsBySugarRange(double minSugarWeight,
double maxSugarWeight) {
<write your code here>
}
// the method calculates total weight of the present
public double calculateTotalWeight() {
<write your code here>
}

// the method that adds sweet to the present


public void addSweet(Sweet sweet) {
<write your code here>
}

// the method returns copy of the Sweet[] array so that nobody could
// modify state of the present without addSweet() method.
// Also array shouldn’t contain null values.
public Sweet[] getSweets() {
<write your code here>
}

Sweet candy = new ChocolateCandy(); Sweet lollipop = new Lollipop();

candy.setName("Ritter Sport"); lollipop.setWeight(0.5);

candy.setSugarWeight(0.53); lollipop.setName("Lollipop");

candy.setWeight(0.05); lollipop.setSugarWeight(0.2);

Cookie cookie = new Oreo(); Present present = new Present();

cookie.setName("Milk Oreo"); present.addSweet(candy);

cookie.setSugarWeight(0.1); present.addSweet(cookie);

cookie.setDoughWeight(0.3); present.addSweet(lollipop);

cookie.setWeight(0.2);

Sample test:
 <package>Q3: Interface
testDevice() method
public static void testDevice(Device device) {

System.out.println("Tests with basic remote.");

BasicRemote basicRemote = new BasicRemote(device);

basicRemote.power();

device.printStatus();

System.out.println("Tests with advanced remote.");

AdvancedRemote advancedRemote = new AdvancedRemote(device);

advancedRemote.power();

advancedRemote.mute();

device.printStatus();

Sample test:

You might also like