I am having issues formatting my currency to 2 decimal places. I have tried this
ID: 3655989 • Letter: I
Question
I am having issues formatting my currency to 2 decimal places. I have tried this method and always receive errors: System.out.printf("Car Type: "+car1.getCarType()+", $"+"%1.2f",car1.getRentalRate()+" "); The rental rates and total should be 2 decimal places. Also, how can I convert the car types(1,2,3) to characters? 1=Compact Car 2= Mid-sized Car 3= Full size Car Here is my code: package userentalcar; /** * * @author Jay */ /** * * @author Bob */ public class RentalCar { int carType; double rentalRate; int numDays; int getCarType() { return carType; } double getRentalRate() { return rentalRate; } public RentalCar(int carType,int numDays) { this.carType = carType; if(carType == 1){ this.rentalRate = 69.95 * numDays; } else if(carType == 2){ this.rentalRate = 89.95* numDays; } else{ this.rentalRate = 99.99* numDays; } } } class Luxury extends RentalCar{ double Surcharge; double getSurcharge(){ return this.Surcharge; } public Luxury(int carType,int numDays){ super(carType,numDays); this.Surcharge = 40.00; } } _______________________________________________ package userentalcar; import java.util.Scanner; /** * * @author Jay */ public class UseRentalCar { public static void main(String[] args){ int numDays; System.out.println("Enter carType of car1: " + "(1) for Compact " + "(2) for Mid-sized " + "(3) for Full size "); Scanner my_input = new Scanner(System.in); int cartype = my_input.nextInt(); System.out.println("How many day do you need this rental?"); numDays = my_input.nextInt(); RentalCar car1 = new RentalCar(cartype,numDays); System.out.println("Enter carType of car2: " + "(1) for Compact " + "(2) for Mid-sized " + "(3) for Full size "); cartype = my_input.nextInt(); System.out.println("How many day do you need this rental?"); numDays = my_input.nextInt(); RentalCar car2 = new RentalCar(cartype,numDays); System.out.println("Enter carType of car3: " + "(1) for Compact " + "(2) for Mid-sized " + "(3) for Full size "); cartype = my_input.nextInt(); System.out.println("How many day do you need this rental?"); numDays = my_input.nextInt(); RentalCar car3 = new RentalCar(cartype,numDays); System.out.println("Enter carType of car4: " + "(1) for Compact " + "(2) for Mid-sized " + "(3) for Full size "); cartype = my_input.nextInt(); System.out.println("How many day do you need this rental?"); numDays = my_input.nextInt(); Luxury car4 = new Luxury(cartype,numDays); System.out.println("**********Recipt**********"); System.out.println("Note: Car Types: 1 = Compact, 2 = Mid-sized, 3 = Full size "); System.out.println("Car Type: "+car1.getCarType()+", $"+car1.getRentalRate()+" "); System.out.println("Car Type: "+car2.getCarType()+", $"+car2.getRentalRate()+" "); System.out.println("Car Type: "+car3.getCarType()+", $"+car3.getRentalRate()+" "); System.out.println("Car Type: "+car4.getCarType()+", $"+car4.getRentalRate()+" Surcharge: $" +car4.getSurcharge()+" "); double rentalTotal; rentalTotal = car1.getRentalRate()+car2.getRentalRate()+car3.getRentalRate() +car4.getRentalRate()+car4.getSurcharge(); System.out.println("Your total is: ----- $"+rentalTotal); } }Explanation / Answer
if you are having problem with posting question line by line then try to upload a photo of your question or contact zoe@chegg.com
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.