Answer to Question #300760 in Java | JSP | JSF for Bella Wang

Question #300760

Create a class named INVOICE that contains fields for an item number, name, quantity, price, and total cost. Create instance methods that set the item name, quantity, and price. Whenever the price or quantity is set , recalculate the total (price times quantity ). Also include a DISPLAYLine() method that displays the item number, name, quantity, price for each INVOICE. Save the class as INVOICE.java


Sample output

item # : 111

Item name: chips

Quantity:2

Price: 1.00

Total Cost: 2.00


1
Expert's answer
2022-02-22T01:10:29-0500


class INVOICE {
	private String itemNumber;
	private String name;
	private int quantity;
	private double price;
	private double totalCost;


	public INVOICE() {
	}


	public void SETDATA(String itemNumber, String name, int quantity, double price) {
		this.itemNumber = itemNumber;
		this.name = name;
		this.quantity = quantity;
		this.price = price;
		this.totalCost = this.price * this.quantity;
	}


	public void DISPLAYLine() {
		System.out.println("Item #: " + itemNumber);
		System.out.println("Item name: " + name);
		System.out.println("Quantity: " + quantity);
		System.out.printf("Price: %.2f\n", price);
		System.out.printf("Total cost: %.2f\n\n", totalCost);
	}
}


class App {


	public static void main(String[] args) {
		INVOICE iNVOICE = new INVOICE();
		iNVOICE.SETDATA("111", "chips", 2, 1);
		iNVOICE.DISPLAYLine();


	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS