The program below is the answer to Deitel’s Java How to Program (9th Edition) Chapter 2 Exercise 2.35.
Question: Research several car-pooling websites. Create an application that calculates your daily driving cost, so that you can estimate how much money could be saved by car pooling, which also has other advantages such as reducing carbon emissions and reducing traffic congestion. The application should input the following information and display the user’s cost per day of driving to work:
a) Total miles driven per day.
b) Cost per gallon of gasoline.
c) Average miles per gallon.
d) Parking fees per day.
e) Tolls per day.
Click here to see other answers to Java How to Program | Click here to see the same program in C.
b) Cost per gallon of gasoline.
c) Average miles per gallon.
d) Parking fees per day.
e) Tolls per day.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.35 - Car-Pool Savings Calculator<br /> * This Program Calculates Your Daily Driving Cost<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class Ex02_35 {<br /> public static void main (String [] args) {<br /><br /> Scanner input = new Scanner (System.in);<br /> <br /> int totalMiles; <br /> int gasolineCost; <br /> int milesPerGallon; <br /> int parkingFees; <br /> int tolls;<br /> int dailyDrivingCost;<br /> <br /> System.out.println ("This Application Calculates Your Daily Driving Cost");<br /> <br /> System.out.println (); //displays a blank line<br /> <br /> System.out.print ("Enter Total Miles Driven Per Day: ");<br /> totalMiles = input.nextInt();<br /> System.out.print ("Enter Cost Per Gallon Of Gasoline: ");<br /> gasolineCost = input.nextInt();<br /> System.out.print ("Enter Average Miles Per Gallon: ");<br /> milesPerGallon = input.nextInt();<br /> System.out.print ("Enter Parking Fees Per Day: ");<br /> parkingFees = input.nextInt();<br /> System.out.print ("Enter Tolls Per Day: ");<br /> tolls = input.nextInt();<br /> <br /> dailyDrivingCost = (totalMiles / milesPerGallon) * gasolineCost + parkingFees + tolls;<br /> <br /> System.out.println("n");<br /> System.out.printf ("Your Daily Driving Cost Is: %dn", dailyDrivingCost);<br /><br /> }<br />}<br /> |
Click here to see other answers to Java How to Program | Click here to see the same program in C.