我无法访问类

时间:2016-06-30 03:17:17

标签: java arrays methods

这是我第一次尝试在Java中创建对象数组。 我的代码是一个热门的混乱,充满了愚蠢的初学者错误。

package javaapplication62;

import java.util.Scanner;

public class JavaApplication62 {

    public static void main(String[] args) {

        while (true) {

            Scanner in = new Scanner(System.in);

            System.out.println("1.Enroll Student");
            System.out.println("2.Offer Course");

            String name = in.next();
            int choice = in.nextInt();

            if (choice == 1) {

                student_class[] studentList = new student_class[500];

                studentList[0] = new student_class();

                while (true) {

                    System.out.print(" Enter name of the student: ");
                    studentList[0].setName(in.next());

                    System.out.println("");
                    System.out.print(" The student is given the unique ID =  " + studentList[0].getUniqueStudentID() + " and the number of students =  " + studentList[0].getNumberOfStudents());

                    System.out.print("> and the number of students :  ");
                    studentList[0].setnumberOfStudents(in.nextInt);

                    System.out.println("");
                    System.out.print(" Enter the e-mail address of the student: ");
                    studentList[0].setemail(in.next);

                    System.out.print("Enter the semester number of the student:  ");
                    studentList[0].setsemesterNumber(in.nextInt);

                    System.out.print(" Add another student (Y/N): ");
                    char add = in.next().charAt(0);
                    if (add == 'Y' || add == 'y') {

                    }

                    if (add == 'N' || add == 'n') {
                        break;
                    }

                }

            } else if (choice == 2) {

                while (true) {

                    Course[] courseOfferedList;
                    courseOfferedList = new Course[500];
                    courseOfferedList[0] = new Course();

                    System.out.println("Enter the course code : ");
                    courseOfferedList[0].setCourseCode(in.next());

                    System.out.println(" Enter the course title: ");
                    courseOfferedList[0].setCourseTitl(in.next());

                    System.out.println(" Enter the credit hours of the course: ");
                    courseOfferedList[0].setCreditHours(in.nextInt());

                    System.out.print(" Add another course (Y/N): ");
                    char add2 = in.next().charAt(0);
                    if (add2 == 'Y' || add2 == 'y') {
                    }

                    if (add2 == 'N' || add2 == 'n') {
                        break;
                    }

                }

            }

        }
    }

}

学生班。

    public class student_class {
    private String name;
    private int uniqueStudentID;
    private String email;
    private int mobileNumber;
    private int semesterNumber;
    static int numberOfStudents = 0;

    public student_class() {

        name = null;
        uniqueStudentID = 0;
        email = null;
        mobileNumber = 0;
        semesterNumber = 0;
        numberOfStudents++;

    }

    public void setName(String name) {
        this.name = name;
    }

    public void setUniqueStudentID(int uniqueStudentID) {
        this.uniqueStudentID = uniqueStudentID;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setMobileNumber(int mobileNumber) {
        this.mobileNumber = mobileNumber;
    }

    public void setSemesterNumber(int semesterNumber) {
        this.semesterNumber = semesterNumber;
    }

    public void setNumberOfStudents(int numberOfStudents) {
        this.numberOfStudents = numberOfStudents;
    }

    public String getName() {

        return name;
    }

    public int getUniqueStudentID() {

        return uniqueStudentID;

    }

    public String getEmail() {

        return email;

    }

    public int getMobileNumber() {

        return mobileNumber;
    }

    public int getSemesterNumber() {

        return semesterNumber;
    }

    public int getNumberOfStudents() {

        return numberOfStudents;
    }

    void setName() {

    }

    void setuniqueStudentID() {

    }

    void setnumberOfStudents() {

    }

    void setsemesterNumber() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    void setmobileNumber() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    void setemail() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}

课程类:

public class Course {

    private int courseCode;
    private String courseTitl;
    private int creditHours;
    static int numberOfCourses = 0;

    public int getCourseCode() {
        return courseCode;
    }

    public void setCourseCode(int courseCode) {
        this.courseCode = courseCode;
    }

    public String getCourseTitl() {
        return courseTitl;
    }

    public void setCourseTitl(String courseTitl) {
        this.courseTitl = courseTitl;
    }

    public int getCreditHours() {
        return creditHours;
    }

    public void setCreditHours(int creditHours) {
        this.creditHours = creditHours;
    }

    public static int getNumberOfCourses() {
        return numberOfCourses;
    }

    public static void setNumberOfCourses(int numberOfCourses) {
        Course.numberOfCourses = numberOfCourses;   
}}

每次我运行它时都会显示错误:

Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
    at javaapplication62.student_class.setName(student_class.java:11)
    at javaapplication62.JavaApplication62.main(JavaApplication62.java:29)
Java Result: 

这就是我想要的输出

>用于输入和<用于输出

{Display the menu, Choose the menu item}
> 1

> Enter name of the student: john

< The student is given the unique ID = 1 and the number of students = 1

> Enter the e-mail address of the student: john@stu.fau.edu.uk

> Enter the semester number of the student:  3

> Add another student (Y/N): Y

> Enter name of the student: Ibrahim

< The student is given the unique ID = 2 and the number of students = 2

> Enter the e-mail address of the student:  Ibrahim@stu.fau.edu.uk

> Enter the semester number of the student:  3
> Add another student (Y/N): N

{Display the menu, Choose the menu item}
> 2

> Enter the course code: CPCS203

> Enter the course title: Programming 2

> Enter the credit hours of the course: 4
> Add another course (Y/N): Y

> Enter the course code: CPCS204

> Enter the course title: Data Structures

> Enter the credit hours of the course: 3
> Add another course (Y/N): N

{Display the menu, Choose the menu item}

1 个答案:

答案 0 :(得分:1)

您的大多数错误都在canvas { border: 1px solid black; height: 300px; width: 300px; position:relative; } #message { position:absolute; top:150px; left:100px; } 课程中。我已经纠正它们以获得您想要的所需输出。您的所有课程仍然存在许多问题。我会把这件事留给你纠正。

查看更正的评论。

JavaApplication62

此外,我还没有改进你的缩进。你也应该看一下。

这将为您提供问题中提到的输出。但我认为你应该完全重构你的很多代码。