Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,930
    Thanks
    56
    Thanked 552 Times in 549 Posts
    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.

  • Users who have thanked xelawho for this post:

    Mizufall (01-17-2012)

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,930
    Thanks
    56
    Thanked 552 Times in 549 Posts
    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.

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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) >");


    }
    }

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,930
    Thanks
    56
    Thanked 552 Times in 549 Posts
    ha, ha.

    try the java forum. this is javascript.

    good luck!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •