0% found this document useful (0 votes)
6 views1 page

(3 Marks) Coffee Speccoffee Coffee Coffee

The document outlines the requirements for creating a Coffee class and a SpecCoffee subclass in a programming context. The Coffee class includes attributes for name and size, with methods for getting and setting these values, while the SpecCoffee class adds a price attribute and additional methods for modifying the name and calculating the value based on size. The document also provides an example of expected program output based on user input and method tests.

Uploaded by

dungga2103
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

(3 Marks) Coffee Speccoffee Coffee Coffee

The document outlines the requirements for creating a Coffee class and a SpecCoffee subclass in a programming context. The Coffee class includes attributes for name and size, with methods for getting and setting these values, while the SpecCoffee class adds a price attribute and additional methods for modifying the name and calculating the value based on size. The document also provides an example of expected program output based on user input and method tests.

Uploaded by

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

(3 marks) Write a class Coffee and a class SpecCoffee extending from Coffee (i.e.

Coffee is a superclass
and SpecCoffee is a subclass) with the following information:
Coffee Where:
-name:String  getName():String – return name.
-size:int  getSize():int – return size.
 setName(name:String):void – update name.
+Coffee()
+Coffee(name:String, size:int)  toString():String – return the string of format:
+getName():String name, size
+getSize():int
+setName(name:String):void
+toString():String
Where:
SpecCoffee  toString():String – return the string of
-price:int format:
name, size, price
+SpecCoffee()  setData():void – Insert the string "CF" at
+SpecCoffee(name:String, size:int, price:int) the end of name.
+toString():String  getValue():int – Check if the size < 10
+setData():void then return price, otherwise return
+getValue():int price+5.

The program output might look something like:


Enter name: vietnam Enter name: vietnam Enter name: vietnam Enter name: vietnam
Enter size: 2 Enter size: 2 Enter size: 4 Enter size: 10
Enter price: 12 Enter price: 12 Enter price: 12 Enter price: 12
1. Test toString() 1. Test toString() 1. Test toString() 1. Test toString()
2. Test setData() 2. Test setData() 2. Test setData() 2. Test setData()
3. Test getValue() 3. Test getValue() 3. Test getValue() 3. Test getValue()
Enter TC (1,2,3): 1 Enter TC (1,2,3): 2 Enter TC (1,2,3): 3 Enter TC (1,2,3): 3
OUTPUT: OUTPUT: OUTPUT: OUTPUT:
vietnam, 2 vietnamCF, 2 12 17
vietnam, 2, 12

You might also like