Answer to Question #299473 in Java | JSP | JSF for Amy Lee

Question #299473

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

1
Expert's answer
2022-02-18T12:50:49-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 Number: " + itemNumber);
		System.out.println("Name: " + name);
		System.out.println("Quantity: " + quantity);
		System.out.println("Price: " + price);
		System.out.println("Total cost: " + totalCost);
	}
}


class App {


	public static void main(String[] args) {
		INVOICE iNVOICE = new INVOICE();
		iNVOICE.SETDATA("454512", "Item 4", 4, 40);
		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