Answer to Question #237323 in Java | JSP | JSF for FELLY

Question #237323

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:45:10-0400
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);
	}
}

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
APPROVED BY CLIENTS