Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19069

Re: Java Help - Beginner

Newsgroups comp.lang.java.programmer
Date 2012-10-02 19:01 -0700
References <eff7a57c-eb1a-4cb5-83d0-dbb6b118e972@googlegroups.com>
Message-ID <e457d5e5-c72e-458e-87f6-247401f92635@googlegroups.com> (permalink)
Subject Re: Java Help - Beginner
From Lew <lewbloch@gmail.com>

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Java Help - Beginner Marie <kaylamariemonk@gmail.com> - 2012-10-02 18:39 -0700
  Re: Java Help - Beginner Lew <lewbloch@gmail.com> - 2012-10-02 19:01 -0700
  Re: Java Help - Beginner Marie <kaylamariemonk@gmail.com> - 2012-10-02 19:25 -0700
    Re: Java Help - Beginner Knute Johnson <nospam@knutejohnson.com> - 2012-10-02 20:11 -0700
  Re: Java Help - Beginner Marie <kaylamariemonk@gmail.com> - 2012-10-02 21:59 -0700
    Re: Java Help - Beginner Joerg Meier <joergmmeier@arcor.de> - 2012-10-03 13:07 +0200
      Re: Java Help - Beginner Marie <kaylamariemonk@gmail.com> - 2012-10-03 05:26 -0700
        Re: Java Help - Beginner bob smith <bob@coolfone.comze.com> - 2012-10-03 07:59 -0700
          Re: Java Help - Beginner Joerg Meier <joergmmeier@arcor.de> - 2012-10-06 14:51 +0200
            Re: Java Help - Beginner Arne Vajhøj <arne@vajhoej.dk> - 2012-10-06 09:10 -0400

csiph-web