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

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

ID: 3696257 • Letter: C

Question

Create a computer program that will calculate the range for 3 different vehicles. The program should create a “programmer created” class, where 3 int objects are created passengers, fuel capacity, and mpg. Create a void () method inside the “programmer created “class to calculate vehicle range. range = fuel capacity * miles per gallon. Each Vehicle type should have unique values for number of passengers, fuel capacity, and miles per gallon. Follow the sample below and return information on 3 vehicle 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.

Explanation / Answer

Try the below C# code, it may help you to an extent...
In each cycle the vehicle type is taken and the passengers,fuelcapacity,mpg is taken and vehicle Range is calculated on that basis.


using System;

namespace programmerCreatedName
{
class ProgrammerCreated
{
private int passengers = 0;
private int fuelcapacity = 0;
private int mpg = 0;
private int range = 0;
public string vehicletype = " ";
  
  
// Declare a passengers property of type int:
public int Passengers
{
get
{
return passengers;
}
set
{
passengers = value;
}
}
  
// Declare a fuelcapacity property of type int:
public int Fuelcapacity
{
get
{
return fuelcapacity;
}
set
{
fuelcapacity = value;
}
}
  
// Declare a mpg property of type int:
public int Mpg
{
get
{
return mpg;
}
set
{
mpg = value;
}
}

public void calculateRange()
{
        range = fuelcapacity * mpg;
       Console.WriteLine("Range for vehicle "+ vehicletype +" is " + range);
}

}//class ends...


class ProgrammerCreatedMain
{
public static void Main()
{
  
ProgrammerCreated pc = new ProgrammerCreated();

int i = 1;
       int cntr = 0;
       char ch='';

do
{
           Console.WriteLine("Please enter Vehicle Type-"+i);
           pc.vehicletype = Console.ReadLine();

           Console.WriteLine("Please enter any option for {0} vehicle", pc.vehicletype);
           Console.WriteLine("1. Passengers");
           Console.WriteLine("2. Fuel Capacity");
           Console.WriteLine("3. MPG");
           Console.WriteLine("4. Calculate Vehicle Range");
           ch = Console.ReadKey();
           cntr = 0;

      
           do
           {
           Switch(ch)
           {
               case '1': Console.WriteLine("Enter Number of Passengers:");
                           pc.Passengers = Convert.ToInt32(Console.ReadLine());
                           break;
               case '2': Console.WriteLine("Enter Fuel Capacity:");
                           pc.Fuelcapacity = Convert.ToInt32(Console.ReadLine());
                           break;
               case '3': Console.WriteLine("Enter MPG:");
                           pc.Mpg = Convert.ToInt32(Console.ReadLine());
                           break;
               case '4': pc.calculateRange();
                           break;
               default: Console.WriteLine("Invalid Option..."); // Do nothing
                           break;

           }
          
               cntr++;
           }
           while (cntr < 4);          

           i++;
       }
while (i <= 3);

  
   }// main() ends...
} // class ends...
}

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