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

Objective: Find out the “true” MPG (Miles Per Gallon) of a vehicle, given a grou

ID: 3844549 • Letter: O

Question

Objective: Find out the “true” MPG (Miles Per Gallon) of a vehicle, given a group of conditions which the user provides values for. 5 are given, 1 you create on your own. Requirements:

Prompt the user for the car’s MPG first. i.e. Please Enter MPG: 26

Then prompt the user to enter a value for six factors which will affect the MPG of the vehicle, prompting for single value inputs after showing menus (i.e. a series of println() statements showing the options/valid values to enter)

After collecting all of the inputs, provide a detailed report of the inputs, their meaning, how much they affect MPG, as well as the the beginning and final MPG.

The following criteria will be used for the six inputs.

City or Highway Driving: Use a boolean type variable for input

City Subtracts 2 from MPG

Highway Adds 5 to MPG

Rainy or Sunny: Use a String type variable for input

“Rainy” Subtracts 1 from MPG

“Sunny” No Change to MPG

Elevation: Use a char type variable for input

‘S’ for Steep, Steep Subtracts from 5MPG

‘H’ for Hilly, Hilly Subtracts 3 from MPG

‘F’ for Flat, No Change to MPG

Weight in Vehicle (cargo or passenger): Use double type for input

Each 100lbs subtracts 0.5 MPG

Speed Preference: Use an int type variable for input

1 for under speed limit, Add 2 to MPG

2 for at speed limit, No Change to MPG

3 for 5% above speed limit, Subtract 1 from MPG

4 for 10% above speed limit, Subtract 3 from MPG

5 for over 20% above speed limit, Subtract 5 from MPG

Suggestion: Use a switch() statement for Speed Preference

Add one additional factor which you will prompt the user for, that affects MPG such as

tire pressure/condition,

hybrid vs. gas powered,

engine condition,

towing load,

2WD/4WD,

objective: Find out the "true" MPG (Miles Per Gallon) of a vehicle, given a group of conditions which the user provides values for 5 are given, 1 you create on your own. Requirements: Prompt the user for the car's MPG first. e. Please Enter MPG: 26 Then prompt the user to enter a value for six factors which will affect the MPG of the vehicle, prompting for single value inputs after showing menus (i.ee. a series of prinNn statements showing the options/valid values to enter) After collecting all of the inputs, provide a detailed report of the input their meaning, how much they affect MPG, as well as the the beginning and final MPG. The following criteria will be used for the six inputs. 1. City or Highway Driving: Use a boolean type variable for input City Subtracts 2 from MPG Highway Adds 5 to MPG 2. Rainy or Sunny: Use a Stringtype variable for input "Rainy" Subtracts 1 from MPG "Sunny No Change to MPG 3. Elevation: Use a char type variable for input 'S' for Steep, steep subtracts from 5MPG 'H' for Hilly, Hilly Subtracts 3 from MPG "F" for Flat, No Change to MPG 4. Weight in Vehicle (cargo or passenger: Use double type for input Ea ch 100lbos subtracts 0.5 MPG 5. Speed Preference: Use an int type variable for input 1 for under speed limit, Add 2 to MPG 2 for at speed limit, No Change to MPG 3 for 5% above speed limit, Subtract 1 from MPG 4 for 10% above speed limit, Subtract 3 from MPG 5 for over 20% above speed limit, Subtract 5 from MPG Suggestion: Use a switch0 statement for Speed Preference 6. Add one additional factor which you will prompt the user for, that affects MPG such as tire pressure/condition, hybrid vs. gas powered, engine condition, towing load, 2WD/4WD, etc

Explanation / Answer

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
class Miles_Per_Gallon
{
public static int mpg;
public static double weight;
String inp, input;
boolean bool;
char ch1;
boolean city, highway;
public void display()
{
System.out.println(" OUTPUT");
System.out.println(" MPG = "+mpg);
System.out.println(" City or Highway Driving =");
if(input == "City")
       {
       System.out.println(" City = ");
       System.out.print(mpg-2);
       }
       else
       {
       System.out.println(" Highway = "+(mpg+5));
       }
       System.out.println(" Rainy or Sunny = ");
       {
       if(inp == "Rainy")
       {
       System.out.println("Rainy ="+(mpg-1));
       }
       else
       {
       System.out.println(" Sunny = "+mpg);
       }
       }
       System.out.println(" Elevation = ");
       if(ch1 == 'S')
       {
       System.out.print(mpg-5);
       }
       else if(ch1 == 'H')
       {
       System.out.print(mpg-3);
       }
       else
       {
       System.out.print(mpg);
       }
       System.out.println(" Wweight in Vehicle ="+(mpg-0.5));
}
}
class Test
{
   public static void main (String args[])
   {
       Miles_Per_Gallon mp = new Miles_Per_Gallon();
       Scanner scan = new Scanner(System.in);
       System.out.println(" Please Enter MPG:");
       int mpg = scan.nextInt();
       System.out.println(" City or Highway Driving:");
       boolean bool;
       String input = "City";
       System.out.println(" Rainy or Sunny:");
       String inp = scan.next();
       System.out.println(" Elevation:");
       char ch1 = scan.next().charAt(0);
       System.out.println(" Weight in Vehicle:");
       double weight = scan.nextDouble();
       System.out.println(" Speed Preference:");
       int ch = scan.nextInt();
       System.out.println(" 1. Under Speed Limit:");
       System.out.println(" 2. At Speed Limit:");
       System.out.println(" 3. For 5% above Speed Limit:");
       System.out.println(" 4. For 10% abouve Speed Limit:");
       System.out.println(" 5. For Over 20% above Speed Limit:");
       switch(ch)
       {
       case 1:
       System.out.println(" Speed Limit = ");
       System.out.print(mpg+2);
       break;
       case 2:
       System.out.println(" Speed Limit = ");
       System.out.print(mpg);
       break;
       case 3:
       System.out.println(" Speed Limit = ");
       System.out.print(mpg-1);
       break;
       case 4:
       System.out.println(" Speed Limit = ");
       System.out.print(mpg-3);
       break;
       case 5:
       System.out.println(" Speed Limit = ");
       System.out.print(mpg-5);
       break;
       }
       mp.display();
   }
}