Question: 1. GasPump Class (5 points) GAS SSS Write a class named GasPump that has the following fields: gallons: number of gallons to pump fuelGrade: type

1. GasPump Class (5 points) GAS SSS Write a class named GasPump that has the following fields: gallons: number of gallons to pump fuelGrade: type of fuel (represented by 1,2, or 3 see below) Specifications: Add a comment to the top of the code that describes the purpose of the class Enforce encapsulation Provide a no argument constructor which initializes gallons to 0. Set gallons in the object only if it is greater than 0 and less than 25. Add a method named pump() that simulates the pumping of fuel by printing a descriptive message after each gallon is pumped. Add a method named calculateCost() that returns the total cost of the transaction based on the number of gallons pumped and the price per gallon. See information below about pricing. Add a method named printReceipt() that calls calculateCost() then prints a descriptive message of the transaction. Gas is commonly available in three octane ratings or "grades": 87 lowest octane rating and cheapest option 88-90 mid-grade 90-94 premium or high grade Pricing is as follows: (87) $2.00 per gallon (Fuel Grade 1) (88-90) $2.50 per gallon (Fuel Grade 2) (90-94) $3.00 per gallon (Fuel Grade 3)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
