subject

Project 16A- Gas Mileage package: mileage
Class: 2 files - Main. java, and Automobile. java

Create a class called Automobile in which you pass a gas mileage (miles per gallon)
parameter to the constructor which in turn passes it to the state variable, mpg. The
constructor should also set the state variable gallons (gas in the tank) to 0. A method called
fillUp adds gas to the tank. Another method, takeTrip, removes gas from the tank as the
result of driving a specified number of miles. Finally, the method reportFuel returns how
much gas is left in the car.

**Also throw in a way to calculate the cost of a trip to your interface.

Test your Automobile class by creating a Tester class as follows:

public class Tester
{
public static void main( String args[] )
{
//Create a new object called myBmw. Pass the constructor an
//argument of 24 miles per gallon
Automobile myBmw = new Automobile(24);

//Use the myBmw object to call the fillup method. Pass it an argument
//of 20 gallons.
myBmw. fillUp(20);

//Use the myBmw object to call the takeTrip method. Pass it an
//argument of 100 miles. Driving 100 miles of course uses fuel and we
//would now find less fuel in the tank.
myBmw. takeTrip(100);

//Use the myBmw object to call the reportFuel method. It returns a
//double value of the amount of gas left in the tank and this is assigned
// to the variable fuel_left
double fuel_left = myBmw. reportFuel( );
//Print the fuel_left variable

System. out. println(fuel_left); //prints gallons left, 15.833333333333332
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:10
Ihave a music player on my phone. i can buy songs, add them to playlists and play them. obviously it would be redundant to store each song in each playlist; each playlist is just a list of pointers to the songs. for this lab you will simulate this behavior. your program will need to have options to: add songs to the system library (you will store the text of the first line of the song, rather than the audio) add playlists add songs to a playlist list playlists play a playlist list all of the songs in the library with a count of how many times each song has been played remove a song from a playlist remove a playlist remove a song from the library (and thus from all playlists that contain it) note that we will not be checking many error cases. in real programming this would be bad, you should usually try to recognize and respond to as many types of errors as you can. in the context of class we are trying to acquaint you with as many concepts as possible, so for the sake of educational efficiency we will not be checking most errors in this lab, you may assume that your user provides correct input. you may add all appropriate error testing if you wish, but we will not be testing for it.
Answers: 2
question
Computers and Technology, 22.06.2019 17:40
Consider the simple 3-station assembly line illustrated below, where the 2 machines at station 1 are parallel, i.e., the product only needs to go through one of the 2 machines before proceeding to station 2.what is the throughput time of this process?
Answers: 2
question
Computers and Technology, 23.06.2019 22:30
You draw two cards from a standard deck of 52 cards, but before you draw the second card, you put the first one back and reshuffle the deck. (a) are the outcomes on the two cards independent? why?
Answers: 3
question
Computers and Technology, 24.06.2019 01:30
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
You know the right answer?
Project 16A- Gas Mileage package: mileage
Class: 2 files - Main. java, and Automobile. java
Questions
question
Physics, 31.01.2020 11:47
question
Mathematics, 31.01.2020 11:47
question
Mathematics, 31.01.2020 11:47
question
Mathematics, 31.01.2020 11:47
Questions on the website: 13722361