Monday, October 10, 2011

ITC 110 Assignment 1 in Java

This is the Java equivalent of the first ITC 110 assignment. I will do the other assignments in ITC 110 and also post them here


package Mileage;
import java.util.Scanner;
import java.io.*;
public class CalcMileage {

 /**
  * This is a simple program to Calculate
  * miles per gallon
  * it is the equivalent to ITC110
  * assignment 1
  * steve conger 9-26-2011
  */
 public static void main(String[] args) {
  //declare Scanner
  Scanner reader = new Scanner(System.in);
  //declare variables
  double beginMileage;
  double endMileage;
  double gallons;
  double pricePerGallon;
  double milesPerGallon;
  double costPerMile;
  //get input
  System.out.println("Enter the beginning mileage");
  beginMileage=reader.nextDouble();
  System.out.println("Enter the ending mileage");
  endMileage=reader.nextDouble();
  System.out.println("Enter the number of gallons");
  gallons=reader.nextDouble();
  System.out.println("Enter the price per gallon");
  pricePerGallon=reader.nextDouble();
  
  //do processing of input
  milesPerGallon=(endMileage-beginMileage)/gallons;
  costPerMile=pricePerGallon /(endMileage-beginMileage);
  
  //output results
  System.out.print("Your miles per gallon is ");
  System.out.format("%.2f",milesPerGallon);
  System.out.println();
  System.out.print("the cost per mile is ");
  System.out.format("%.2f",costPerMile);
 }

}

No comments:

Post a Comment