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);
int basic_cost=250;
int amount_per_km;
int distance_travelled;
System.out.println("Enter amount per kilometer: ");
amount_per_km=in.nextInt();
System.out.println("Enter distance travelled: ");
distance_travelled=in.nextInt();
int total=250+(amount_per_km*distance_travelled);
double amount=0;
if (distance_travelled<60)
amount=total+(0.03*total);
else if (distance_travelled>350)
amount=total-(0.09*total);
System.out.println("Amount = "+amount);
}
}
Comments
Leave a comment