Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* The question isn't as clear to me either but i think he wants me to replace the multiple arrays with two dimentional arrays. There

*The question isn't as clear to me either but i think he wants me to replace the multiple arrays with two dimentional arrays. There is supposed to be 4 legs and each leg should hold the distance and speed. I think he might want 2 dimentional arrays, one for car1 and car2. Below i added the first assignment of where we created the base of the code. The question i had before was the complete question and there was no sample code besides the one provided.*

Descripton: I would like you to create two new classes "YourCar" and "YourCarTrip" that will help you calculate the total distance from one point (point A) to a second point (point B), how long it will take you to get there, and if you need gas for the return trip. YourCarTrip is the application.

Example: Depart UHCL (point A), take a left on to Bay Area Boulevard for 3.5 miles at 30 MPH, take a left onto I45 South for 26.3 miles at 65 MPH, exit right onto 61st street, go 2.0 miles to Stewart Drive, take a right and go 4.3 miles at 45 MPH to your destination on the right (point B).

YourCar should define, at least, the instance variables that hold the number of gallons in the tank (must be input at some point), the number of miles in the trip (starts at zero), current speed (starts at zero). YourCar should also be able to change direction, change speed (increase, decrease), and determine if you need gas. Needs gas, implies you will need to calculate your fuel consumption, so assume your car averages 25 MPG at any speed.

I would like you to run two different YourCar objects at the same time to see if it is worth the time to go ten miles over the speed limit. so, your application should output, the route (changes in course), the total distance, the total time, and fuel consumption.

Hint: you can assume you know the following information. 1) the number of road segment 2) for each road segment, you have information of speed limit, length of the road segment, direction that the car is heading, the name of the road.

Please don't copy and paste the answer from other questions simliar to this on this post. So far they have all been wrong or didn't implement two-dimentional arrays. Thank you.

I would like you to update the classes you created for homework5. Update "YourCar" and "YourCarTrip" such that you use a two-dimensional arrayto store each leg. Your application should store all legs for the trip in multiple arrays, including the distance and the speed limit for each leg of the trip. The rest of the requirements are the same as previous homework. Outputs should include, but are not limited to: time to travel each leg, total time, total distance, fuel consumption and remaining fuel.

Example: Depart UHCL (point A), take Bay Area Boulevard for 3.5 miles at 30 MPH, take I45 South for 26.3 miles at 65 MPH, exit right onto 61st street and go 2.0 miles at 30 MPH, then take Stewart Drive 4.3 miles at 45 MPH to your destination (point B). You application should ask the user for the number of legs (this case four (4)) then loop through four sets of questions to gather the necessary inputs for distance and speed.

YourCar should define, at least, the instance variables that hold the number of gallons in the tank (must be input at some point), the number of miles in the trip (starts at zero), current speed (starts at zero). YourCar should have the ability (methods) to change speed (increase, decrease), calculate time, calculate distance traveled, and determine if you need gas. Needs gas, implies you will need to calculate your fuel consumption, so assume your car averages 25 MPG at any speed. You may have to ask the user for amount of fuel (gallons) at the beginning of the trip. Constraint: Your gas tank cannot hold over 10 gallons.

My code of what i have so far :

package yourcartrip;

import java.util.Scanner;

class YourCar

{

double gallons = 0;

double miles = 0;

double speed = 0;

}

public class YourCarTrip

{

public static void main(String[] args)

{

double time1 = 0;

double time2 = 0;

YourCar car1= new YourCar();

YourCar car2= new YourCar();

Scanner input=new Scanner(System.in);

System.out.printf("Enter the number of gallons in the tank for car 1: ");

car1.gallons= input.nextDouble();

System.out.printf(" Enter the number of gallons in the tank for car 2: ");

car2.gallons= input.nextDouble();

System.out.println("Enter your number of legs for car 1: ");

int legs = input.nextInt();

double[] miles = new double[legs];

double[] sp1 = new double[legs];

double[] sp2 = new double[legs];

for(int i=0;i

{

System.out.println("leg"+(i+1)+":miles");

miles[i] = input.nextDouble();

System.out.println("Car 1 speed: ");

sp1[i] = input.nextDouble();

System.out.println("Car 2 speed: ");

sp2[i] = input.nextDouble();

car1.miles+=miles[i];

car2.miles+=miles[i];

car1.speed+=sp1[i];

car2.speed+=sp2[i];

time1+=miles[i]/sp1[i];

time2+=miles[i]/sp2[i];

}

int j=0;

System.out.println(" Route 1: Depart UHCL (point A), take a left on to Bay Area Boulevard "

+ "for "+miles[j]+" miles at "+sp1[j++]+" MPH, take a left onto I45 South for "+miles[j]+" miles at "+sp1[j++]+" MPH, "

+ "exit right onto 61st street, go "+miles[j]+" miles at "+sp1[j++]+" MPH to Stewart Drive, take a right "

+ "and go "+miles[j]+" miles at "+sp1[j++]+" MPH to your destination on the right (point B).");

System.out.println(" Car 1: ");

System.out.println("Total distance: "+ car1.miles+" miles");

System.out.println("Total time: "+ time1+" hours");

System.out.println("Total speed: "+ car1.speed+" MPH");

System.out.println("Gas: "+ (car1.gallons-2 * (car1.miles/25))+" gallons");

if((car1.gallons-2 * (car1.miles/25))>=0)

{

System.out.println("You don't need gas ");

}

else

System.out.println("You do need gas ");

j=0;

System.out.println(" Route 1: Depart UHCL (point A), take a left on to Bay Area Boulevard "

+ "for "+miles[j]+" miles at "+sp2[j++]+" MPH, take a left onto I45 South for "+miles[j]+" miles at "+sp2[j++]+" MPH, "

+ "exit right onto 61st street, go "+miles[j]+" miles at "+sp2[j++]+" MPH to Stewart Drive, take a right "

+ "and go "+miles[j]+" miles at "+sp2[j++]+" MPH to your destination on the right (point B).");

System.out.println(" Car 2: ");

System.out.println("Total distance: "+ car2.miles+" miles");

System.out.println("Total time: "+ time2+" hours");

System.out.println("Total speed: "+ car2.speed+" MPH");

System.out.println("Gas: "+ (car2.gallons-2 * (car2.miles/25))+" gallons");

if((car2.gallons-2 * (car2.miles/25))>=0)

{

System.out.println("You don't need gas ");

}

else

System.out.println("You do need gas ");

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago

Question

To solve by the graphical methods 2x +3y = 9 9x - 8y = 10

Answered: 1 week ago

Question

14-18 Compare the two major types of planning and control tools.

Answered: 1 week ago