-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKitchenAppliance.java
More file actions
75 lines (67 loc) · 2.79 KB
/
Copy pathKitchenAppliance.java
File metadata and controls
75 lines (67 loc) · 2.79 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
import java.util.*;
import java.util.LinkedList;
public class KitchenAppliance
{
private String applianceCode; //KA100, KC22
private String applianceType; //oven,toaster,mixer
private double price;
private String colour; //grey, black, white, silver, red
//normal constructor
public KitchenAppliance(String code, String type, double p, String c) {
applianceCode = code;
applianceType = type;
price = p;
colour = c;
}
//accessor methods: getCode(), getType(), getPrice(), getColour()
public String getCode() {return applianceCode;}
public String getType() {return applianceType;}
public double getPrice() {return price;}
public String getColour() {return colour;}
//printer method: toString()
public String toString() {
return "\n\nAppliance Code: "+getCode()+"\nAppliance Type: "+getType()+"\nAppliance Colour: "+getColour()+"\nAppliance Price: "+getPrice();
}
public static void main(String[] args) {
LinkedList <KitchenAppliance> applianceLL = new LinkedList<>();
LinkedList <KitchenAppliance> ovenLL = new LinkedList<>();
LinkedList <KitchenAppliance> toasterLL = new LinkedList<>();
LinkedList <KitchenAppliance> mixerLL = new LinkedList<>();
LinkedList <KitchenAppliance> redMixerLL = new LinkedList<>();
String temp1, temp2, temp3;
double price=0;
Scanner sc = new Scanner(System.in);
Scanner num = new Scanner(System.in);
System.out.println("\nEnter 10 Appliances details:");
for(int i=0; i<10; i++) {
System.out.println("\nInsert Aplliance Code :");
temp1= sc.nextLine();
System.out.println("Insert Aplliance Type :");
temp2= sc.nextLine();
System.out.println("Insert Aplliance Colour :");
temp3= sc.nextLine();
System.out.println("Insert Aplliance Price :");
price= num.nextDouble();
KitchenAppliance temp = new KitchenAppliance(temp1, temp2, price, temp3);
applianceLL.add(temp);
}
for(int i=0; i<10; i++) {
if(applianceLL.get(i).getType().equalsIgnoreCase("oven"))
ovenLL.add(applianceLL.get(i));
else if(applianceLL.get(i).getType().equalsIgnoreCase("toaster"))
toasterLL.add(applianceLL.get(i));
else if(applianceLL.get(i).getType().equalsIgnoreCase("mixer"))
mixerLL.add(applianceLL.get(i));
}
for(int i=0; i<mixerLL.size(); i++) {
if(mixerLL.get(i).getColour().equalsIgnoreCase("Red"))
redMixerLL.add(mixerLL.get(i));
}
System.out.println("\nRed Mixer Appliances =-");
for(int i=0; i<redMixerLL.size(); i++) {
System.out.println(redMixerLL.get(i).toString());
}
sc.close();
num.close();
}
}