-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProducelist.java
More file actions
223 lines (128 loc) · 4.02 KB
/
Producelist.java
File metadata and controls
223 lines (128 loc) · 4.02 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import javax.swing.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Arrays;
public class Producelist {
public node first;
/**
* Default constructor
*/
public Producelist() {
first = new node();
}//default constructor
/**
* Creates a new LinkedList with a dummy node and
* another node with the input data.
*
* @param data, an integer
*/
public Producelist(ProduceItem data) {
first = new node();
first.setNext(new node(data));
}//one argument constructor
/**
* Creates a new node at the end of the Linked List.
*
* @param data, an integer
*/
public void append(ProduceItem data) {
node current = first;
while (current.getNext() != null)
current = current.getNext();
current.setNext(new node(data));
}//append
/**
* Creates a new node at the beginning of the Linked List.
*
* @param data, an integer
*/
public void prepend(ProduceItem data) {
first.setNext(new node(data, first.getNext()));
}//prepend
/**
* Prints the Linked List to the console.
*/
public void printList() {
node current = first.getNext();
while (current != null) {
System.out.print(current.getName() + " ");
current = current.getNext();
}//while
System.out.println();
}
/**
* getName accepts a String Parameter called code, which is used to check the ProduceList which is the LinkedList
* checks each node and returns a name.
*
* @param code code coordinate from transaction.txt
* @return Name back to Main to output array
*/
public String getName(String code) {
node current = first.getNext();
String name = null;
while (current != null) {
if (current.getCode().equals(code)) {
name = current.getName();
name= current.getData().getname();
}
current = current.getNext();
}
return name;
}
/**
* getPrice accepts a String Parameter called code, which is used to check the ProduceList which is the LinkedList
* checks each node and returns a price.
*
* @param code code coordinate from transaction.txt
* @return price back to Main to output array
*/
public float getPrice(String code) {
node current = first.getNext();
float price = 0;
while (current != null) {
if (current.getCode().equals(code)) {
price = current.getPrice();
}
current = current.getNext();
}
return price;
}
/**public String getType(String code) {
node current = first.getNext();
String type=null;
while (current != null) {
if (current.getCode().equals(code)) {
type = current.getType();
}
current = current.getNext();
}
return type;
}
public ArrayList<String> displayfruits (){
ArrayList<String> fruit = new ArrayList<>();
String t="F";
node current = first.getNext();
while (current != null) {
if (current.getType().equals(t)) {
String str = current.getType()+"\t"+current.getName()+"\t" + current.getPrice();
fruit.add(str);
}
current.getNext();
}
return fruit;
}
public ArrayList<String> displayveg(){
ArrayList<String> veg = new ArrayList<>();
String t="V";
node current = first.getNext();
while (current != null) {
if (current.getType().equals(t)) {
String str = current.getType()+"\t"+current.getName()+"\t" + current.getPrice();
veg.add(str);
}
current.getNext();
}
return veg;
}*/
}
//class