Answer to Question #237303 in Java | JSP | JSF for due

Question #237303

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-15T00:10:46-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double total = 250;
        System.out.print("R/km: ");
        double perKilometre = in.nextDouble();
        System.out.print("km: ");
        double km = in.nextDouble();
        if (km < 60) {
            total += km * perKilometre + km * perKilometre * 0.03;
        } else if (km > 350) {
            total += km * perKilometre - km * perKilometre * 0.09;
        } else {
            total += km * perKilometre;
        }
        System.out.println("Total: " + total);
    }
}

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