View Full Version : Unsure of how to start a program. Help much appreciated!

01-17-2012, 06:55 PM
I'm in a first year programming class and I'm unsure how to start or even structure a problem.

The instructions go like this...

You are to write a program that will allow a user to pump gas into his car. Like at a gas station,
the second-by-second gallons filled and cost should be displayed to the user.
The user should provide you with:
• the size of their car’s tank
• an estimate of how many gallons of gas are currently in their tank
The user should select a grade of gas to fill their tank with:
• Regular
• Premium
• Super
The price per gallon for each of these must be stored and used as a constant variable in your
You need to calculate the total cost of gas; however, you must print to the screen the current
cost and gallons filled for every 0.1 gallons of gas added. In order to make the output more
readable, please delay the screen by 50 milliseconds when printing.

I'm not asking for this to be done for me I just I'.m not sure where to start I realize it will require a loop but that's about it any help is really appreciated!

01-17-2012, 07:08 PM
personally, I find it useful to design the interface first - the html.

then you need js code to collect the user-entered data and store it as variables.

then you need functions to manipulate that data and produce a result

then you need a way of displaying that result. If you try to do all that and it still isn't working, post some code with specific questions, you are sure to get some help.

01-17-2012, 07:18 PM
oh - and I'm not sure it will require a loop - all of the calculations are fairly straightforward mathematics and the updating display can be done using setInterval. :thumbsup:

01-17-2012, 07:47 PM
Alright so here is what I have so far I've been researching setInterval however, I'm a bit unsure how to implement it. P.S. Thank you for helping me :)

import java.util.Scanner;

public class GasStationMain {

private static Scanner in = new Scanner(System.in);

public static void main(String[] args) {
double userinput;
double gasTank = 0;
double regular = 1.70;
double premium = 1.75;
double superGas = 1.80;
System.out.println("Welcome to a generic Gas Station!");
System.out.println("How big is your gas tank? (in gallons) > ");
gasTank = in.nextDouble();
System.out.println("How much gas do you think you already have? (guess in gallons) > ");
userinput = in.nextDouble();
gasTank -= userinput;
System.out.println("1. Regular $1.70 per gallon");
System.out.println("2. Premium $1.75 per gallon");
System.out.println("3. Super $1.80 per gallon");
System.out.println("What type of gas do you want? (1-3) >");


01-17-2012, 07:48 PM
ha, ha.

try the java forum. this is javascript.

good luck!