Answer to Question #200580 in Java | JSP | JSF for Thabby

Question #200580

Sam runs a local musical equipment store in your neighbourhood. He has contracted you to create an interactive application that will assist him with customer purchases. Create a class named Customer Purchases that will contain get and set methods for a customer number, first name, surname, product, price and quantity. Create a separate class called Printing that will include a method called Print Details, that will print the Customer Invoice. In the Printing class include another method called Customer Purchase Report which will display the following information: REPORT OPTION PERCENTAGE TAX 15% COMMISSION 8.5% DISCOUNT 10% TOTAL (Price + Tax) – (Discount + Commission


1
Expert's answer
2021-05-30T07:11:15-0400
import java.util.Scanner;


class CustomerPurchases {
	// customer number, first name, surname, product, price and quantity.
	private String customerNumber;
	private String firstName;
	private String surname;
	private String product;
	private double price;
	private int quantity;


	// get and set methods for a customer number, first name, surname, product,
	// price and quantity.


	/**
	 * @return the customerNumber
	 */
	public String getCustomerNumber() {
		return customerNumber;
	}


	/**
	 * @param customerNumber the customerNumber to set
	 */
	public void setCustomerNumber(String customerNumber) {
		this.customerNumber = customerNumber;
	}


	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}


	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}


	/**
	 * @return the surname
	 */
	public String getSurname() {
		return surname;
	}


	/**
	 * @param surname the surname to set
	 */
	public void setSurname(String surname) {
		this.surname = surname;
	}


	/**
	 * @return the product
	 */
	public String getProduct() {
		return product;
	}


	/**
	 * @param product the product to set
	 */
	public void setProduct(String product) {
		this.product = product;
	}


	/**
	 * @return the price
	 */
	public double getPrice() {
		return price;
	}


	/**
	 * @param price the price to set
	 */
	public void setPrice(double price) {
		this.price = price;
	}


	/**
	 * @return the quantity
	 */
	public int getQuantity() {
		return quantity;
	}


	/**
	 * @param quantity the quantity to set
	 */
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
}


class Printing {
	private CustomerPurchases customerPurchases;


	/**
	 * Constructor
	 * 
	 * @param customerPurchases
	 */
	public Printing(CustomerPurchases customerPurchases) {
		this.customerPurchases = customerPurchases;
	}


	/**
	 * Print Details, that prints the Customer Invoice
	 */
	public void PrintDetails() {
		System.out.println("CUSTOMER INVOICE");
		System.out.println("***************************");
		System.out.println("CUSTOMER NUMBER: " + this.customerPurchases.getCustomerNumber());
		System.out.println("CUSTOMER FIRST NAME: " + this.customerPurchases.getFirstName());
		System.out.println("CUSTOMER SURNAME: " + this.customerPurchases.getSurname());
		System.out.println("PRODUCT PRICE: R " + String.format("%.2f", this.customerPurchases.getPrice()));
		System.out.println("PRODUCT QUANTITY: " + this.customerPurchases.getQuantity());
		System.out.println("***************************");
	}


	/**
	 * Method called Customer Purchase Report which will display the following
	 * information: REPORT OPTION PERCENTAGE TAX 15% COMMISSION 8.5% DISCOUNT 10%
	 * TOTAL (Price + Tax) – (Discount + Commission)
	 */
	public void CustomerPurchaseReport() {
		double productPrice = this.customerPurchases.getQuantity() * this.customerPurchases.getPrice();
		double tax=0.15*productPrice;
		double commission=0.085*productPrice;
		double discount=0.1*productPrice;
		double total=(productPrice + tax) - (discount + commission);
		System.out.println("\nCUSTOMER PURCHASE REPORT");
		System.out.println("***************************");
		System.out.println("PRODUCT PRICE: R " + String.format("%.2f", productPrice));
		System.out.println("TAX (15%): R " + String.format("%.2f", tax));
		System.out.println("COMMISSION (8.5% ): R " + String.format("%.2f", commission));
		System.out.println("DISCOUNT (10% ): R " + String.format("%.2f", discount));
		System.out.println("TOTAL: R " + String.format("%.2f", total));
		System.out.println("***************************");
	}
}


public class Q200580 {
	/**
	 * Main method
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		java.util.Locale.setDefault(new java.util.Locale("en-US", "en-US"));
		// Scanner object
		Scanner in = new Scanner(System.in);
		System.out.print("Enter the customer number: ");
		String customerNumber = in.nextLine();
		System.out.print("Enter the customer first name: ");
		String firstName = in.nextLine();
		System.out.print("Enter the customer surname: ");
		String surname = in.nextLine();
		System.out.print("Enter the customer product: ");
		String product = in.nextLine();
		System.out.print("Enter the customer price: ");
		double price = in.nextDouble();
		System.out.print("Enter the customer quantity: ");
		int quantity = in.nextInt();
		CustomerPurchases customerPurchases = new CustomerPurchases();
		customerPurchases.setCustomerNumber(customerNumber);
		customerPurchases.setFirstName(firstName);
		customerPurchases.setSurname(surname);
		customerPurchases.setProduct(product);
		customerPurchases.setPrice(price);
		customerPurchases.setQuantity(quantity);


		Printing printing = new Printing(customerPurchases);
		printing.PrintDetails();
		printing.CustomerPurchaseReport();


		// close Scanner
		in.close();
	}
}









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