Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA: Scenario: Lets say you are a college student that comes from a low-income

ID: 3726707 • Letter: J

Question

JAVA: Scenario: Lets say you are a college student that comes from a low-income family, so you inherited your grandparent's 1985 Chevy whose Gas Gauge doesn't work properly. Write a program that lets you know when its time to fill up your gas tank based on your commute. Lets say you know the accurate mpg of the vehicle and you use it as a daily (school, to get lunch, to go to Walmart for groceries, to go to the gas station) MPG of the 1985 Chevy is: 12MPG Full tank can fill 8 Gallons of gas. Gas has a fixed price of $2.50 per gallon. MUST: You go to school 4 times a week, and school is 10 miles away. (remember you must calculate round trip). MUST: You go to walmart twice a week to buy groceries and its 8 miles way from HOME. (round trip). MUST : Your nearest Gas station is 2 miles away from HOME. Optional: Your nearest Chik-Fil-A is 7 miles away from HOME, and you go AFTER getting HOME from school. Approximately calculate how many times can you go to chik-fil-A without running out of gas if you have a budget of $30 a week for gas.

Please use the most basic and simple approaches for this problem. We still on the beggining of the Java N I dont want my professor thinking I’m a java god haha thanks! JAVA: Scenario: Lets say you are a college student that comes from a low-income family, so you inherited your grandparent's 1985 Chevy whose Gas Gauge doesn't work properly. Write a program that lets you know when its time to fill up your gas tank based on your commute. Lets say you know the accurate mpg of the vehicle and you use it as a daily (school, to get lunch, to go to Walmart for groceries, to go to the gas station) MPG of the 1985 Chevy is: 12MPG Full tank can fill 8 Gallons of gas. Gas has a fixed price of $2.50 per gallon. MUST: You go to school 4 times a week, and school is 10 miles away. (remember you must calculate round trip). MUST: You go to walmart twice a week to buy groceries and its 8 miles way from HOME. (round trip). MUST : Your nearest Gas station is 2 miles away from HOME. Optional: Your nearest Chik-Fil-A is 7 miles away from HOME, and you go AFTER getting HOME from school. Approximately calculate how many times can you go to chik-fil-A without running out of gas if you have a budget of $30 a week for gas.

Please use the most basic and simple approaches for this problem. We still on the beggining of the Java N I dont want my professor thinking I’m a java god haha thanks! MPG of the 1985 Chevy is: 12MPG Full tank can fill 8 Gallons of gas. Gas has a fixed price of $2.50 per gallon. MUST: You go to school 4 times a week, and school is 10 miles away. (remember you must calculate round trip). MUST: You go to walmart twice a week to buy groceries and its 8 miles way from HOME. (round trip). MUST : Your nearest Gas station is 2 miles away from HOME. Optional: Your nearest Chik-Fil-A is 7 miles away from HOME, and you go AFTER getting HOME from school. Approximately calculate how many times can you go to chik-fil-A without running out of gas if you have a budget of $30 a week for gas.

Please use the most basic and simple approaches for this problem. We still on the beggining of the Java N I dont want my professor thinking I’m a java god haha thanks!

Explanation / Answer

public class MPGCalculator {

public static void main(String str[]) {

int millage = 12;

int perWeekBugget = 30;

int tankSize = 8;

float perGallonCharge = 2.5F;

float totalGasCanBeFill = 30/2.5F;

System.out.println("totalGasCanBeFill" + totalGasCanBeFill);

int gasFillingCount = (int) Math.ceil(totalGasCanBeFill/tankSize);

System.out.println("Gas filling count " + Math.ceil(totalGasCanBeFill/tankSize));

/**

* RoundTrip of 2 miles distance

*/

int gasStationDistance = 2* 2 * gasFillingCount;

System.out.println("Per weak Gas station distance" + gasStationDistance);

/**

* Round trip of 10 miles distance 4 times

*/

int schoolPerWeekTripDistance = 10*2*4;

/**

* Round Trip of 8 miles distance 4 times

*/

int walmartPerWeekTripDistance = 8*2*2;

/**

* Go to Chick-Fill-A and come back distance will be round trip

*/

int chickFillADistance = 7 * 2;

/**

* Total compalsary distance per weak will be(school distance + walmartDistance + Gas Station Distance)

*/

int perWeekCompalsaryDistance = schoolPerWeekTripDistance + walmartPerWeekTripDistance + gasStationDistance;

System.out.println("perWeekCompalsaryDistance" + perWeekCompalsaryDistance);

/**

* Max distance can be run by Gauge without running out gas.

*/

float maxDistance = totalGasCanBeFill * millage;

System.out.println("max distance : " + maxDistance);

float remaingDistance = maxDistance - perWeekCompalsaryDistance;

int saiflyChickFillACount = (int) Math.floor(remaingDistance/chickFillADistance);

System.out.print("Chik-fill-A safe trip count = " + saiflyChickFillACount);

}

}

Sample output:-

totalGasCanBeFill12.0

Gas filling count 2.0
Per weak Gas station distance8
perWeekCompalsaryDistance120
max distance : 144.0
Chik-fill-A safe trip count = 1