Java Help - Beginner

Discussion in 'Java' started by Marie, Oct 3, 2012.

  1. Marie

    Marie Guest

    Hi, Im new at Java and have to do an assignment on it. First thing I need help with is the computer I am trying to compile the java code on doesn't allow me to so if anyone can tell me if the below code works to so that usersinput the values of the int such as mcLane ect. that would be wonderful :)The next problem I'm having is applying conditions to the ints such as mcLane having to be between 1-4, sum of all lanes (mc, ac, et) have to be greater less then or equal to 8 and sum of mcLane and acLane has to be less thenor equal to 4. I'm clueless whether to use a boolean condition or who to loop it back to the user input until the condition is met. Any help would begreatly appreciated, Thank you :)

    package Jtoll;
    import java.util.Scanner;
    public class Jtoll {public static void main(String[] args) {
    int mcLane;
    Scanner user_input = new Scanner(System.in);
    System.out.println("Input number of MC lanes");
    mcLane = s.nextDouble();

    int acLane;
    System.out.println("Input number of AC lanes");
    acLane = s.nextDouble();

    int etlane;
    System.out.println("Input number of ET lanes");
    etLane = s.nextDouble();

    int costMcStaff;
    System.out.println("Input cost of MC Staff");
    costMcStaff= s.nextDouble();

    int costAClane;
    System.out.println("Input cost of running AC lane");
    costAClane = s.nextDouble();

    int costETlane;
    System.out.println("Input cost of running ET lane");
    costETlane = s.nextDouble();

    int timeMClane;
    System.out.println("Input time taken to process one vehicle in MC lane");
    timeMClane = s.nextDouble();

    int timeAClane;
    System.out.println("Input time taken to process one vehicle in AC lane");
    timeAClane = s.nextDouble();

    int timeETlane;
    System.out.println("Input time taken to process one vehicle in ET lane");
    timeETlane = s.nextDouble();

    int priceV1;
    System.out.println("Input price for V1");
    priceV1 = s.nextDouble();

    int priceV2;
    System.out.println("Input price for V2");
    priceV2= s.nextDouble();

    int priceV3;
    System.out.println("Input price for V3");
    priceV3 = s.nextDouble();
    }
    }
    Marie, Oct 3, 2012
    #1
    1. Advertising

  2. Marie

    Lew Guest

    Marie wrote:
    > Hi, Im new at Java and have to do an assignment on it. First thing I need help with is the computer I


    Don't you have teaching assistants or more advanced students to ask?

    > am trying to compile the java code on doesn't allow me to so if anyone can tell me if the below code


    When you say, "doesn't allow", what is it doing instead?

    COPY AND PASTE any error messages, warnings, etc., into your response.
    Paraphrasing usually doesn't work.

    > works to so that users input the values of the int such as mcLane ect. that would be wonderful :)


    What do you mean by "works"? You have things accepting input in that code, but nothing
    that uses the input, e.g., to test it or show it to anybody.

    > The next problem I'm having is applying conditions to the ints such as mcLane having to be between
    > 1-4, sum of all lanes (mc, ac, et) have to be greater less then or equal to 8 and sum of mcLane and


    "lanes"?

    > acLane has to be less then or equal to 4. I'm clueless whether to use a boolean condition or who to
    > loop it back to the user input until the condition is met.
    >
    > package Jtoll;


    This doesn't affect your correctness, but conventionally most Java shops use only
    lower-case letters for package names.

    > import java.util.Scanner;
    >
    > public class Jtoll {public static void main(String[] args) {


    Please indent for readability.

    There's no reason to jam everything on one line like that.

    The Java coding conventions are spelled out here:
    http://www.oracle.com/technetwork/java/codeconv-138413.html

    > int mcLane;
    >
    > Scanner user_input = new Scanner(System.in);
    >
    > System.out.println("Input number of MC lanes");
    >
    > mcLane = s.nextDouble();


    You said that the variable is an 'int'. Why are you trying to give it a 'double'?

    What do you do with mcLane' after this?

    How can you tell if it has the right value?
    ('System.out.println()')


    > int acLane;


    Ditto. You declare it 'int'.

    > System.out.println("Input number of AC lanes");
    > acLane = s.nextDouble();


    Then feed it a 'double'.

    > int etlane;
    > System.out.println("Input number of ET lanes");


    Then completely fail to use it.

    > etLane = s.nextDouble();
    >
    > int costMcStaff;


    Ditto.

    > System.out.println("Input cost of MC Staff");
    > costMcStaff= s.nextDouble();
    >
    > int costAClane;


    And so forth.

    > System.out.println("Input cost of running AC lane");
    > costAClane = s.nextDouble();
    >
    > int costETlane;
    > System.out.println("Input cost of running ET lane");
    > costETlane = s.nextDouble();
    >
    > int timeMClane;
    > System.out.println("Input time taken to process one vehicle in MC lane");
    > timeMClane = s.nextDouble();
    >
    > int timeAClane;
    > System.out.println("Input time taken to process one vehicle in AC lane");
    > timeAClane = s.nextDouble();
    >
    > int timeETlane;
    > System.out.println("Input time taken to process one vehicle in ET lane");
    > timeETlane = s.nextDouble();
    >
    > int priceV1;
    > System.out.println("Input price for V1");
    > priceV1 = s.nextDouble();
    >
    > int priceV2;
    > System.out.println("Input price for V2");
    > priceV2= s.nextDouble();
    >
    > int priceV3;
    > System.out.println("Input price for V3");
    > priceV3 = s.nextDouble();
    > }
    > }


    You can't just tell the compiler that a variable is of type 'A', then try to jam
    an unrelated type 'B' into it.

    Even with related types, there are issues. With those there are ways around
    the issues, but why go through all that?

    If someone enters "4.3315678", how will an 'int' hold that?

    --
    Lew
    Lew, Oct 3, 2012
    #2
    1. Advertising

  3. Marie

    Marie Guest

    It keeps saying that javac is not recognized as an internal or external command. I've tried following tips to fix this but none have worked on my computer. As I said I am very new at java so I know that the code is highly flawed at present. The user values or need to be ints as they have to be wholenumbers so thanks for pointing that out :)by lanes i mean the sum of the ints mcLane, etLane and acLane can not exceed 8. The second part of the assignment uses the input but I didn't want to continue until I'd sorted out the first part. I just needed confirmation that the input from the user then allocates to the corresponding variable and how to add conditions to the variable. Thanks for your time responding :)
    Marie, Oct 3, 2012
    #3
  4. On 10/2/2012 7:25 PM, Marie wrote:
    > It keeps saying that javac is not recognized as an internal or
    > external command. I've tried following tips to fix this but none have
    > worked on my computer. As I said I am very new at java so I know that
    > the code is highly flawed at present. The user values or need to be
    > ints as they have to be whole numbers so thanks for pointing that out
    > :)by lanes i mean the sum of the ints mcLane, etLane and acLane can
    > not exceed 8. The second part of the assignment uses the input but I
    > didn't want to continue until I'd sorted out the first part. I just
    > needed confirmation that the input from the user then allocates to
    > the corresponding variable and how to add conditions to the variable.
    > Thanks for your time responding :)
    >


    You are using Windows? You need to set the path to the compiler. On XP
    (Vista and 7 are similar), Open the Control Panel, select Performance
    and Maintenance, select System to bring up the System Properties dialog.
    Select the Advanced tab, press the Environment Variables button, and
    edit or create a new PATH environment variable that points to the Java
    compiler. On my XP computer it is
    C:\Program Files\Java\jdk1.7.0_07\bin.

    Then open a new command prompt and the path should allow you to run the
    java.exe program from the command line.

    --

    Knute Johnson
    Knute Johnson, Oct 3, 2012
    #4
  5. Marie

    Marie Guest

    I'm using Windows 7, I've tried adding it as a path with unfortunately no success. I'll keep trying though :)
    Marie, Oct 3, 2012
    #5
  6. Marie

    Joerg Meier Guest

    On Tue, 2 Oct 2012 21:59:54 -0700 (PDT), Marie wrote:

    > I'm using Windows 7, I've tried adding it as a path with unfortunately no success. I'll keep trying though :)


    This might be a silly question, but have you actually downloaded and
    installed the JDK ? It doesn't come with Windows, you know ;-)

    http://www.oracle.com/technetwork/java/javase/downloads/jdk7u7-downloads-1836413.html

    Liebe Gruesse,
    Joerg

    --
    Ich lese meine Emails nicht, replies to Email bleiben also leider
    ungelesen.
    Joerg Meier, Oct 3, 2012
    #6
  7. Marie

    Marie Guest

    I have installed it, ive even tried uninstalling and re-installing it but no luck there either
    Marie, Oct 3, 2012
    #7
  8. Marie

    bob smith Guest

    On Wednesday, October 3, 2012 7:26:40 AM UTC-5, Marie wrote:
    > I have installed it, ive even tried uninstalling and re-installing it but no luck there either


    You need to make sure you add the bin directory to the path.


    c:\jdk\bin
    bob smith, Oct 3, 2012
    #8
  9. Marie

    Joerg Meier Guest

    On Wed, 3 Oct 2012 07:59:44 -0700 (PDT), bob smith wrote:

    > On Wednesday, October 3, 2012 7:26:40 AM UTC-5, Marie wrote:
    >> I have installed it, ive even tried uninstalling and re-installing it but no luck there either

    > You need to make sure you add the bin directory to the path.


    > c:\jdk\bin


    It is very unlikely that would be the path. Odds are it is either

    C:\Program Files\Java\jdk1.7.0_07\bin

    or

    C:\Program Files (x86)\Java\jdk1.7.0_07\bin

    depending on whether she installed 32 or 64 bit.

    Liebe Gruesse,
    Joerg

    --
    Ich lese meine Emails nicht, replies to Email bleiben also leider
    ungelesen.
    Joerg Meier, Oct 6, 2012
    #9
  10. Marie

    Arne Vajhøj Guest

    On 10/6/2012 8:51 AM, Joerg Meier wrote:
    > On Wed, 3 Oct 2012 07:59:44 -0700 (PDT), bob smith wrote:
    >> On Wednesday, October 3, 2012 7:26:40 AM UTC-5, Marie wrote:
    >>> I have installed it, ive even tried uninstalling and re-installing it but no luck there either

    >> You need to make sure you add the bin directory to the path.

    >
    >> c:\jdk\bin

    >
    > It is very unlikely that would be the path. Odds are it is either
    >
    > C:\Program Files\Java\jdk1.7.0_07\bin
    >
    > or
    >
    > C:\Program Files (x86)\Java\jdk1.7.0_07\bin
    >
    > depending on whether she installed 32 or 64 bit.


    c:\jdk\bin may have been intended to be read as:
    c:\wherever-you-installed-the-jdk\bin

    I don't install JDK in Program Files.

    Arne
    Arne Vajhøj, Oct 6, 2012
    #10
  11. Marie

    1968

    Joined:
    Oct 8, 2012
    Messages:
    5
    How do I get some music on
    my phone
    1968, Oct 8, 2012
    #11
  12. Marie

    1968

    Joined:
    Oct 8, 2012
    Messages:
    5
    How do I get some music on my phone?
    1968, Oct 8, 2012
    #12
  13. Marie

    1968

    Joined:
    Oct 8, 2012
    Messages:
    5
    tina bell

    Why is no one replying to My questions, i'm being ignored please help
    1968, Oct 8, 2012
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    559
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  2. Kristin

    Beginner Java...need help!

    Kristin, Mar 21, 2006, in forum: Java
    Replies:
    5
    Views:
    486
    Bonney Armstrong
    Mar 22, 2006
  3. Rensjuh
    Replies:
    7
    Views:
    949
    Mabden
    Sep 2, 2004
  4. Replies:
    2
    Views:
    337
    TechBookReport
    Sep 5, 2006
  5. william nelson

    Beginner's Beginner

    william nelson, Apr 11, 2011, in forum: Ruby
    Replies:
    7
    Views:
    199
    7stud --
    Apr 12, 2011
Loading...

Share This Page