大神请帮帮我这菜鸟吧,写一个简单的程序

时间:2021-10-29 14:10:53
初学者,问题是:
写一个Student类,包含name,age,hobbies(爱好), director(主任),count几个属性,这几个属性都是私有的。
要求(1)写一个Driver 类,创建5个我们班的同学的信息作为对象;
(2)由于私有方法不能在类外面访问,所以自行设计其它的访问属性的set和get方法。
(3)由于所有同学的主任都是李惠老师,特别思考下这个属性应该怎么设计?而且设置成私有的以后如何访问它?
(4)count属性用于统计一共有多少个学生,思考应该如何设计,并要求输出一共有多少个学生。
(5)要求至少提供两种初始化对象的方法。
(6)其他内容自行设计。

9 个解决方案

#1


新建一个Student实体类,属性都添加好,在eclipse中右键source-->Generater Getter and Setter,创建所有属性的set、get方法,然后自己添加需要的构造,其他的都跟着做就是了

#2


怎么感觉像作业题啊

#3


最烦做作业神马的了

#4


好好学习,天天向上

#5


实在是不清楚你这个要求的具体意思 不好意思

package com.company;

/**
 * Created by Scott_Wang on 30/09/2014.
 */
class Student {
    private String name;
    private int age;
    private String hobbies;
    private final String director = "LI HUI";
    private int count;

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

    public void setAge(int age){
        this.age = age;
    }

    public void sethobbies(String hobbie){
        this.hobbies = hobbie;
    }

    public void setCount(int count){
        this.count = count;
    }

    public String getName(){
        return name;
    }

    public int getAge(){
        return age;
    }

    public String gethobbies(){
        return hobbies;
    }

    public String getDirector(){
        return director;
    }

    public int getCount(){
        return count;
    }
}

public class Driver{
    Student[] students;

    Driver(){
        students = new Student[5];
    }
    
    //
    //
    //
    public static void main(String[] args){
        
    }
}




#6


好好学习,天天向上。

#7


ggs,ddu!

#8


还是自己先想想,直接给你代码没什么意思~ 大神请帮帮我这菜鸟吧,写一个简单的程序

#9


大神请帮帮我这菜鸟吧,写一个简单的程序

#1


新建一个Student实体类,属性都添加好,在eclipse中右键source-->Generater Getter and Setter,创建所有属性的set、get方法,然后自己添加需要的构造,其他的都跟着做就是了

#2


怎么感觉像作业题啊

#3


最烦做作业神马的了

#4


好好学习,天天向上

#5


实在是不清楚你这个要求的具体意思 不好意思

package com.company;

/**
 * Created by Scott_Wang on 30/09/2014.
 */
class Student {
    private String name;
    private int age;
    private String hobbies;
    private final String director = "LI HUI";
    private int count;

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

    public void setAge(int age){
        this.age = age;
    }

    public void sethobbies(String hobbie){
        this.hobbies = hobbie;
    }

    public void setCount(int count){
        this.count = count;
    }

    public String getName(){
        return name;
    }

    public int getAge(){
        return age;
    }

    public String gethobbies(){
        return hobbies;
    }

    public String getDirector(){
        return director;
    }

    public int getCount(){
        return count;
    }
}

public class Driver{
    Student[] students;

    Driver(){
        students = new Student[5];
    }
    
    //
    //
    //
    public static void main(String[] args){
        
    }
}




#6


好好学习,天天向上。

#7


ggs,ddu!

#8


还是自己先想想,直接给你代码没什么意思~ 大神请帮帮我这菜鸟吧,写一个简单的程序

#9


大神请帮帮我这菜鸟吧,写一个简单的程序