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
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);
}
}
Comments
Leave a comment