Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
132 views

Lab Exercise (Programming)

This class defines an Exer object that can set and get item name and total cost attributes. It contains methods to set the item name and total cost based on quantity and price inputs, get the item name and calculate total cost, and read input and write output related to an item purchase including name, quantity, price, and amount due.

Uploaded by

Ashley Aquino
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views

Lab Exercise (Programming)

This class defines an Exer object that can set and get item name and total cost attributes. It contains methods to set the item name and total cost based on quantity and price inputs, get the item name and calculate total cost, and read input and write output related to an item purchase including name, quantity, price, and amount due.

Uploaded by

Ashley Aquino
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

public class Exer {

private String itemName;


private double itemPrice, amountDue;
private int itemQuantity;

public void setItemName(String newItemName) {


itemName = newItemName;
}

public void setTotalCost(int quantity, double price) {


itemPrice = price;
itemquantity = quantity;
}

public String getItemName() {


return itemName;
}

public double getTotalCost () {


amountDue = itemPrice * itemquantity;
return amountDue;
}

public void readInput () {


Scanner a = new Scanner(System.in);
System.out.println("Enter the name of the item you are purchasing.");
itemName = a.nextLine();

System.out.println("Enter the quality and price seperated by a space.");


itemquantity = a.nextInt();
itemPrice = a.nextDouble();
}

public void writeOutput() {


System.out.println("You are purchasing " + "(s) at" + itemPrice + "each.");
System.out.println("Amount due is" + amountDue);
}
}

You might also like