QuestionAsk Questions?

Soni Electric Company celebrates their 10th anniversary by having a special promotion for 2 weeks. Each customer who purchases any electrical equipments or components in a single receipt will get special discount according to the total amount they purchase. The discount rate will be given according to the indicator below:total purchase<500,discount rate=0%;total purchase>=500but<700,discount rate=5%;total purchase>=700but<1000,discount rate=7%;total purchase>1000,discount rate=10%

Total amount of payment is computed by this formula: Total Payment = Tâ?? T*(D/100) where T is the total purchase in RM and D is the discount rate in percent according the total amount purchased. Based on the above scenario, write a complete Java program. Your program should have two (2) classes namely, Purchase and PurchaseDemo class . Purchase class has three (3) methods. a. input() method reads a customer name and total purchased. b. calculateTotalPayment() method calculates the total payment c. display() method displays the name of customer, total purchased, discount rate and total payment.

Meanwhile, PurchaseDemo class only have main() method. main() method creates an object from Purchase class. It calls input() method to read a customer name and total purchased , then calculateTotalPayment() method calculates the total payment and display() method displays the name of customer, total purchased, discount rate and total payment.

View Answers

December 2, 2011 at 5:29 PM

import java.util.*; class Purchase { String name; double purchase; double drate; public void input(){ Scanner input=new Scanner(System.in); System.out.print("Enter Name: "); name=input.nextLine(); System.out.print("Total Purchase: "); purchase=input.nextDouble(); } public double calculateTotalPayment(){ if(purchase<500){ drate=0; } if(purchase>=500&&purchase<700){ drate=5; } if(purchase>=700&&purchase<1000){ drate=7; } if(purchase>1000){ drate=10; } double rate=drate/100; double discount=rate*purchase; double total=purchase-discount; return total; } public void display(double totalPayment){ System.out.println("Name: "+name); System.out.println("Purchase: "+purchase); System.out.println("Discount Rate: "+drate+"%"); System.out.println("Total Payment: "+totalPayment); } } class PurchaseDemo{ public static void main(String[] args) { Purchase p=new Purchase(); p.input(); double payment=p.calculateTotalPayment(); p.display(payment); } }

Related Tutorials/Questions & Answers: