subject

Implement a class Car, which contains the fields: make, e. g. Ford, Subaru, Toyota ...
model, e. g., Escape, Outback, Camry ...
year
MPG miles per gallon
milesDriven, the total number of miles ever driven in this car.
fuelCapacity in gallons, i. e., the size in gallons of the fuel tank.
fuelRemaining, which represents the amount of fuel remaining in the gas tank.
Implement at least the following methods within the Car class:
a constructor, which initializes each of the fields
fillTank(double g), which adds up to g gallons of gas to the fuel tank, but not more than the car's fuel capacity.
drive(double m), which simulates driving m miles in the car, adding to the total number of miles driven, and reducing the amount of gas in the car according to this car's average MPG.
toString( ), which returns a String representation of the car.
getFuelRemaining( ), which returns the amount of fuel left in the tank.
For example, we should be able to do something like the following:
Car oldJunker = new Car("Ford", "Pinto", 1972, 17.5, 12, 8); // creates a new Car object
oldJunker. drive(5); // drives the Car 5 miles
oldJunker. fillTank(1); // put in a gallon of gas
System. out. println(oldJunker. getFuelRemaining()); // prints the amount of fuel left
System. out. println(oldJunker); // prints the attributes of the car to the screen
Write a short driver program to test your Car class with a short array of Cars.
Fractions (35 points)
Write a class used to represent fractions. It should contains fields for numerator and denominator, and it should be able to perform some simple arithmetic operations.
The fields are:
numerator
denominator
Implement at least the following methods:
public Fraction(int n, int d)
Constructor that creates a Fraction with numerator and denominator d. If d is 0, throw an ArithmeticException. We haven't yet had a chance to cover exceptions in as much depth as we soon will, but this can be done simply in your method with the statement throw new ArithmeticException();
public int getNum()
Returns the value of the numerator field
public int getDenom()
Returns the value of the denominator field
public void setNum(int n)
Sets the numerator field to the value given in n
public void setDenom(int d)
Sets the denominator field to the value given in d. If d is 0, throw an ArithmeticException.
public Fraction add(Fraction a)
Returns the fraction that is the sum of the subject of the method and a. For example (new Fraction(3,4)).add(new Fraction(1,4)) is 16/16 i. e 1/1 We sum the fractions a/b and c/d as (a*d+b*c)/b*d then reduce.
public boolean equals(Fraction a)
Returns true if subject of method and argument of call are equal. Fractions a/b and c/d are equal if a*d and b*c are equal or since the fractions are normalized, if a==c and b==d.
public String toString()
Returns a String representation of the fraction. For example, if the numerator is 1 and the denominator is 2, the String "1/2" is returned.
Fractions should be stored in reduced form. For example, 2/4, 3/6, 4/8, etc. should all be stored as 1/2. 4/10 should be stored as 2/5. Use the Euclidean Algorithm for determining the greatest common divisor, so that you can store fractions in reduced form.
Write a simple main driver method to test your fraction class and each of its methods.
Note about files
There are several possible ways to organize your files for this assignment. The simplest and recommended way would be that you have four files:
Car. java - contains a Car class definition (i. e., what we've been calling a blueprint or a cookie cutter)
CarMain. java - contains your test program
Fraction. java - contains a Fraction class definition
FractionMain. java - contains a test program

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 01:00, Ltik11900
Write the command that can be used to answer the following questions. (hint: try each out on the system to check your results.) a. find all files on the system that have the word test" as part of their filename. b. search the path variable for the pathname to the awk command. c. find all files in the /usr directory and subdirectories that are larger than 50 kilobytes in size. d. find all files in the /usr directory and subdirectories that are less than 70 kilobytes in size. e. find all files in the / directory and subdirectories that are symbolic links. f. find all files in the /var directory and subdirectories that were accessed less than 60 minutes ago. g. find all files in the /var directory and subdirectories that were accessed less than six days ago. h. find all files in the /home directory and subdirectories that are empty. i. find all files in the /etc directory and subdirectories that are owned by the group bin."
Answers: 1
image
Computers and Technology, 23.06.2019 12:00, lyn94
Using the list, you can select the number of photos that will appear on each slide. a. theme b. frame shape c. pictures in album d. picture layout
Answers: 1
image
Computers and Technology, 23.06.2019 14:30, rose6038
Select the correct answer. peter has launched a website that features baby products. however, clients often find they are unable to access the website because the server is down. which feature of cybersecurity should peter focus on for his website? a. data authenticity b. data privacy c. data availability d. data integrity e. data encryption
Answers: 3
image
Computers and Technology, 24.06.2019 13:50, jaystarr9395
Write a program that performs a simple n-body simulation, called "jumping leprechauns." this simulation involves n leprechauns, numberd 1 to n. it maintains a gold value g_i for each leprechaun i, which begins with each leprechaun starting out with a million dollars worth of gold, that is, g_i = 1000000 for each i = 1,. in addition, the simulation also maintains, for each leprachaun, i, a place on the horizon, which is represented as a double-precision floating point number, x_i. in each iteration of the simulation, the simulation processes the leprachauns in order. processing a leprachaun i during its iteration begins by computing a new place on the horizon for i, which is determined by the assignment:
Answers: 3
You know the right answer?
Implement a class Car, which contains the fields: make, e. g. Ford, Subaru, Toyota ...
model,...

Questions in other subjects: