Brittney P.

asked • 08/22/21

Not able to print the first element in an array (Inputed by user)

I am trying to print the types of vehicles that are being rented. The issue I'm currently having is that the print statement only prints the second type of input from the user.


Here I have the do loop where the user inputs the number of vehicles that they are renting. They rent less than 3 vehicles, which is what IsValidVehicleNumber(numOfVehicles) checks for. I created a new array that will then store what was inputed (either motorbike, car, or trailer). That array is vehicleTypes[].

I created ANOTHER array that store the properties of each of those vehicles inputted.


//Ask user how many vehicles are being rented

do {

System.out.println("Number of vehicles you are renting: ");

numOfVehicles = ReadIntegerFromUser();

}while(IsValidVehicleNumber(numOfVehicles) == false);

//Here is where we begin the final part of the program:

vehicleTypes = new String[numOfVehicles];

vehicleRentedArry = new CVehicle[numOfVehicles];


I think this part makes sense. So, just to walk through some of it.... this will take the inputs and place them into the vehicleTypes array if they equal certain inputs.



for(int i = 0; i < vehicleTypes.length; i++) {

System.out.println("What vehicle type would you like? Motorbike, trailer, or car?: ");

vehicleType = ReadStringFromUser();

if((vehicleType.equalsIgnoreCase("Motorbike")) || (vehicleType.equalsIgnoreCase("Trailer")) || (vehicleType.equalsIgnoreCase("Car"))) {

vehicleTypes[i] = vehicleType;

for(int j = 0; j < vehicleRentedArry.length; j++) {

if(vehicleType.equalsIgnoreCase("Motorbike")) {

CMotorbike motorbikeOption = new CMotorbike();

motorbikeOption.SetMethods("Handle Bars", 35, 2);

vehicleRentedArry[j] = motorbikeOption;

}else if(vehicleType.equalsIgnoreCase("car")) {

CCar carOption = new CCar();

carOption.SetMethods("Steering Wheel", 25, 4);

vehicleRentedArry[j] = carOption;

}else if(vehicleType.equalsIgnoreCase("Trailer")) {

CTrailer trailerOption = new CTrailer();

trailerOption.SetMethods("Use Another Vehicle", 0, 6);

vehicleRentedArry[j] = trailerOption;

}

}

}

}

//Calculate the rates

dailyRates = CalculateDailyRates(vehicleTypes, numOfVehicles, numOfDays);

//Check if rates appear correctly

for(int k = 0; k < dailyRates.length; k++) {

totalRentalSale += dailyRates[k];

//Adding tax to that:

totalRentalSale = totalRentalSale *1.06f;


}

This is the print part of the project. The concern is specifically the actual result I get.


//Printing the outputs:

System.out.println("** Order Confirmation **");

System.out.printf("----------------------------------------------------------------------\n");

System.out.printf("Customer Name: \t\t\t\t%s %s\n", strFirstName, strLastName);

System.out.printf("Phone Number: \t\t\t\t%s\n", strPhoneNumber);

System.out.printf("Email: \t\t\t\t\t%s\n", strEmail);

System.out.printf("----------------------------------------------------------------------\n");

System.out.println("** Details about Rental **");

System.out.printf("----------------------------------------------------------------------\n");

System.out.printf("Type of Vehicle: \t\t\t");

for(int intIndex = 0; intIndex < vehicleRentedArry.length; intIndex++) {

System.out.println("Try this: " + vehicleRentedArry[0].getVehicleType());

}



******HERE IS WHERE I HAVE A PROBLEM*************

For the vehicle type, it is only printing the second input and not the first AND second. I want it to have the first input on the same line as "type of vehicle" and the second input below the first. To be clear, this is what is shown in my console.


Let's see if your inputs are valid!

-----------------------------------------------

Enter QUIT at anytime to exit.


First Name of Renter: John

Last Name of Renter: Smith

What phone number is best to get in contact? Use format '###-###-####' or '##########': 123-456-7890

Renter's Email: [email protected]

When would you like to pick-up the vehicle? Use format MM-DD-YYYY or MM/DD/YYYY: 12-12-2021

Number of days you are renting: 1

Number of vehicles you are renting:

2

What vehicle type would you like? Motorbike, trailer, or car?:

Car

What vehicle type would you like? Motorbike, trailer, or car?:

Trailer

** Order Confirmation **

----------------------------------------------------------------------

Customer Name: John Smith

Phone Number: 123-456-7890

Email: [email protected]

----------------------------------------------------------------------

** Details about Rental **

----------------------------------------------------------------------

Type of Vehicle: Try this: Trailer

Try this: Trailer



1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.