Wednesday, July 1, 2015


Car-Pools Savings Calculator

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.
 * @Author: Aghatise Osazuwa
 * Website:
 * Exercise 2.35 - Car-Pool Savings Calculator
 * This Program Calculates Your Daily Driving Cost

import java.util.Scanner;

public class Ex02_35 {
    public static void main (String [] args) {

 Scanner input = new Scanner (;
        int totalMiles; 
        int gasolineCost; 
        int milesPerGallon; 
        int parkingFees; 
        int tolls;
        int dailyDrivingCost;
        System.out.println ("This Application Calculates Your Daily Driving Cost");
        System.out.println (); //displays a blank line
        System.out.print ("Enter Total Miles Driven Per Day: ");
        totalMiles = input.nextInt();
        System.out.print ("Enter Cost Per Gallon Of Gasoline: ");
        gasolineCost = input.nextInt();
        System.out.print ("Enter Average Miles Per Gallon: ");
        milesPerGallon = input.nextInt();
        System.out.print ("Enter Parking Fees Per Day: ");
        parkingFees = input.nextInt();
        System.out.print ("Enter Tolls Per Day: ");
        tolls = input.nextInt();
        dailyDrivingCost = (totalMiles / milesPerGallon) * gasolineCost + parkingFees + tolls;
        System.out.printf ("Your Daily Driving Cost Is: %d\n", dailyDrivingCost);


Click here to see other answers to Java How to Program | Click here to see the same program in C.


  1. I’ve bookmarked your site, and I’m adding your RSS feeds to my Google account.Surya Informatics

  2. This comment has been removed by the author.

  3. When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Surya Informatics


DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately. To get notified of replies or follow-up comments, click the box next to notify me.