Java Code can't succeed to compile - Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chiasien
    New Member
    • Aug 2007
    • 2

    Java Code can't succeed to compile - Help

    Hi All,

    I need help!! Please refer below for my java code. There was error some where inside! But need those expert to help me complete my Java code without error.... Please help!! Thanks alot.

    Java Code:

    //Import statement for the JoptionPane
    import javax.swing.JOp tionPane;

    // Definition of class Student
    public class Student1 {

    //Attributes
    private String name;
    private int ID;
    private String Course;

    // create constructor with initialising name, ID and course to "Not allocated", a and "None" respectively.
    Student(){
    System.out.prin tln ("Student Detail");
    name = "Not allocated";
    ID = 0;
    Course = "None";
    }

    // create another constructor with Initialising name, ID and course for user to input
    Student (String inName, int inID, String inCourse){
    name = inName;
    ID = inID;
    Course = inCourse;
    }

    // Get the value of attribute Name
    public String getName(){
    return name;
    }
    // Get the value of attribute ID
    public int getID(){
    return ID;
    }
    // Get the value of attribute Course
    public String getCourse(){
    return Course;
    }

    // Show the Student Detail on the screen
    public static void main(String args []){

    String inName, inID, inCourse;
    char name, Course;
    int ID;

    //Create a dialog box for user to key in the name, ID, & Course.
    inName =
    JOptionPane.sho wInputDialog("S tudent Name: ");
    name = inName.charAt(1 5);

    inID =
    JOptionPane.sho wInputDialog("S tudent ID: ");
    ID = Integer.parseIn t(inID);

    inCourse =
    JOptionPane.sho wInputDialog("S tudent Course: ");
    name = inName.charAt(1 5);

    // system output with first constructor
    Student Detail1 = new Student ();
    System.out.prin tln("Name is: " + Detail1.getName ());
    System.out.prin tln("ID is: " + Detail1.getID() );
    System.out.prin tln("Course is: " + Detail1.getCour se());

    // system output with second constructor
    Student Detail2 = new Student (tanchunho, 0407010231, Engineering);
    System.out.prin tln("Name is: " + Detail2.getName ());
    System.out.prin tln("ID is: " + Detail2.getID() );
    System.out.prin tln("Course is: " + Detail2.getCour se());

    }

    }
  • madhoriya22
    Contributor
    • Jul 2007
    • 251

    #2
    Originally posted by chiasien
    Hi All,

    I need help!! Please refer below for my java code. There was error some where inside! But need those expert to help me complete my Java code without error.... Please help!! Thanks alot.

    Java Code:
    Code:
    //Import statement for the JoptionPane
    import javax.swing.JOptionPane;
     
    // Definition of class Student
    public class Student1 {
     
    //Attributes
    private String name;
    private int ID;
    private String Course;
     
    // create constructor with initialising name, ID and course to "Not allocated", a and "None" respectively. 
    Student(){
    System.out.println ("Student Detail");
    name = "Not allocated";
    ID = 0;
    Course = "None";
    }
     
    // create another constructor with Initialising name, ID and course for user to input
    Student (String inName, int inID, String inCourse){
    name = inName;
    ID = inID;
    Course = inCourse;
    }
     
    // Get the value of attribute Name 
    public String getName(){
    return name;
    } 
    // Get the value of attribute ID
    public int getID(){
    return ID;
    } 
    // Get the value of attribute Course
    public String getCourse(){
    return Course; 
    } 
     
    // Show the Student Detail on the screen 
    public static void main(String args []){
     
    String inName, inID, inCourse; 
    char name, Course; 
    int ID; 
     
    //Create a dialog box for user to key in the name, ID, & Course.
    inName =
    JOptionPane.showInputDialog("Student Name: ");
    name = inName.charAt(15); 
     
    inID =
    JOptionPane.showInputDialog("Student ID: "); 
    ID = Integer.parseInt(inID);
     
    inCourse =
    JOptionPane.showInputDialog("Student Course: "); 
    name = inName.charAt(15);
     
    // system output with first constructor
    Student Detail1 = new Student ();
    System.out.println("Name is: " + Detail1.getName());
    System.out.println("ID is: " + Detail1.getID());
    System.out.println("Course is: " + Detail1.getCourse());
     
    // system output with second constructor
    Student Detail2 = new Student (tanchunho, 0407010231, Engineering); 
    System.out.println("Name is: " + Detail2.getName());
    System.out.println("ID is: " + Detail2.getID());
    System.out.println("Course is: " + Detail2.getCourse());
     
    }
     
    }
    Hi,
    Please use code tags while posting code.
    You havn't tell that what is the error and where it is in your code. So without this information nobody can help you in solving your problem.
    So next time please be specific with your problem.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Also note that a constructor must have exactly the same name as the name of it's class.

      Comment

      Working...