Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将主类中字符串的值设置为setter 公共课堂学生测试{ 公共静态void main(字符串参数[]){ 本科uG1=新本科(); uG1.设定名称(“约翰”); uG1.setMatric(“0192345”); System.out.println(“本科学生信息”); uG1.setCourse(新课程(“CS1103”,3)); uG1.设置课程(新课程(“IT4504”,3)); uG1.displayStudentInfo(); System.out.println(“”); 博士后pG1=新博士后(); pG1.设置名称(“Sam”); pG1.setMatric(“G015466”); pG1.setResearch(“经验软件工程”); pG1.setResearch(“数据挖掘”); System.out.println(“研究生信息”); pG1.displayStudentInfo(); } } 公共课{ 私有字符串courseName; 私人时间; 公共课程(字符串n,int c){ courseName=n; crhour=c; } 公共void setCourseName(字符串课程){ 课程名称=课程; } 公共字符串getCourseName(){ 返回courseName; } 公共无效setCreditH(内部c){ crhour=c; } } 公立班学生{ 私有字符串matric=“-matric required-”; 私有字符串name=“-name required-”; 公立学生(){ } 公共void集合名(字符串n){ 如果(n.matches(“[a-zA-Z]+”)==false) System.out.println(“无效名称”); 其他的 name=n; } 公共字符串getName(){ 返回名称;} 公共无效集合矩阵(字符串m){ 矩阵=m;} 公共字符串getMatric(){ 返回矩阵;} } 公立本科学生{ 私人课程讲师[]; 私有整数指数=0; 公共本科(){ 课程列表[]=新课程[7];} 公共课程(课程名称){ //课程列表[]=新课程[2]; } 公共课程[]getCourse(){ 返回课程列表;} public void displayStudentInfo(){ System.out.println(“Name:+getName()); System.out.println(“矩阵:+getMatric()); System.out.println(“课程列表:+getCourse()); }} 公立班研究生{ 私人字符串研究区[]; 私有整数指数=0; 公共研究生() { researchArea=新字符串[5]; } 公共研究(字符串研究){ 对于(指数=0;指数_Java_Arrays - Fatal编程技术网

Java 无法将主类中字符串的值设置为setter 公共课堂学生测试{ 公共静态void main(字符串参数[]){ 本科uG1=新本科(); uG1.设定名称(“约翰”); uG1.setMatric(“0192345”); System.out.println(“本科学生信息”); uG1.setCourse(新课程(“CS1103”,3)); uG1.设置课程(新课程(“IT4504”,3)); uG1.displayStudentInfo(); System.out.println(“”); 博士后pG1=新博士后(); pG1.设置名称(“Sam”); pG1.setMatric(“G015466”); pG1.setResearch(“经验软件工程”); pG1.setResearch(“数据挖掘”); System.out.println(“研究生信息”); pG1.displayStudentInfo(); } } 公共课{ 私有字符串courseName; 私人时间; 公共课程(字符串n,int c){ courseName=n; crhour=c; } 公共void setCourseName(字符串课程){ 课程名称=课程; } 公共字符串getCourseName(){ 返回courseName; } 公共无效setCreditH(内部c){ crhour=c; } } 公立班学生{ 私有字符串matric=“-matric required-”; 私有字符串name=“-name required-”; 公立学生(){ } 公共void集合名(字符串n){ 如果(n.matches(“[a-zA-Z]+”)==false) System.out.println(“无效名称”); 其他的 name=n; } 公共字符串getName(){ 返回名称;} 公共无效集合矩阵(字符串m){ 矩阵=m;} 公共字符串getMatric(){ 返回矩阵;} } 公立本科学生{ 私人课程讲师[]; 私有整数指数=0; 公共本科(){ 课程列表[]=新课程[7];} 公共课程(课程名称){ //课程列表[]=新课程[2]; } 公共课程[]getCourse(){ 返回课程列表;} public void displayStudentInfo(){ System.out.println(“Name:+getName()); System.out.println(“矩阵:+getMatric()); System.out.println(“课程列表:+getCourse()); }} 公立班研究生{ 私人字符串研究区[]; 私有整数指数=0; 公共研究生() { researchArea=新字符串[5]; } 公共研究(字符串研究){ 对于(指数=0;指数

Java 无法将主类中字符串的值设置为setter 公共课堂学生测试{ 公共静态void main(字符串参数[]){ 本科uG1=新本科(); uG1.设定名称(“约翰”); uG1.setMatric(“0192345”); System.out.println(“本科学生信息”); uG1.setCourse(新课程(“CS1103”,3)); uG1.设置课程(新课程(“IT4504”,3)); uG1.displayStudentInfo(); System.out.println(“”); 博士后pG1=新博士后(); pG1.设置名称(“Sam”); pG1.setMatric(“G015466”); pG1.setResearch(“经验软件工程”); pG1.setResearch(“数据挖掘”); System.out.println(“研究生信息”); pG1.displayStudentInfo(); } } 公共课{ 私有字符串courseName; 私人时间; 公共课程(字符串n,int c){ courseName=n; crhour=c; } 公共void setCourseName(字符串课程){ 课程名称=课程; } 公共字符串getCourseName(){ 返回courseName; } 公共无效setCreditH(内部c){ crhour=c; } } 公立班学生{ 私有字符串matric=“-matric required-”; 私有字符串name=“-name required-”; 公立学生(){ } 公共void集合名(字符串n){ 如果(n.matches(“[a-zA-Z]+”)==false) System.out.println(“无效名称”); 其他的 name=n; } 公共字符串getName(){ 返回名称;} 公共无效集合矩阵(字符串m){ 矩阵=m;} 公共字符串getMatric(){ 返回矩阵;} } 公立本科学生{ 私人课程讲师[]; 私有整数指数=0; 公共本科(){ 课程列表[]=新课程[7];} 公共课程(课程名称){ //课程列表[]=新课程[2]; } 公共课程[]getCourse(){ 返回课程列表;} public void displayStudentInfo(){ System.out.println(“Name:+getName()); System.out.println(“矩阵:+getMatric()); System.out.println(“课程列表:+getCourse()); }} 公立班研究生{ 私人字符串研究区[]; 私有整数指数=0; 公共研究生() { researchArea=新字符串[5]; } 公共研究(字符串研究){ 对于(指数=0;指数,java,arrays,Java,Arrays,此处: 您正在打印字符串数组返回的默认值toString()。请不要这样做。遍历数组并打印每个项目,或者使用java.util.array.toString(…) 你还需要给你的课程类一个有效的toString()方法,返回courseName和可能的学时数的方法。此外,我将课程字段更改为courses或courseList,以反映它不代表一门课程,而是一组课程。同样,getter方法应反映字段名称的更改。此处: public class StudentTest{ public stati

此处:

您正在打印字符串数组返回的默认值
toString()
。请不要这样做。遍历数组并打印每个项目,或者使用
java.util.array.toString(…)

你还需要给你的课程类一个有效的
toString()
方法,返回courseName和可能的学时数的方法。此外,我将课程字段更改为courses或courseList,以反映它不代表一门课程,而是一组课程。同样,getter方法应反映字段名称的更改。

此处:

public class StudentTest{

  public static void main(String args[]){

    UnderGrad uG1 = new UnderGrad();
    uG1.setName("John");
    uG1.setMatric("0192345");

    System.out.println("Undergarduate Student Info");
    uG1.setCourse(new Course("CS1103",3));
    uG1.setCourse(new Course("IT4504",3));
    uG1.displayStudentInfo();

    System.out.println(" ");

    PostGrad pG1 = new PostGrad();
    pG1.setName("Sam");
    pG1.setMatric("G015466");
    pG1.setResearch("Empirical Software Engineering");
    pG1.setResearch("Data Mining");
    System.out.println("Postgrad Student Info");
    pG1.displayStudentInfo();
  }
}

public class Course{
  private String courseName;
  private int crhour;

  public Course(String n, int c){
    courseName = n;
    crhour = c;
  }

  public void setCourseName(String course){
    courseName = course;
  }

  public String getCourseName(){
    return courseName;
  }

  public void setCreditH(int c){
    crhour = c;
  }
}

public class Student{

  private String matric ="-matric required-";
  private String name="-name required-";

  public Student(){
  }

    public void setName(String n){
      if (n.matches("[a-zA-Z]+") == false)
        System.out.println("Invalid Name");
      else
        name = n;
    }
    public String getName(){
    return name;}


  public void setMatric(String m){
    matric = m;}
  public String getMatric(){
    return matric;}
}

      public class UnderGrad extends Student{
    private Course courseList[];
    private int index = 0;

    public UnderGrad(){
      Course courseList[] =new Course[7];}

  public void setCourse(Course courseName){
    //Course courseList[]= new Course[2];
    }

  public Course[] getCourse(){
  return courseList;}

  public void displayStudentInfo(){

    System.out.println("Name: "+getName());
    System.out.println("Matric: "+getMatric());
    System.out.println("Course List: "+getCourse());
      }}

  public class PostGrad extends Student{
    private String researchArea[];
    private int index = 0;

    public PostGrad()
 {
 researchArea = new String[5];
 }

  public void setResearch(String research){
      for(index=0;index<2;index++){
        researchArea[index]=research;}
    }

  public String[] getResearch(){
  return researchArea;}

  public void displayStudentInfo(){

    System.out.println("Name: "+getName());
    System.out.println("Matric: "+getMatric());
    System.out.println("Research List: "+getResearch());
      }}
您正在打印字符串数组返回的默认值
toString()
。请不要这样做。遍历数组并打印每个项目,或者使用
java.util.array.toString(…)

你还需要给你的课程类一个有效的
toString()
方法,返回courseName和可能的学时数的方法。此外,我将课程字段更改为courses或courseList,以反映它不代表一门课程,而是一组课程。同样,getter方法也应反映字段名称的更改

System.out.println("Course List: "+getCourse());
System.out.println("Course List: "+ java.util.Arrays.toString(getCourse()));