Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package temp;
- import java.util.*;
- public class RujulCAT {
- public static void main(String[] args) {
- ArrayList<Invoice> invoices = new ArrayList<Invoice>();
- // Adding three invoices
- invoices.add(new Invoice("Part 1", "Desc 1", 12, 5.0));
- invoices.add(new Invoice("Part 2", "Desc 2", -1, 10.0));
- invoices.add(new Invoice("Part 3", "Desc 3", 20, -9.0));
- // Printing invoice amount
- for(Invoice i : invoices) {
- System.out.println("\nPart number: " + i.getPartNum() + "\nDescription: " + i.getDesc() + "\nQuantity:" + i.getQuantity() + "\nPrice Per item: " + i.getPricePerItem());
- System.out.println("Invoice Amount:" + i.getInvoiceAmount());
- }
- }
- }
- class Invoice{
- String partNum;
- String desc;
- int quantity;
- double pricePerItem;
- public Invoice(String partNum, String desc, int q, double p) {
- setPartNum(partNum);
- setDesc(desc);
- setQuantity(q);
- setPricePerItem(p);
- }
- public void setPartNum(String partNum) {
- this.partNum = partNum;
- }
- public void setDesc(String desc) {
- this.desc = desc;
- }
- public void setQuantity(int quantity) {
- if (quantity < 0) {
- this.quantity = 0;
- }
- else {
- this.quantity = quantity;
- }
- }
- public void setPricePerItem(double pricePerItem) {
- if (pricePerItem < 0) {
- this.pricePerItem = 0.0;
- }
- else {
- this.pricePerItem = pricePerItem;
- }
- }
- public String getPartNum() {
- return partNum;
- }
- public String getDesc() {
- return desc;
- }
- public int getQuantity() {
- return quantity;
- }
- public double getPricePerItem() {
- return pricePerItem;
- }
- public double getInvoiceAmount() {
- return quantity*pricePerItem;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement