-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFruit.java
More file actions
115 lines (95 loc) · 2.94 KB
/
Fruit.java
File metadata and controls
115 lines (95 loc) · 2.94 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Author: Ryan Smith
* Date: 3/13/2026
* Section: CSC 311-002
*/
public class Fruit extends FoodItem {
// Does the fruit have a peel?
private boolean hasPeel;
// Is the fruit sweet?
private boolean isSweet;
// What shape is the fruit?
private String shape;
/**
* Initialize new instance of food item
* @param itemID
* @param price
* @param quantity
* @param calories
* @param expirationDate
* @param color
* @param hasSeeds
* @param hasPeel
* @param isSweet
* @param shape
*/
public Fruit(int itemID, String name, double price, int quantity, int calories,
double expirationDate, String color, boolean hasSeeds, boolean hasPeel,
boolean isSweet, String shape){
//call constructor of food item
super(itemID, name, price, quantity, calories, expirationDate, color, hasSeeds);
this.shape = shape;
this.hasPeel = hasPeel;
this.isSweet = isSweet;
}
//Accessors
/**
* Accessor for hasPeel
* @return hasPeel
*/
public boolean getHasPeel() {return hasPeel;}
/**
* Accessor for isSweet
* @return isSweet
*/
public boolean getIsSweet() {return isSweet;}
/**
* Accessor for shape
* @return shape
*/
public String getShape() {return shape;}
//Mutator
/**
* Mutator for hasPeel
* @param hasPeel
*/
public void setHasPeel(boolean hasPeel) {this.hasPeel = hasPeel;}
/**
* Mutator for isSweet
* @param isSweet
*/
public void setIsSweet(boolean isSweet) {this.isSweet = isSweet;}
/**
* Mutator for Shape
* @param shape
*/
public void setShape(String shape) {this.shape = shape;}
/**
* Creates string to represent a fruit item with attributes:
* itemID
* price
* quantity
* calories
* expirationDate
* color
* hasSeeds
* hasPeel
* isSweet
* shape
*/
@Override
public String toString() {
return String.format("ItemID: %d| Name: %s| Price: %.2f| Quantity: %d| Calories: %d| Expiration Date: %f| Color: %s|vHas Seeds? %b| Has Peel? %b| Is Sweet? %b| Shape: %s",
getItemID(), getName(), getPrice(), getQuantity(), getCalories(), getExpirationDate(), getColor(), getHasSeeds(), getHasPeel(), getIsSweet(), getShape());
// return "ItemId: " + this.getItemID() +
// "\nPrice: " + this.getPrice() +
// "\nQuantity: " + this.getQuantity() +
// "\nCalories: " + this.getCalories() +
// "\nExpiration Date: " + this.getExpirationDate() +
// "\nColor: " + this.getColor() +
// "\nHas Seeds: " + this.getHasSeeds() +
// "\nHas Peel: " + this.getHasPeel() +
// "\nIs Sweet: " + this.getIsSweet() +
// "\nShape: " + this.getShape();
}
}