Results 1 to 7 of 7
  1. #1
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Question Java Newbie NEED HELP with simple CODE

    Hi

    My HW states I need to create a program that will allow user enter "LENGHT" + "WIDTH" where java will make a simple calculation for him such as how many "SQUARE FEET" and "ACREAGE" is the specific terrain. So far this is what I've got but getting bunch of errors and can't figure it out. I'm using jgrasp for the java project. Please help!!!

    public class Assignment1b
    {
    public static void main(String[] args)
    {
    Scanner keyboard = new Scanner (System.in); //declaration
    int computAcre;
    int computeAcre = keyboard.nextInt(); //integar name

    System.out.println ("Enter the lenght in feet: "); //user enters lenght for calculation
    System.out.println ("Enter the width in feet: "); //user enters width for calculation

    computeAcre = keyboard.nextInt();

    System.out.println ("The size of the land is square feet is: " * computeAcre);
    System.out.println ("The size of the land in acres is: " * computeAcre / 43,560);

    }
    }

    *NOTE* user enters length and width where the output shows him answer in square feet and acres. What am I missing here?-CODE's ERRORS are as follow:

    ----jGRASP exec: javac -g Assignment1b.java
    Assignment1b.java:17: cannot find symbol
    symbol : class Scanner
    location: class Assignment1b
    Scanner keyboard = new Scanner (System.in); //declaration
    ^
    Assignment1b.java:17: cannot find symbol
    symbol : class Scanner
    location: class Assignment1b
    Scanner keyboard = new Scanner (System.in); //declaration
    ^
    Assignment1b.java:26: operator * cannot be applied to java.lang.String,int
    System.out.println ("The size of the land is square feet is: " * computeAcre);
    ^
    Assignment1b.java:27: operator * cannot be applied to java.lang.String,int
    System.out.println ("The size of the land in acres is: " * computeAcre / 43,560);
    ^
    Assignment1b.java:27: cannot find symbol
    symbol : method println(int,int)
    location: class java.io.PrintStream
    System.out.println ("The size of the land in acres is: " * computeAcre / 43,560);
    ^
    5 errors

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Newbie NEED HELP with simple CODE

    Quote Originally Posted by xcaldk74 View Post
    ----jGRASP exec: javac -g Assignment1b.java
    Assignment1b.java:17: cannot find symbol
    symbol : class Scanner
    location: class Assignment1b
    Scanner keyboard = new Scanner (System.in); //declaration
    ^
    Assignment1b.java:17: cannot find symbol
    symbol : class Scanner
    location: class Assignment1b
    Scanner keyboard = new Scanner (System.in); //declaration
    ^
    Have you imported the Scanner class?

    Assignment1b.java:26: operator * cannot be applied to java.lang.String,int
    System.out.println ("The size of the land is square feet is: " * computeAcre);
    ^
    Assignment1b.java:27: operator * cannot be applied to java.lang.String,int
    System.out.println ("The size of the land in acres is: " * computeAcre / 43,560);
    ^
    The error is speaking the truth -- you can't have a * symbol where you're using it. Perhaps you want to use another symbol for String concatenation? The + usually works well for me.

  3. #3
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Default Re: Java Newbie NEED HELP with simple CODE

    Hi Fubarable and THANK YOU For a quick response:

    This is what I come up with:

    import java.util.Scanner;
    public class Assignment1b_test
    {
    public static void main(String[] args)
    {
    Scanner keyboard = new Scanner (System.in);

    int lenght = 4356;
    int width = 10;
    //int squarefoot;
    //int acres;
    int squarefoot = lenght*width;
    //int squarefoot = keyboard.nextInt();
    System.out.println("The size of the land in square feet is: " + squarefoot);
    }
    }

    outcome:
    ----jGRASP exec: java Assignment1b_test
    The size of the land in square feet is: 43560

    ----jGRASP: operation complete.

    everything is fine BUT what my HW is asking me to do is to ALLOW USER to input the numbers not me and let java compute it. I'm still waiting for my class book to arrive so I don't have any resource to look at. the only think I have from my notes would be as follow to use:

    Scanner keyboard = new Scanner (System.in);

    and

    int squarefoot = keyboard.nextInt();


    BUT i don't know how to implement that into the code so the USER is responsible for the integer input. Please advise.

    Regards,
    dk

  4. #4
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Default Re: Java Newbie NEED HELP with simple CODE

    **UPdATE

    **UPDATE:

    import java.util.Scanner;
    public class Assignment1b_test
    {
    public static void main(String[] args)
    {
    Scanner keyboard = new Scanner (System.in);

    //int lenght = keyboard.nextInt(4356);
    //int width = keyboard.nextInt(10);

    int lenght = 4356;
    int width = 10;

    System.out.println("Enter the lenght in feet: ");
    //System.out.print("Enter the width in feet: ");

    int squarefoot = lenght*width;
    //int acres = squarefoot/43560;

    System.out.println("The size of the land in square feet is: " + squarefoot);
    //System.out.println("The size of the land in acres is: " + acres);
    }
    }

    outcome:
    ----jGRASP exec: java Assignment1b_test
    Enter the lenght in feet: The size of the land in square feet is: 43560

    ----jGRASP: operation complete.

    **HELP <--
    1) how do I make so the user can input the integers i know its using:

    int lenght = keyboard.nextInt(4356);
    int width = keyboard.nextInt(10);

    is above right?

    2) in the text : Enter the lenght in feet: The size of the land in square feet is: 43560 this should be as follow:
    Enter the lenght in feet:
    The size of the land in square feet is: 43560

    I am putting System.out.println "ln" <- which should get next print at the bottom

    Please help me out :(

  5. #5
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Default Re: Java Newbie NEED HELP with simple CODE

    IS THIS GOOD NOW:

    import java.util.Scanner;
    public class Assignment1b_test
    {
    public static void main(String[] args)
    {
    Scanner keyboard = new Scanner (System.in);

    int lenght = keyboard.nextInt();
    int width = keyboard.nextInt();

    //int lenght = 4356;
    //int width = 10;

    System.out.println("Enter the lenght in feet: " + lenght);
    System.out.println("Enter the width in feet: " + width);
    System.out.println("-----------------------------------");

    int squarefoot = lenght*width;
    int acres = squarefoot/43560;

    System.out.println("The size of the land in square feet is: " + squarefoot);
    System.out.println("The size of the land in acres is: " + acres);
    }
    }

    OUTCOME

    ----jGRASP exec: java Assignment1b_test
    4356
    10
    Enter the lenght in feet: 4356
    Enter the width in feet: 10
    -----------------------------------
    The size of the land in square feet is: 43560
    The size of the land in acres is: 1

    ----jGRASP: operation complete.

  6. #6
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Default Re: Java Newbie NEED HELP with simple CODE

    **ALSO what should i do to add text to instead of empty field:
    "added text here i.e length:" 4356
    width: 10

    Enter the lenght in feet: 4356
    Enter the width in feet: 10
    -----------------------------------
    The size of the land in square feet is: 43560
    The size of the land in acres is: 1

    Please advise

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Newbie NEED HELP with simple CODE

    You want to print the prompt immediately before getting the input. So you will often have a System.out.print(promptString); followed by line that uses Scanner to get the input, and repeat as needed.

    e.g.,

    Java Code:
    System.out.print("Enter your name: ");
    String name = keyboard.nextLine();
    
    System.out.print("Enter your age: ");
    int age = keyboard.nextInt();
    keyboard.nextLine();  // this is needed after nextInt to handle end of line token

Similar Threads

  1. Newbie need help w/ Java code :)
    By mailboxo71 in forum New To Java
    Replies: 5
    Last Post: 01-21-2011, 07:48 AM
  2. java newbie..simple mail server implementation
    By saurabh4dudes in forum Networking
    Replies: 1
    Last Post: 03-12-2010, 03:46 PM
  3. Simple newbie codes..
    By kampong in forum New To Java
    Replies: 9
    Last Post: 03-11-2009, 03:10 PM
  4. please help in java code (simple)
    By rahul_swe23 in forum New To Java
    Replies: 4
    Last Post: 01-26-2009, 04:32 PM
  5. Need Help With VERY Simple Program -- Newbie!!!
    By somethingfast in forum New To Java
    Replies: 17
    Last Post: 11-25-2008, 08:38 AM

Posting Permissions

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