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

I have a working program but I need to clean up my code apparently. Can you help

ID: 3638774 • Letter: I

Question

I have a working program but I need to clean up my code apparently. Can you help?

Thanks.
John

/**
This program demonstrates the use of escape sequence and the system-out-println system outputs.

@author John Rozsa
@version 2/6/12
CIS 1500

*/

import java.util.Scanner;


public class testgas
{
public static void main (String [] args)
{
double milesdriven, gallons, milespergallon;

double milesperweek;
double milespergallonofauto;
double currentcostofgas;



//get information from the user // declares milespergallon = milesdriven divided by gallons

System.out.println("GAS CALCULATION PROGRAM");
System.out.println("How many miles you drive per week?");
Scanner keyboard = new Scanner(System.in);
milesperweek = keyboard.nextDouble();

System.out.println("How many miles per gallon does your auto get?");
milespergallonofauto = keyboard.nextDouble();

System.out.println("What is the current cost of gas?");
currentcostofgas = keyboard.nextDouble();

double milesperyear = 52.18 * milesperweek;

//display information back to the user

//calculate miles per year

System.out.println ("At " + milesperweek + " miles per week you will travel " + milesperyear + " miles per year.");

System.out.println ("Gallons per week " + (milesperweek/milespergallonofauto));

System.out.println ("Gallons per year " + (milesperweek/milespergallonofauto * 365));

System.out.println ("With gas at " + (currentcostofgas) + " per gallon, you will spend:");

System.out.println ("Gas expence per week: " + (currentcostofgas) * milesperweek/milespergallonofauto);

System.out.println ("Gas expense per year: " + (currentcostofgas) * milesperyear/milespergallonofauto);

System.out.println ("If gas goes up by one dollar per gallon to " + (currentcostofgas + 1) + " per gallon, you will spend:");

System.out.println ("Gas expense per week: " + (currentcostofgas + 1) * milesperweek/milespergallonofauto);

System.out.println ("Gas expense per year: " + (currentcostofgas + 1) * milesperyear/milespergallonofauto);

































}
}

Explanation / Answer

See here for the code with good indentation and syntax highlighting: http://pastebin.com/di8K6ne1 /** This program demonstrates the use of escape sequence and the system-out-println system outputs. @author John Rozsa @version 2/6/12 CIS 1500 */ import java.util.Scanner; public class testgas { public static void main (String [] args) { double milesdriven, gallons, milespergallon, milesperweek, milespergallonofauto, currentcostofgas, milesperyear; //get information from the user // declares milespergallon = milesdriven divided by gallons System.out.println("WELCOME TO THE GAS CALCULATION PROGRAM."); System.out.println("How many miles you drive per week?"); Scanner keyboard = new Scanner(System.in); milesperweek = keyboard.nextDouble(); System.out.println("How many miles per gallon does your auto get?"); milespergallonofauto = keyboard.nextDouble(); System.out.println("What is the current cost of gas?"); currentcostofgas = keyboard.nextDouble(); milesperyear = 52.18 * milesperweek; //display information back to the user //calculate miles per year System.out.println ("At " + milesperweek + " miles per week you will travel " + milesperyear + " miles per year. "); System.out.println ("Gallons per week " + (milesperweek/milespergallonofauto) + " "); System.out.println ("Gallons per year " + (milesperweek/milespergallonofauto * 365) + " "); System.out.println ("With gas at " + (currentcostofgas) + " per gallon, you will spend: "); System.out.println ("Gas expence per week: " + (currentcostofgas) * milesperweek/milespergallonofauto + " "); System.out.println ("Gas expense per year: " + (currentcostofgas) * milesperyear/milespergallonofauto + " "); System.out.println ("If gas goes up by one dollar per gallon to " + (currentcostofgas + 1) + " per gallon, you will spend: "); System.out.println ("Gas expense per week: " + (currentcostofgas + 1) * milesperweek/milespergallonofauto + " "); System.out.println ("Gas expense per year: " + (currentcostofgas + 1) * milesperyear/milespergallonofauto + " "); } } Please check if this is okay!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote