Code Monkey home page Code Monkey logo

bell-kevin / milespergallonofgas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jcboydsd/milespergallon

0.0 0.0 0.0 16 KB

SDEV 2210 Project. Create a project that calculates miles per gallon for a given trip, and accumulates the miles and gallons to calculate an overall MPG for the vehicle. Create a class named MPG that includes private instance variables for miles, gallons, and mpg, which are doubles. Add class variables for totalMiles, totalGallons, and totalMPG, which are doubles, and numTrips, which is an integer. Create a constructor which accepts 2 double parameters, one for miles, one for gallons. Inside the constructor, set the instance variables for miles and gallons, and calculate the mpg. Add to the class variables for totalMiles and TotalGallons, and increment the number of trips. Create an instance method named displayCurrentMPG( ) which displays the MPG variable for a specific trip object. Create a class method named displayTotalMPG( ) which calculates and displays the overall MPG for all of the trip objects. The driver class will instantiate 4 trips, display the MPG for each trip, and display the overall MPG. For the sample session, use the following values: Trip1: miles = 320, gallons = 29 Trip2: miles = 325.8, gallons = 32.1 Trip3: miles = 412.5, gallons = 35 Trip4: miles = 345, gallons = 32.6 Note that these 4 trips test all the possible combinations of variable types – 2 integers, 2 doubles, 1 integer and 1 double, 1 double and 1 integer. It’s always good practice to test all possible situation. Once the program works as it should to match the sample session, run the project twice more, with different numbers for every trip, and take screenshots of the results.

Java 100.00%
datc davistech 2210 davis gas gasoline miles mpg sdev sdev2210 tech object-oriented-programming oop

milespergallonofgas's Introduction

MilesPerGallonOfGas

SDEV 2210 Project Create a project that calculates miles per gallon for a given trip, and accumulates the miles and gallons to calculate an overall MPG for the vehicle.

Create a class named MPG that includes private instance variables for miles, gallons, and mpg, which are doubles. Add class variables for totalMiles, totalGallons, and totalMPG, which are doubles, and numTrips, which is an integer. Create a constructor which accepts 2 double parameters, one for miles, one for gallons. Inside the constructor, set the instance variables for miles and gallons, and calculate the mpg. Add to the class variables for totalMiles and TotalGallons, and increment the number of trips.

Create an instance method named displayCurrentMPG( ) which displays the MPG variable for a specific trip object. Create a class method named displayTotalMPG( ) which calculates and displays the overall MPG for all of the trip objects.

The driver class will instantiate 4 trips, display the MPG for each trip, and display the overall MPG.

For the sample session, use the following values: Trip1: miles = 320, gallons = 29 Trip2: miles = 325.8, gallons = 32.1 Trip3: miles = 412.5, gallons = 35 Trip4: miles = 345, gallons = 32.6

Note that these 4 trips test all the possible combinations of variable types – 2 integers, 2 doubles, 1 integer and 1 double, 1 double and 1 integer. It’s always good practice to test all possible situation.

Once the program works as it should to match the sample session, run the project twice more, with different numbers for every trip, and take screenshots of the results.

== We're Using GitHub Under Protest ==

This project is currently hosted on GitHub. This is not ideal; GitHub is a proprietary, trade-secret system that is not Free and Open Souce Software (FOSS). We are deeply concerned about using a proprietary system like GitHub to develop our FOSS project. We have an open {bug ticket, mailing list thread, etc.} where the project contributors are actively discussing how we can move away from GitHub in the long term. We urge you to read about the Give up GitHub campaign from the Software Freedom Conservancy to understand some of the reasons why GitHub is not a good place to host FOSS projects.

If you are a contributor who personally has already quit using GitHub, please check this resource for how to send us contributions without using GitHub directly.

Any use of this project's code by GitHub Copilot, past or present, is done without our permission. We do not consent to GitHub's use of this project's code in Copilot.

Logo of the GiveUpGitHub campaign

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.