Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

alter the following class by adding random vehicle make with the following vehic

ID: 3634599 • Letter: A

Question

alter the following class by adding random vehicle make with the following vehicles.

*toyota, mazda, nissan, ford, chevrolet, dodge, volvo, bmw, porsche

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

import java.util.Random;
import java.util.Scanner;
public class Customer
{
private String carTag;
private double gasPurchased;
private int gasType;

public Customer ()
{
Random gen = new Random ( );
carTag = "";
for (int i = 1; i <= 6; i++)
{

//a random number between 48 and 90
int code = gen.nextInt (43)+ 48;
if ((code <= 64) && (code >= 58))
{
i--;
continue;
}

carTag += ((char)(code));

}

System.out.println ("a car arrives; tag number:" + carTag);

}

public int getGasType ()
{
Scanner inputDevice = new Scanner (System.in);
//1:regular, 2:plus, 3:premium
System.out.println ("enter type of gas to buy " +
"(1:regular, 2:plus, 3:premium): ");
gasType = inputDevice.nextInt ();
return gasType;

}

public double getGasPurchased ()
{
Random gen = new Random ();
gasPurchased = gen.nextDouble ()* 50;
return gasPurchased;
}

public String getCarTag ()
{
return carTag;
}


}

Explanation / Answer

public class Customer
{
public static final String[] CAR_MAKE = new String[]{"toyota", "mazda", "nissan", "ford", "chevrolet", "dodge", "volvo", "bmw", "porsche"};
private String carMake;

...

public Customer()
{
// set carMake to random element of CAR_MAKE
carMake = CAR_MAKE[(int)(Math.random()*CAR_MAKE.length)];

...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote