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

Java Task: LOOK TO BUILD THE PROGRAM USING MULTIPLE CLASSES AND METHOD OVERLOADI

ID: 3779314 • Letter: J

Question

Java Task: LOOK TO BUILD THE PROGRAM USING MULTIPLE CLASSES AND METHOD OVERLOADING TO ACCOMPLISH THE FOLLOWING EXERCISE.

Build seperate classes for each type of vehicle.

Build multiple methods that accept different argument types.

Create a do-while loop / with switch case statements that operate the program.

You will have multi-level menu operation using do-while implementation.

Present the user with a menu and options. Based upon the options selected by the user the program should operate correctly. You will need nested menu’s of some sort.

Create a computer program that will calculate the range for 3 different vehicles.

The program should create a “programmer created” class, where 3 int class/instance variables are created passengers, fuel capacity, mpg.

Set-up the program so the user can manually input the values for passengers, fuel capacity, mpg for the 3 created vehicles.

Use programming conventions void set() methods to set values, return get() methods to return values.

Think about where in the program in object creation will take place.

range = fuel capacity * miles per gallon.

Each Vehicle type should have unique values for number of passengers, fuel capacity, and miles per gallon.

Attach Snipping photos as the program operates, including menu prompts, outputs etc.

Thank you

Sample Output: // Create similar output for 3 Vehicle Types

On next page-

Change input values now that we are creating the same program multiple times.

**************************************

* Main Menu:                                                       *

*    Enter # to run program or Quit                   *

*    1) Minivan                                                       *

*    2) Hybrid                                                          *

*    3) Sports Car                                                   *

*    4) Quit                                                              *

**************************************

1

You Selected Option 1:

Minivan

**************************************

* Minivan Main Menu:                                        *

*    Enter # to run program or Quit                   *

*    1) Enter Fuel Capacity                                   *

*    2) Enter Miles Per Gallon                             *

*    3) Calculate Range                                         *

*    4) Return To Main Menu                              *

**************************************

You Selected Option 1:

Enter fuel capacity in Integers Please

15

You entered: 15

**************************************

*    Minivan Menu:                                                *

*    Enter # to run program or Quit                    *

*    1) Enter Fuel Capacity                                    *

*    2) Enter Miles Per Gallon                              *

*    3) Calculate Range                                         *

*    4) Return To Main Menu                              *

**************************************

You Selected Option 3:

You cannot calculate range without entering both Fuel Cap and Miles Per Gallon

**************************************

*    Minivan Menu:                                                *

*    Enter # to run program or Quit                    *

*    1) Enter Fuel Capacity                                    *

*    2) Enter Miles Per Gallon                              *

*    3) Calculate Range                                         *

*    4) Return To Main Menu                              *

**************************************

You Selected Option 2:

Enter Miles Per Gallon in Integers Please

30

You entered: 30

**************************************

*    Minivan Menu:                                                *

*    Enter # to run program or Quit                    *

*    1) Enter Fuel Capacity                                    *

*    2) Enter Miles Per Gallon                              *

*    3) Calculate Range                                         *

*    4) Return To Main Menu                              *

**************************************

You Selected Option 3:

Range = 450

**************************************

*    Minivan Menu:                                                *

*    Enter # to run program or Quit                    *

*    1) Minivan                                                        *

*    2) Enter Miles Per Gallon                              *

*    3) Calculate Range                                         *

*    4) Return To Main Menu                              *

**************************************

Explanation / Answer

import java.io.*;


class Minivan
{
static int passengers, fuelcapacity, mpg,range;


void setpassengers(int pass)
{
passengers=pass;
}

int getpassengers()
{

return passengers;
}

void setfuelcapacity(int fc)
{

fuelcapacity=fc;

}


int getfuelcapacity()
{

return fuelcapacity;

}

void setmpg(int mg)
{
mpg=mg;

}

int getmpg()
{
return mpg;

}


}// end

class Hybrid
{
int passengers, fuelcapacity, mpg;


void setpassengers(int pass)
{
passengers=pass;
}

int getpassengers()
{

return passengers;
}

void setfuelcapacity(int fc)
{

fuelcapacity=fc;

}


int getfuelcapacity()
{

return fuelcapacity;

}

void setmpg(int mg)
{
mpg=mg;

}

int getmpg()
{
return mpg;

}


}//end

class SportsCar
{
int passengers, fuelcapacity, mpg;


void setpassengers(int pass)
{
passengers=pass;
}

int getpassengers()
{

return passengers;
}

void setfuelcapacity(int fc)
{

fuelcapacity=fc;

}


int getfuelcapacity()
{

return fuelcapacity;

}

void setmpg(int mg)
{
mpg=mg;

}

int getmpg()
{
return mpg;

}

}//end


class vehicle
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


do
{
System.out.println(" Main Menu: ");
System.out.println("Enter # to run program or Quit ");
System.out.println(" 1) Minivan ");
System.out.println(" 2) Hybrid ");
System.out.println(" 3) Sports Car ");
System.out.println(" 4) Quit ");
String option=br.readLine();
switch(option)
{
case "1":
do
{
Minivan obj1=new Minivan();
System.out.println(" Minivan Main Menu");
System.out.println("Enter # to run program or Quit ");
System.out.println(" 1)Enter fuel capacity");
System.out.println(" 2) Enter Miles Per Gallon ");
System.out.println(" 3) Calculate Range ");
System.out.println(" 4) Return To Main Menu ");
String option=br.readLine();

switch(option)
{
case "1":
System.out.println("Enter fuel capacity in Integers Please ");
int fc;
fc=Integer.parseInt(br.readLine());
obj1.setfuelcapacity(fc);

break;
case "2":
System.out.println("Enter Miles Per Gallon in Integers Please ");
int mpg;
mpg=Integer.parseInt(br.readLine());
obj1.setmpg(mpg);
break;
case "3":
System.out.println("You Selected Option 3:");
range=obj1.getfuelcapacity()*obj2.getmpg();
break;   
case "4":

break;
}
}while(true);//minivan end

case "2":
System.out.println(" 2) Hybrid ");

do
{
Hybrid obj2=new Hybrid();
System.out.println(" Hybrid Main Menu");
System.out.println("Enter # to run program or Quit ");
System.out.println(" 1)Enter fuel capacity");
System.out.println(" 2) Enter Miles Per Gallon ");
System.out.println(" 3) Calculate Range ");
System.out.println(" 4) Return To Main Menu ");
String option=br.readLine();

switch(option)
{
case "1":
System.out.println("Enter fuel capacity in Integers Please ");
int fc;
fc=Integer.parseInt(br.readLine());
obj2.setfuelcapacity(fc);

break;
case "2":
System.out.println("Enter Miles Per Gallon in Integers Please ");
int mpg;
mpg=Integer.parseInt(br.readLine());
obj2.setmpg(mpg);
break;
case "3":
System.out.println("You Selected Option 3:");
range=obj2.getfuelcapacity()*obj2.getmpg();
break;   
case "4":

break;
}
}while(true);//hybrid end


break;

case "3":
System.out.println(" 3) Sports Car ");

do
{
Hybrid obj3=new Hybrid();
System.out.println(" Sports car Main Menu");
System.out.println("Enter # to run program or Quit ");
System.out.println(" 1)Enter fuel capacity");
System.out.println(" 2) Enter Miles Per Gallon ");
System.out.println(" 3) Calculate Range ");
System.out.println(" 4) Return To Main Menu ");
String option=br.readLine();

switch(option)
{
case "1":
System.out.println("Enter fuel capacity in Integers Please ");
int fc;
fc=Integer.parseInt(br.readLine());
obj3.setfuelcapacity(fc);

break;
case "2":
System.out.println("Enter Miles Per Gallon in Integers Please ");
int mpg;
mpg=Integer.parseInt(br.readLine());
obj3.setmpg(mpg);
break;
case "3":
System.out.println("You Selected Option 3:");
range=obj3.getfuelcapacity()*obj3.getmpg();
break;   
case "4":

break;
}
}while(true);//sports end

break;

case "4":
System.exit(0);
break;


}

}while(true);


}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote