Code to be written in JAVA please
In this assignment you will use a class Car to represent a
car that travels to various destinations. Your car has a
fuel economy rating of 32.3 miles per gallon. The gas tank holds
19.5 gallons. Your program will need to simulate two trips: 1) BC
to Yosemite Valley, and 2) BC to Washington, D.C.. For each trip
you will start with a full tank of gas. The output should look as
follows.
Trip one: Bakersfield College to Dodger Stadium
Mileage: 204
Trip two: Bakersfield College to Washington, D.C.
Mileage: 2,686
The constructor will set the fuel efficiency rating to 32.3 mpg
and the initial fuel level for each trip to zero.
Write a method addGas(), to fill the fuel tank.
Write a method getGasInTank(), returning the current amount of
gasoline in the fuel tank.
Write a method named roadTrip() that simulates driving the car a
given distance, reducing the
amount of gasoline in the fuel tank.
Let the user know they ran out of gas if they try to drive further
than the fuel in the tank and the mileage allows. The output must
show the mileage at which they would be where they run out of gas.
Use int for mileage and discard any fractional values resulting
from division.
All values must be hard-coded, do not use the Scanner class.
Save as a text file with the .java extension. Submit the .java files, do not submit the .class files. Be sure the class names match your file names, e.g. if your class is named Car the file name should be Car.java
public class Car {
private double fuelEconomy;
private double tankCapacity;
public Car(double fuel) {
fuelEconomy = fuel;
tankCapacity = 0;
}
public void addGas(double gas) {
System.out.println("Adding gas...");
tankCapacity += gas;
}
public double getGasInTank() {
return tankCapacity;
}
public void roadTrip(double distance) {
double distanceTravelled = 0;
System.out.println("Mileage: "+(int)(tankCapacity*fuelEconomy));
System.out.println("Travelling a distance of "+distance+" miles");
System.out.println("Gasoline Left: " + tankCapacity);
while (tankCapacity > 0 || distanceTravelled >= distance) {
if (tankCapacity > 5) {
tankCapacity -= 5;
distanceTravelled += 5 * fuelEconomy;
if (distanceTravelled >= distance) {
System.out.println("You have reached your destination");
System.out.println("Gasoline Left: " + tankCapacity);
break;
}
System.out.println("Distance travelled : " + (int)(distanceTravelled));
System.out.println("Tank Capacity: " + tankCapacity);
} else {
distanceTravelled += tankCapacity * fuelEconomy;
if (distanceTravelled >= distance) {
System.out.println("You have reached your destination");
System.out.println("Gasoline Left: " + tankCapacity);
break;
}
tankCapacity = 0;
System.out.println("Distance travelled : " +(int)(distanceTravelled));
System.out.println("Tank Capacity: " + tankCapacity);
System.out.println("You need to refuel the tank");
}
}
}
public static void main(String[] args) {
System.out.println("Trip one: Bakersfield College to Dodger Stadium");
Car tripOne = new Car(32.23);
tripOne.addGas(40);
tripOne.roadTrip(500);
System.out.println("Trip two: Bakersfield College to Washington, D.C.");
Car tripTwo = new Car(32.23);
tripTwo.addGas(50);
tripTwo.roadTrip(19*32);
}
}
Code to be written in JAVA please In this assignment you will use a class Car...
In JAVA In this assignment you will use a class Car to represent a car that travels to various destinations. Your car has a fuel economy rating of 32.3 miles per gallon. The gas tank holds 19.5 gallons. Your program will need to simulate two trips: 1) BC to Yosemite Valley, and 2) BC to Washington, D.C.. For each trip you will start with a full tank of gas. The output should look as follows. Trip one: Bakersfield College to...
python code
DC Final Project Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. The following two lines are written in a File called FuelEffic.txt (you have to read these from the txt file) Miles per gallon: 20 Tank Size (in gallons): 25 Therefore, based on these...
*** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...
Please try to write the code with Project 1,2 and 3 in
mind. And use java language, thank you very much.
Create an Edit Menu in your GUI
Add a second menu to the GUI called Edit which will have one
menu item called Search. Clicking on search should prompt the user
using a JOptionPane input dialog to enter a car make. The GUI
should then display only cars of that make. You will need to write
a second menu...
please help me add on this java code to run
public class CarHwMain public static void main(String args 1/ Construct two new cars and one used car for the simulation Cari carl = new Car W"My New Mazda", 24.5, 16.0); Car car2 = new Cart My New Ford" 20.5, 15.0) Cari car) - new Cari ("My Used Caddie", 15.5, 16.5, 5.5, 1/ ADD CODE to completely fill the tanks in the new cars and off the used cars ton //...
For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...
You are allowed to add any parameter you need into any class. You are not allowed to DELETE any mentioned parameter in the question. Use comments to explain your code Your code should be runnable. You can copy-paste your code here, or upload a zip file of your files. Inheritance rules must be considered. The super() method should be used where necessary. You should prevent the creation of instances (i.e. objects) Casting must also be considered where necessary. You should...
This assignment shpuld be code in java. Thanks
Overview In this assignment you will write a program that will model a pet store. The program will have a Pet class to model individual pets and the Assignment5 class will contain the main and act as the pet store. Users will be able to view the pets, make them age a year at a time, add a new pet, and adopt any of the pets. Note: From this point on, your...
Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...
**IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...