Answer to Question #236898 in Java | JSP | JSF for lethu

Question #236898

Ben rents a trailer to move his furniture to his new house. The basic cost is R250 per day plus a specific amount that must be entered by him per kilometre travelled. He also has to enter the distance travelled in kilometres.

If Ben travels less than 60 kilometres, an additional surcharge of 3% is payable on the amount due for distance. However, if he uses the trailer for more than 350 kilometres, he receives a discount of 9% on the amount due for distance (Pretorius & Erasmus, 2012:65).

Write a program to calculate and display the amount due.

Hint: use object oriented programming concepts to develop your program.




1
Expert's answer
2021-09-14T05:18:11-0400


package trailer;


import java.util.Scanner;


public class Trailer {
 private int basic_cost;
 private int distance;
 private double pricePerKm;
 public Trailer(int d, double km){
     basic_cost = 250;
     distance = d;
     pricePerKm = km;
 }
   void calculate_amount_due(){
       double amount=0;
       if(distance <60){
           
           amount = (pricePerKm * distance)+ basic_cost;
           amount = amount + 0.03;
       }
       else if(distance>350){
        amount = (pricePerKm * distance)+  basic_cost; 
        amount = amount - (amount * 0.09);
       }
       System.out.println("Amount due is:  "+ amount);
       
   } 
    public static void main(String[] args) {
        System.out.println("Enter price per km: ");
        Scanner scan = new Scanner(System.in);
        double price = scan.nextDouble();
        
        System.out.println("Enter the distance travelled: ");
        int d= scan.nextInt();
        Trailer t= new Trailer(d, price);
        t.calculate_amount_due();
        
    }
    
}

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