Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: need help on my code

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help on my code

    well i've been trying to fix my code but i dont know what is wrong. im just a beginner in java and was lookong for help on trying to make this program...

    Here is my code:

    File 1
    public class Pet1{
     
    public void displayCourse(String courseName){
    System.out.println("List of Student");
    System.out.println(" 1. Joseph Rosopa");
    }
     
    public void displayCourse2(String couseName2){
    System.out.println("Total Average");
    }
    }

    The error in file 1 is okay since i always get the same error on the past program i used to run.

    File 2
    import java.util.Scanner;
     
    public class File2{
     
    public static void main(String[]args);
    Scanner user_input= = new Scanner (System.in);
    Pet1 myObject = new Pet1();
    System.out.print("Enter Quiz 1: ");
    String courseName = user_input.nextLine();
    System.out.println();
    myObject.displayCourse(courseName);
     
    System.out.print("Enter Quiz 2: ");
    String courseName = user_input.nextLine();
    System.out.println();
    myObject.displayCourse(courseName);
     
    System.out.print("Enter Quiz 3: ");
    String courseName = user_input.nextLine();
    System.out.println();
    myObject.displayCourse(courseName);
     
    }
    }

    And here is the errors i get in file 2
    error1.bmperror1.bmp

    this is supposed to be the output i just save what my friend posted

    untitled.JPG
    Please Help
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: need help on my code

    i dont know what is wrong
    Can you explain?
    Does the code compile? If not copy and paste the errors here.
    Does the code execute without errors? If not same as above.

    Does the code do what you want? If not explain.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Copy any relevant information about the program here on the forum as text.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help on my code

    done sir

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: need help on my code

    Sorry, I missed your explanation of what is wrong with the program.
    Copy the program's output and add comments to it saying what the problem is.


    Please copy and paste the console window here instead of images. There is no way to copy the contents of an image.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help on my code

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\oko>cd "c:\Program Files\Java\jdk1.7.0_07\bin

    C:\Program Files\Java\jdk1.7.0_07\bin>javac Pet2.java
    Pet2.java:6: error: illegal start of expression
    Scanner user_input= = new Scanner (System.in);
    ^
    Pet2.java:8: error: <identifier> expected
    System.out.print("Enter Quiz 1: ");
    ^
    Pet2.java:8: error: illegal start of type
    System.out.print("Enter Quiz 1: ");
    ^
    Pet2.java:10: error: <identifier> expected
    System.out.println();
    ^
    Pet2.java:11: error: <identifier> expected
    myObject.displayCourse(courseName);
    ^
    Pet2.java:11: error: <identifier> expected
    myObject.displayCourse(courseName);
    ^
    Pet2.java:13: error: <identifier> expected
    System.out.print("Enter Quiz 2: ");
    ^
    Pet2.java:13: error: illegal start of type
    System.out.print("Enter Quiz 2: ");
    ^
    Pet2.java:15: error: <identifier> expected
    System.out.println();
    ^
    Pet2.java:16: error: <identifier> expected
    myObject.displayCourse(courseName);
    ^
    Pet2.java:16: error: <identifier> expected
    myObject.displayCourse(courseName);
    ^
    Pet2.java:18: error: <identifier> expected
    System.out.print("Enter Quiz 3: ");
    ^
    Pet2.java:18: error: illegal start of type
    System.out.print("Enter Quiz 3: ");
    ^
    Pet2.java:20: error: <identifier> expected
    System.out.println();
    ^
    Pet2.java:21: error: <identifier> expected
    myObject.displayCourse(courseName);
    ^
    Pet2.java:21: error: <identifier> expected
    myObject.displayCourse(courseName);
    ^
    Pet2.java:24: error: class, interface, or enum expected
    }
    ^
    17 errors
    here is the error

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: need help on my code

    It looks like the compiler thinks all the code in the error messages is not inside of a method.
    Check that you have properly defined the methods. They all require {}s to surround the code that belongs to a method.
    See the tutorial: Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help on my code

    can you help me fix it or something? if its ok thou

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: need help on my code

    Read the tutorial about how to write a method.
    Then look at the code with all the problems and see if you are following the rules for writing a method.
    The error is before the line with the first error. Line 6:
    Pet2.java:6: error: illegal start of expression

    If needed, start over and write the code again being sure to follow the rules for writing a method.
    Write a few lines of code, compile, fix the errors, add a few more lines, compile, fix the errors, add a few more lines, etc
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 04:38 PM
  2. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  3. Help needed - Embedding javascript code in JSP code.
    By chinnu in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: October 29th, 2012, 01:09 PM
  4. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM
  5. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM