-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDonut.java
75 lines (62 loc) · 2.08 KB
/
Donut.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cafeCheckout;
import java.util.Scanner;
/**
* This is a Donut class which is a subclass of Timsproduct and implements the consumable
* interface
*
* @author Meet Patel
**/
public class Donut extends TimsProduct implements Consumable{
// description of the donut
private String description;
// calorie count of the donut
private int calorieCount;
// set the properties of the donut
private Donut(String name, String description, double cost, double price, int calories) {
super(name, cost, price);
this.description = description;
this.calorieCount = calories;
}
// creates an object of donut
public static Donut create() {
System.out.println(
"Please select your choice: \n" +
"1. Apple Fritter \n" +
"2. Chocolate Dip \n" +
"Your choice: "
);
// TODO: Fill in this stub to have a dialog with the user
Scanner sc = new Scanner(System.in);
int choice;
choice = sc.nextInt();
if(choice == 1) {
return new Donut("Apple Fritter","Apple flavoured donut", 1.50, 3.00, 200);
}
else if(choice == 2) {
return new Donut("Chocolate Dip","Chocolate flavoured donut", 1.50, 3.00, 200);
}
else {
System.out.println("Please choose correct option");
}
// and create a TimsOrder.
return null;
}
// return the description of the donut
public String getDescription() {
return description;
}
// return the calorie count
@Override
public int getCalorieCount() {
return calorieCount;
}
// return the consumption
public String getConsumptionMethod() {
return "Eatable";
}
// print string
@Override
public String toString() {
return "Donut: " + super.toString() + "Description: " + description + " Calorie count: " + calorieCount + "Consumption method: " + getConsumptionMethod();
}
}