Results 1 to 10 of 10
  1. #1
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default Need help please

    Ok, we are building an app using NetBeans6.1 .
    Console menu to
    1) Add an Instructor
    2) Add a student
    or
    3) Exit

    All info must be gained through the Scanner class
    Ask user if they eneter in fo for Student or Instructor
    Ask Last, First, and number of years teaching or student (verify number entered with exception handler)

    Store info in appropriate class (Instructor, Student, inheriting from Person as superclass)

    Student class must glean info through constructor
    Instructor class must glean info through Main and load using Set/Get.

    Echo information back to user without using data from the classes (print from the main method)

    What have I done wrong so far? (I'm trying to input data)
    I get the following gibberish from the environment:
    Compiling 5 source files to C:\Documents and Settings\06111246\Desktop\\build\classes
    C:\Documents and Settings\06111246\Desktop\\Scanner.java:20: <identifier> expected
    System.out.print("Select from the following:\n\n");
    C:\Documents and Settings\06111246\Desktop\\Scanner.java:21: <identifier> expected
    System.out.print("\t 1)Add an Instructor \n \t 2)Add a Student \n \t 3)Exit\n\n" );
    C:\Documents and Settings\06111246\Desktop\\Scanner.java:22: <identifier> expected
    System.in(Choice)
    3 errors


    [code]
    */import javax.swing.*;
    import java.util.*;

    public class Scanner extends Person{
    public static void main(String args[])

    public
    Integer Choice;
    Scanner scanner = new Scanner(System.in);

    System.out.print("Select from the following:\n\n");
    System.out.print("\t 1)Add an Instructor \n \t 2)Add a Student \n \t 3)Exit\n\n" );
    System.in(Choice);
    if (iChoice == 1 )
    {
    Instructor oInstructor;
    oInstructor = new Instructor();
    oInstructor.SetInstructor();
    }
    if (iChoice == 2)
    {
    Student oStudent;
    oStudent = new Student();
    oStudent.SetStudent();
    }
    if (iChoice == 3)
    {
    ;
    }
    else
    ;

    }

    public class Instructor extends Person{
    void SetInstructor()
    {

    System.out.print("Please enter your first name: ");
    String FirstName = Scanner.scanner.next();
    System.out.print("Please enter your last name: ");
    String LastName = Scanner.scanner.next();

    System.out.print("Enter your age: ");
    Age = scanner.nextInt();
    System.out.println(LastName + ", " + FirstName + ", " + Age + " years of age.");
    }
    }

    //import javax.util.*;
    public static void main(String[] args) {
    //String IS;
    Scanner oScanner;
    oScanner = new Scanner(System.in);

    Person oPerson;
    oPerson = new Person();

    Instructor oInstructor;
    oInstructor = new Instructor();

    Student oStudent;
    oStudent = new Student();

    */import javax.swing.*;
    import java.util.Scanner;
    public class Person {


    private


    String FirstName;
    String LastName;
    String iAge;
    int Age;

    /*void SetStudent()
    {

    System.out.print("Please enter your first name: ");
    String FirstName = scanner.next();
    System.out.print("Please enter your last name: ");
    String LastName = scanner.next();

    System.out.print("Enter your age: ");
    Age = scanner.nextInt();
    System.out.println(LastName + ", " + FirstName + ", " + Age + " years of age.");
    }*/


    public class Student extends Person{
    void SetStudent()
    {

    System.out.print("Please enter your first name: ");
    String FirstName = scanner.next();
    System.out.print("Please enter your last name: ");
    String LastName = scanner.next();

    System.out.print("Enter your age: ");
    Age = scanner.nextInt();
    System.out.println(LastName + ", " + FirstName + ", " + Age + " years of age.");
    }
    }


    I only get one day a week with this stuff, unfortunately
    Thanks
    Last edited by Reiyn; 10-18-2008 at 08:04 PM.

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Please use code tags, makes it much more readable.

    I would say... Why do you create your own Scanner class, while there already is one?

    Oh, and please highlight the lines in which the errors occur.
    I die a little on the inside...
    Every time I get shot.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,901
    Rep Power
    25

    Default

    You've named your class with the same name as one of Sun's classes. Poor choice. Make it unique by adding something of yours to the name. For example: MyScanner

    The compiler's error messages have line numbers in them. What code is at lines: 20, 21 and 22?

    public
    Integer Choice;
    Perhaps the public here shouldn't be, since it is inside of the main method. The same with the private inside of the Person method.

    import statements should be together at the beginning of the code.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Norm View Post
    You've named your class with the same name as one of Sun's classes. Poor choice. Make it unique by adding something of yours to the name. For example: MyScanner.
    Yep, that can have some rather unfortunate consequences. Take this for example:

    Java Code:
    public class String {
        public static void main(String[] args) {
            int a = 1;
            a = a++ + 1;
            a = ++a + 1;
            a = a-- - --a;
            System.out.println(a);
        }
    }
    What does that produce? And why?

    Edit: And george, daryll, and captain I'm pretty sure you three have seen this on sun's forums already (in fact, it might have been one of you that posted it), so please don't spoil it for the rest. ;-)
    Last edited by masijade; 10-18-2008 at 09:37 PM.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Nobody have an answer? Or does nobody care? ;-)

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    @masijade: That might be better suited to this thread :)
    Quiz Time

    db

  7. #7
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    It produces NoSuchMEthodError for main.

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Darryl.Burke View Post
    @masijade: That might be better suited to this thread :)
    Quiz Time

    db
    Yeah, I know, but ..... Oh, well. ;-)

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by serjant View Post
    It produces NoSuchMEthodError for main.
    Yes, but why?

  10. #10
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Okay, because your class is "String", and the current package (and most definately the current class) is used before the java.lang package. So, whereas the compiler is looking for a method
    Java Code:
      public static void main (java.lang.String[] args)
    your Class has a main method that takes your String class as the parameter.

    This class also "destroys" all other Classes in the same package, as the "current" package will be searched before the java.lang package.

Posting Permissions

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