This repository was archived by the owner on May 22, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathItem.java
More file actions
87 lines (75 loc) · 2.32 KB
/
Copy pathItem.java
File metadata and controls
87 lines (75 loc) · 2.32 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
import java.util.Random;
public class Item {
public String name;
public int number;
public float cost;
public String description;
// Constructor for Item without parameters (default)
public Item() {
Random rand = new Random();
name = "";
number = rand.nextInt(1000);
cost = 0.0f;
description = "";
}
// Constructor for Item with name parameter
public Item(String inName) {
Random rand = new Random();
name = inName;
number = rand.nextInt(1000);
cost = 0.0f;
description = "";
}
// Constructor for Item with number parameter
public Item(int inNumber) {
name = "";
number = inNumber;
cost = 0.0f;
description = "";
}
// Constructor for Item with cost parameter
public Item(float inCost) {
Random rand = new Random();
name = "";
number = rand.nextInt(1000);
cost = inCost;
description = "";
}
// Constructor for Item with name and number parameters
public Item(String inName, int inNumber) {
name = inName;
number = inNumber;
cost = 0.0f;
description = "";
}
// Constructor for Item with name, number and cost parameters
public Item(String inName, int inNumber, float inCost) {
name = inName;
number = inNumber;
cost = inCost;
description = "";
}
// Constructor for Item with all parameters
public Item(String inName, int inNumber, float inCost, String inDescription) {
name = inName;
number = inNumber;
cost = inCost;
description = inDescription;
}
// Function that provides a string for the data contained in the object that is based as this class
public String toString() {
return "Name: " + name + " (" + number + "): $" + cost;
}
// Function that provides a string for the data contained in the object that is based as this class with the description
public String toStringWithDescription() {
return "Name: " + name + " (" + number + "): $" + cost + "\n\t" + description;
}
// Function to get the name of a Item
public String getName() {
return name;
}
// Function to get the number of a Item
public int getNumber() {
return number;
}
}