I need help creating this java program about Cars in Java Coding using programmi
ID: 3778683 • Letter: I
Question
I need help creating this java program about Cars in Java Coding using programming 1 commands because it will help me understanding the solution better. Thank you!
We need 3 classes named Car, CarRental, and RentalManager. RentalManager has main() which asks the user which make of car they’d like (e.g. Porsche or Ferrari), its daily rental rate, the start date (mm, dd, yyyy) and the # of days they’ll rent. Use input validation loops for all data (e.g., month > 0 && < 13). The app ends by printing a report confirming the data entered and cost (days * rate).
required
Set up any needed variables (you’ll come back and do this as you develop the rest of the logic)
Create the keyboard scanner
Ask the user to enter the name of the type of Car they would like (e.g., Porsche or Ferrari)
Ask the user to enter the daily rental rate, start date, and # of days for this rental (make sure the data is valid)
Create an instance of type Car
Create an instance of type CarRental
Display a little confirmation report of the rental info, including the cost
Explanation / Answer
import java.util.Scanner;
public class TestRentalCar {
public static void main(String[] args){
Scanner input = new Scanner (System.in);
String VIN;
String Make;
String Model;
char Classification;
double Rental;
int MileNum;
System.out.print("Enter the VIN number: ");
VIN = input.next();
System.out.print("Enter Make: ");
Make = input.next();
System.out.print("Enter Model: ");
Model = input.next();
System.out.print("Enter Classification; ");
Classification = input.next().charAt(0);
System.out.print("Enter Rental: ");
Rental = input.nextDouble();
System.out.print("Enter Miles: ");
MileNum = input.nextInt();
System.out.println();
RentalCar rentalCar1 = new RentalCar(VIN, Make, Model, Classification, Rental, MileNum);
RentalCar rentalCar2 = new RentalCar();
rentalCar1.print();
rentalCar1.setmiles(75);
System.out.println();
System.out.println("The number of miles of the car is: " + rentalCar1.getmiles());
System.exit(0);
}
class RentalCar {
private
String VIN;
String Make;
String Model;
char Classification;
double Rental;
int MileNum;
public
RentalCar(){}
RentalCar(String vin, String make, String model, char classification, double rental, int milenum) {
VIN = vin;
Make = make;
Model = model;
Classification = classification;
Rental = rental;
MileNum = milenum;
}
public void print() {
System.out.println("VIN of the car is: " + VIN);
System.out.println("Make of the car is: " + Make);
System.out.println("Model of the car is: " + Model);
System.out.println("Classification of the car is " + Classification);
System.out.println("Miles of the car is: " + MileNum);
}
public void setmiles(int milenum) {
MileNum = milenum;
}
public int getmiles() {
return MileNum;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.