, , ,

[SOLVED] Cs2070 assignment 10: the car class

$25

File Name: Cs2070_assignment_10__the_car_class.zip
File Size: 329.7 KB

5/5 - (1 vote)

Object-Oriented Programming (OOP) is about rethinking how we write code. OOP centers around objects. In this case, the object is a Car. Objects do things. They have a status which can change based on what is doing.This homework assignment has lots of math. It’s simple math, but there’s still lots to compute.For instance, a new car will have an odometer of 0. This is the car’s initial state. After the car drives 10 miles, the odometer will be 10. If it drives 10 more miles, the odometer will be 20. Each time the car is driven, the odometer will increase. It should never decrease.Here are the fields that a Car should have (all of which will be represented with double values).Here’s a few important terms which will be necessary for completing this assignment.Example. My car has a 9 gallon tank and gets 33 miles to the gallon.Name your project FirstnameLastnameAssignmentNumberHave your program do the following.Tips: The only primitive data type that I used in this assignment was double. All inputs were double too. Because everything is a double, you’ll need to display everything to 1 decimal place using printf. Also, you must document your public methods in the Car class with a description, precondition, postcondition, a description of each parameter, and the returned value.Create a class named Car which contains the fields mentioned above.In addition to the fields mentioned above, you’ll need these public methods. The precondition for any method which takes an argument is that the argument must be positive. You’ll have to determine if your method as a postcondition. (As postcondition is any method which changes the object’s fields.) Also, no methods will display anything and you’ll be counted off severely if you have print statements in your Car class.This method will assign gas to the field for the fuel and mpg to the car’s milesPerGallon field. The odometer field will always begin at 0.This method will return the fuel (i.e. the amount of gas left in the tank).This method will return the odometer reading.This method will attempt to drive the car at this speed for this amount of time as long as there is enough gas in the tank. If there’s enough gas or not, update the odometer and return the distance driven. In general, I did these steps.The program should continue to loop until the car’s fuel tank is completely empty.Here’s an example run in which I used the same example from earlier in the assignment.Welcome to Dr. Church’s Car Simulator.
Enter the number of gallons of gas in the tank: 9
Enter the car’s miles per gallon: 33
We’ve created a car with 9.0 gallons of gas in the tank and get 33.0 MPG.
We will loop while there is gas in the tank.Enter the speed (in miles per hour) at which you will drive the car: 70
Enter the time (in hours) that you drove the car: 3
The car drove a distance of 210.0 miles.
The car odometer is at 210.0 miles.
There is 2.6 gallons of gas left in the tank.Enter the speed (in miles per hour) at which you will drive the car: 30
Enter the time (in hours) that you drove the car: 0.5
The car drove a distance of 15.0 miles.
The car odometer is at 225.0 miles.
There is 2.2 gallons of gas left in the tank.Enter the speed (in miles per hour) at which you will drive the car: 50
Enter the time (in hours) that you drove the car: 1.5
The car drove a distance of 72.0 miles.
The car odometer is at 297.0 miles.
There is 0.0 gallons of gas left in the tank.Your source code must include the following documentation:To turn in your application, find the folder containing your entire project (not the folder with the “java” file), zip it up, and turn it in.

Shopping Cart

No products in the cart.

No products in the cart.

[SOLVED] Cs2070 assignment 10: the car class
$25