-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZeroDayAttack.java
74 lines (64 loc) · 1.94 KB
/
ZeroDayAttack.java
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
import java.util.Scanner;
public class ZeroDayAttack {
private int item_id;
private String item_name;
private int item_type;
private int item_quantity;
private double item_price;
void getDetails() {
System.out.println("Item ID : " + item_id);
System.out.println("Item Name : " + item_name);
System.out.println("Item Price : " + item_price);
System.out.println("Item Quantity : " + item_quantity);
System.out.println("Item Type : " + item_type);
}
void setDetails() {
Scanner in = new Scanner(System.in);
System.out.println("Enter Item Details : \n");
System.out.print("Enter Item ID : ");
item_id = in.nextInt();
System.out.print("Enter Item Name : ");
item_name = in.next();
System.out.print("Enter Item Type : ");
item_type = in.nextInt();
System.out.print("Enter Item Quantity : ");
item_quantity = in.nextInt();
System.out.print("Enter Item Price : ");
item_price = in.nextDouble();
in.close();
}
private double calculateTax(int type, double price) {
double tax = 0.0;
switch(type) {
case 1: tax = price * (0.05); break;
case 2: tax = price * (0.12); break;
case 3: tax = price * (0.18); break;
case 4: tax = price * (0.28); break;
default: tax = 0.0;
}
return tax;
}
void printInvoice() {
System.out.println("INVOICE : \n");
getDetails();
System.out.println("Tax : " + calculateTax(item_type, item_price));
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("How many items : ");
int n = in.nextInt();
ZeroDayAttack obj[] = new ZeroDayAttack[n];
for(int i = 0; i < n; i++) {
obj[i] = new ZeroDayAttack();
}
for(int i = 0; i < n; i++) {
System.out.println("Enter Item " + (i + 1) + " details : \n");
obj[i].setDetails();
}
for(int i = 0; i < n; i++) {
System.out.println("INVOICE " + (i + 1) + " details : \n");
obj[i].printInvoice();
}
in.close();
}
}