-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnack.java
More file actions
74 lines (57 loc) · 1.15 KB
/
Snack.java
File metadata and controls
74 lines (57 loc) · 1.15 KB
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
/*
* Matthew Homan
* Assignment 2: Inheritance and Encapsulation
* April 11, 2023
* CMIS 242 7382
* Spring 2023
*
* This program allows a user to order a salty or fruit snack and choose from additional options.
* It then calculates the price and displays the order.
*
*/
public class Snack {
private String id;
private String size;
private double price;
final double S = 19.99;
final double M = 29.99;
final double L = 39.99;
final double CITRUS = 5.99;
final double NUT = 4.50;
public Snack(String id, String size) {
this.id = id;
this.size = size;
switch (size) {
case "S":
setPrice(S);
break;
case "M":
setPrice(M);
break;
case "L":
setPrice(L);
break;
}
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String toString () {
return "type = " + size + " ID = " + id + " and price = $" + String.format("%.2f", price) + "\n";
}
}