Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2012, 06:55 PM   PM User | #1
Mizufall
New to the CF scene

 
Join Date: Jan 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Mizufall is an unknown quantity at this point
Unsure of how to start a program. Help much appreciated!

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
program.
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!
Mizufall is offline   Reply With Quote
Old 01-17-2012, 07:08 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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.
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
Mizufall (01-17-2012)
Old 01-17-2012, 07:18 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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.
xelawho is offline   Reply With Quote
Old 01-17-2012, 07:47 PM   PM User | #4
Mizufall
New to the CF scene

 
Join Date: Jan 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Mizufall is an unknown quantity at this point
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("");
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) >");


}
}
Mizufall is offline   Reply With Quote
Old 01-17-2012, 07:48 PM   PM User | #5
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
ha, ha.

try the java forum. this is javascript.

good luck!
xelawho is offline   Reply With Quote
Reply

Bookmarks

Tags
mizufall "gas station"

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:42 AM.


Advertisement
Log in to turn off these ads.