7-25 程序填空题1 (5 分)

以下程序不完整,请你补全代码,已经给定的代码无误,不允许修改。

 

import java.util.ArrayList;

 

public class Main{ private ArrayList slist = new ArrayList(); public void addStudent(Student s){ this.slist.add(s); } public void showStudent(){ for(Student s:slist){ System.out.println(s); } } public static void main(String[] args) { Main t = new Main(); t.addStudent(new Student("2016001","rose",18)); t.addStudent(new Student("2016002","hunifu",19)); t.addStudent(new Student("2016003","britsh",20)); t.addStudent(new Student("2016004","sunni",17)); t.showStudent(); } }

class Student { //补全代码处 }

 

输入格式:

输出格式:

输入样例:


输出样例:

2016001 rose 18
2016002 hunifu 19
2016003 britsh 20
2016004 sunni 17
import java.util.ArrayList;

public class Main{
    private ArrayList slist = new ArrayList();

    public void addStudent(Student s){
        this.slist.add(s);
    }

    public void showStudent(){
        for(Student s:slist){
            System.out.println(s);
        }
    }

    public static void main(String[] args) {
        Main t = new Main();
        t.addStudent(new Student("2016001","rose",18));
        t.addStudent(new Student("2016002","hunifu",19));
        t.addStudent(new Student("2016003","britsh",20));
        t.addStudent(new Student("2016004","sunni",17));
        t.showStudent();
    }
}


class Student {
    //补全代码处
    String date;
    String name;
    int age;

    @Override
    public String toString() {
        return   date+" " + name+" "+  age ;
    }

    public Student(String date, String name, int age) {
        this.date = date;
        this.name = name;
        this.age = age;
    }
}

你可能感兴趣的:(pta)