- Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBills.java
More file actions
Latest commit
70 lines (64 loc) · 1.9 KB
/
Copy pathBills.java
File metadata and controls
70 lines (64 loc) · 1.9 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
importjava.util.Scanner;
interfacecalc
{
voidcalculate();
}
classbillimplementscalc
{
Stringdate,name,p_id;
intquantity;
doubleunit_price,total,namount=0;
Scannersc = newScanner(System.in);
publicvoidgetdata()
{
System.out.print("\nEnter product id:");
p_id = sc.nextLine();
System.out.print("Enter product name:");
name = sc.nextLine();
System.out.print("Enter the Quantity:");
quantity = sc.nextInt();
System.out.print("Enter the unit price:");
unit_price = sc.nextDouble();
}
publicvoidcalculate()
{
total = quantity * unit_price;
}
publicvoiddisplay()
{ System.out.println(p_id+"\t\t"+name+"\t\t"+quantity+"\t\t"+unit_price+"\t"+total);
}
}
publicclassBills
{
publicstaticvoidmain(Stringargs[])
{
intn,i;
doublenamount=0,t;
intran;
Stringdate;
t = Math.random() *1000000;
ran = (int) t;
Scannersc = newScanner(System.in);
System.out.println("Order no. #"+ran);
System.out.print("Enter the date:");
date = sc.nextLine();
System.out.print("Enter how many products are there:");
n = sc.nextInt();
billob[] = newbill[n];
for(i=0;i<n;i++)
ob[i] = newbill();
for(i=0;i<n;i++){
ob[i].getdata();
ob[i].calculate();
}
System.out.println("Date:"+date);
System.out.println("Product Id \tName\t Quantity\t unit price\t Total ");
System.out.println("--------------------------------------------------------------");
for(i=0;i<n;i++){
ob[i].display();
namount += ob[i].total;
}
System.out.println("--------------------------------------------------------------");
System.out.println("\t\t\tNet.Amount\t"+ namount);
}
}