I need help changing this java code from scanner input to ONLY JOptionPane for input and output. So meaning no import scanner should be in this code
only import JOptionPane should be in this code for input and output
import java.util.Scanner;
import javax.swing.JOptionPane;
public class CarMin {
public static void main(String[] args) {
/**
* For ever array, index
* 0: Hybrid
* 1: Coupe
* 2: Sedan
* 3: Minivan
*/
String[] vehicleName = {"Hybrid","Coupe","Sedan","Minivan"};
// Creating an array which stores bonus percentage
double[] bonusPercentage = {4,1.5,3,2.5};
// defining arrays to store number of vehicle sold, tital sales, total commission, average commission
int[] numberOfVehicleSold = new int[4];
double[] totalSales = new double[4];
double[] totalCommission = new double[4];
double[] avgCommission = new double[4];
// This loop initialises all the elements in the array with value 0
for(int i=0;i<>
{
numberOfVehicleSold[i] = 0;
totalSales[i] = 0;
totalCommission[i] = 0;
avgCommission[i] = 0;
}
// An integer variable to take vehicleType as input
int vehicleType;
// Using do while loop to take input until manager wants to quit
do{
// Asking for manager input and storing it in variable using scanner
System.out.print("Enter type of vehicle(1:Hybrid,2:Coupe,3:Sedan,4:SUV,5:QUIT): ");
Scanner scan = new Scanner(System.in);
vehicleType = scan.nextInt();
// If manager input is in range of 1-4, then it means manager has chosen a type of vehicle
if(vehicleType>0 && vehicleType<>
{
// A double variable to store price in it
double price;
// We use a do while loop to store the price
do{
// Asking price as input and storing it in price variable
System.out.print("Enter the price of vehicle sold: ");
price = scan.nextDouble();
// if price is less than or equals to 0, then we show an error message and ask manager to try again.
if(price<>
System.out.println("Price of vehicle can not be less tahn or equals to 0. Try again.");
// This loop keeps on taking input untill balue of price is less than or equals to 0.
}while(price<>
// NOTE: We are using vehicleType-1, since manager inputs between 1-4, but computer stores between 0-3
// We increase the number of vehicles for that type of vehicle by 1
numberOfVehicleSold[vehicleType-1]++;
// We increase the totalSales for that type of vehicle by sprice
totalSales[vehicleType-1] += price;
// We calculate commission for the type of vehicle and store it
double commission = (bonusPercentage[vehicleType-1]/100)*price;
// We print the value of totalCommission by commission calculated just now.
totalCommission[vehicleType-1] += commission;
// We calculate average commission for this type of vehicle
avgCommission[vehicleType-1] = totalCommission[vehicleType-1]/numberOfVehicleSold[vehicleType-1];
}
// If manager enters 5, then showing a quitting message and quitting
else if(vehicleType == 5)
System.out.println("Quitting");
// Else manager has entered an incorrect value, asing user to try again.
else
System.out.println("Incorrect input for type of car. Try again. ");
// This do while loop continues until manager given an input of 5, which means he wants to quit
}while(vehicleType!=5);
// Adding first two lines of the message dialog box
String output = "Type | # of sales | Total sales | Total commissions | Avg commissions" + "\n" +
// Using a for loop to add details of every type of vehicle details
for(int i=0;i<>
{
// Using String to format to specify number of spaces for each output value
output += "\n" + String.format("%-7s |",vehicleName[i])
+ String.format(" %-12s |",numberOfVehicleSold[i])
+ String.format(" $%-13s |",totalSales[i])
+ String.format(" $%-26s |",totalCommission[i])
+ String.format(" $%-10s",avgCommission[i]);
}
// Using JOptionPane to shown output in message dialog box
JOptionPane.showMessageDialog(null,output);
}
}