-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBills.java
More file actions
70 lines (64 loc) · 1.9 KB
/
Bills.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
import java.util.Scanner;
interface calc
{
void calculate();
}
class bill implements calc
{
String date,name,p_id;
int quantity;
double unit_price,total,namount=0;
Scanner sc = new Scanner(System.in);
public void getdata()
{
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();
}
public void calculate()
{
total = quantity * unit_price;
}
public void display()
{ System.out.println(p_id+"\t\t"+name+"\t\t"+quantity+"\t\t"+unit_price+"\t"+total);
}
}
public class Bills
{
public static void main(String args[])
{
int n,i;
double namount=0,t;
int ran;
String date;
t = Math.random() *1000000;
ran = (int) t;
Scanner sc = new Scanner(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();
bill ob[] = new bill[n];
for(i=0;i<n;i++)
ob[i] = new bill();
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);
}
}