-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaptopQueue.java
More file actions
82 lines (75 loc) · 2.98 KB
/
Copy pathLaptopQueue.java
File metadata and controls
82 lines (75 loc) · 2.98 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
import java.util.Scanner;
public class LaptopQueue {
private String brand; //Acer, Asus, Lenovo,etc
private String OS; //Operating system: Windows 8, Unix, etc
private double price;
private String colour; //black, white, silver, blue, etc
public LaptopQueue (String b, String o, double p, String c) {
brand = b;
OS = o;
price = p;
colour = c;
}
public String getBrand() { return brand;}
public String getOS() {return OS;}
public double getPrice() {return price;}
public String getColour() {return colour;}
public void setData(String b, String o, double p, String c) {
brand=b;
OS=o;
price=p;
colour=c;
}
public String toString() {return "\n\nLaptop brand : "+getBrand()+"\nOperating System : "+getOS()+"\nPrice : "+getPrice()+"\nColour : "+getColour();}
public static void main(String[] args) {
Queue LaptopQ = new Queue();
Queue WindowsQ = new Queue();
Queue tempQ = new Queue();
Queue unixQ = new Queue();
Scanner sc = new Scanner(System.in);
Scanner num = new Scanner(System.in);
String brand, OS, colour;
double price;
int count=0;
int total=0;
for(int i=0; i<5; i++) {
System.out.println("\nInsert the brand of Laptop : ");
brand = sc.nextLine();
System.out.println("The Operating System used : ");
OS = sc.nextLine();
System.out.println("Price of Laptop : ");
price = num.nextDouble();
System.out.println("Colour : ");
colour = sc.nextLine();
LaptopQueue lq = new LaptopQueue(brand, OS, price, colour);
LaptopQ.enqueue(lq);
}
while(!LaptopQ.isEmpty()) {
LaptopQueue temp = (LaptopQueue) LaptopQ.dequeue();
if(temp.getOS().equalsIgnoreCase("Unix"))
unixQ.enqueue(temp);
else if(temp.getOS().equalsIgnoreCase("Windows"))
WindowsQ.enqueue(temp);
}
System.out.println("\nList of Silver Asus laptops that uses Windows OS.");
while(!WindowsQ.isEmpty()) {
LaptopQueue temp = (LaptopQueue) WindowsQ.dequeue();
if(temp.getBrand().equalsIgnoreCase("Asus") && temp.getColour().equalsIgnoreCase("Silver")) {
temp.toString();
count++;
}
}
System.out.println("\nThere are "+count+" total of Silver Asus laptops that uses Windows OS.");
while(!unixQ.isEmpty()) {
LaptopQueue temp = (LaptopQueue) unixQ.dequeue();
if(temp.getColour().equalsIgnoreCase("Black")) {
temp.toString();
total+=temp.getPrice();
}
tempQ.enqueue(temp);
}
System.out.println("\nTotal price of all Unix based laptos is RM"+total);
sc.close();
num.close();
}
}