-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoiceTest.java
More file actions
42 lines (31 loc) · 1.06 KB
/
InvoiceTest.java
File metadata and controls
42 lines (31 loc) · 1.06 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
import java.util.Scanner;
class Invoice {
String partNumber;
String partDescription;
int quantity;
double pricePerItem;
Invoice(String pNo, String pDesc, int qty, double price) {
partNumber = pNo;
partDescription = pDesc;
quantity = (qty > 0) ? qty : 0;
pricePerItem = (price > 0) ? price : 0.0;
}
double getInvoiceAmount() {
return quantity * pricePerItem;
}
}
public class InvoiceTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Part Number: ");
String pNo = sc.nextLine();
System.out.print("Enter Description: ");
String desc = sc.nextLine();
System.out.print("Enter Quantity: ");
int qty = sc.nextInt();
System.out.print("Enter Price per Item: ");
double price = sc.nextDouble();
Invoice i = new Invoice(pNo, desc, qty, price);
System.out.println("\nInvoice Amount = " + i.getInvoiceAmount());
}
}