实验报告求大家帮帮忙

img

只给你代码,实验结论你要自己写哈,另外记得采纳哈。

第一个学生的实验

import java.text.MessageFormat;

public class Student {
    private String sno;
    private String sname;
    private int age;
    private String address;
    private String tel;

    public Student(String sno, String sname, int age, String address, String tel) {
        this.sno = sno;
        this.sname = sname;
        this.age = age;
        this.address = address;
        this.tel = tel;
    }

    public void study() {
        System.out.println(MessageFormat.format("{0}学习ing...", this));
    }

    public void eat() {
        System.out.println(MessageFormat.format("{0}吃饭ing...", this));
    }

    public void sleep() {
        System.out.println(MessageFormat.format("{0}睡觉ing...", this));
    }

    public String getSno() {
        return sno;
    }

    public void setSno(String sno) {
        this.sno = sno;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public int getAge() {
        return age;
    }

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

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String toString() {
        return MessageFormat.format("学生(学号:{0}, 姓名:{1}, 年龄:{2}, 地址:{3}, 电话:{4})", sno, sname, age, address, tel);
    }

    public static void main(String[] args) {
        Student s1 = new Student("1", "张三", 20, "张三的地址", "张三的电话");
        Student s2 = new Student("2", "李四", 20, "李四的地址", "李四的电话");
        Student s3 = new Student("3", "王五", 20, "王五的地址", "王五的电话");

        s1.study();
        s1.eat();
        s1.sleep();

        s2.study();
        s2.eat();
        s2.sleep();

        s3.study();
        s3.eat();
        s3.sleep();
    }
}

img

第二个斐波那契数列

import java.text.MessageFormat;

public class Test {
    public static void main(String[] args) {
        int n = 15;
        System.out.println(MessageFormat.format("斐波那契数列第{0}个值为:{1}", n, getFibonacci(n)));
    }

    public static int getFibonacci(int n) {
        if (n <= 0) {
            throw new IllegalArgumentException();
        }
        switch (n) {
            case 1:
                return 0;
            case 2:
                return 1;
            default:
                return getFibonacci(n - 1) + getFibonacci(n - 2);
        }
    }
}

img

class Student{
private int sno;
private ......(如上照着打);

public Student(){
}
public Student(int sno,-------){
    this.sno = sno;
    -------(如上)
}

public void study(){
System.out.println("我是学习方法");

}
public static void main(String[] args) {
        Student stu = new Student(son,name,-----);
        stu.study();
        ------
    }
}