JAVA 小白 把一个Student类封装起来,模拟一个转校生转入新学校后为其制作学生信息的过程

本文通过JAVA编程,介绍如何封装一个Student类,详细阐述在转校生转入新学校的情景下,如何使用该类来创建和管理学生信息,包括姓名、年级、科目成绩等关键数据。
public class Student
{
    Backstage information = new Backstage();//创建后台查找系统
    void Access (String mation)//查询信息
    {
        information.cooking(mation); //通知mation查询信息
    }
    void SaySorry()
    {
        System.out.println("查无此人");
    }
    public static void main(String[] args)
    {
        Student Reception = new Student();
        System.out.println("查找李敖信息如下");
        Reception.Access("\n");//查询信息如下
    }
    class Backstage //后台
    {
        String Studentnumber;//设置变量
        String name;
        String sex;
        String place;
        String phono;
        Backstage()//定义变量
        {
            this.Studentnumber = "学号";
            this.name = "姓名";
            this.sex = "性别";
            this.place = "籍贯";
            this.phono = "父母的联系方式";
        }
        void cooking(String mation)//信息
        {
            System.out.println(Studentnumber+"26"+mation);
            System.out.println(name+"李敖"+mation);
            System.out.println(sex+"男"+mation);
            System.out.println(place+"北京"+mation);
            System.out.println(phono+"父:130xxxx1100"+mation);
        }
    }
}
好的,下面是一个关于如何在Java中通过封装`Student`模拟转校生转入学校的简单示例: --- ### 封装 `Student` 首先我们可以创建一个名为 `Student` 的,并将学生的基本信息如姓名、年龄、原学校等作为私有属性进行封装。然后提供相应的构造函数以及 getter 和 setter 方法。 ```java public class Student { private String name; // 学生姓名 private int age; // 年龄 private String originalSchool; // 原学校名称 private String newSchool; // 转入学校名称 public Student(String name, int age, String originalSchool) { this.name = name; this.age = age; this.originalSchool = originalSchool; } // 设置学校名 public void setNewSchool(String newSchool) { this.newSchool = newSchool; } // 获取学生信息 public String getInformation() { return "学生姓名:" + this.name + "\n年龄:" + this.age + "\n原来就读于:" + this.originalSchool + "\n现在已转入:" + (this.newSchool == null ? "尚未分配" : this.newSchool); } } ``` #### 使用场景描述: 假设有一个从其他地方转学来的学生张三(14岁),他原来的学校叫“光明小学”,而现在需要将其注册到“希望中学”。 ```java public class Main { public static void main(String[] args) { // 创建学生对象 Student student = new Student("张三", 14, "光明小学"); System.out.println("--- 初始状态 ---"); System.out.println(student.getInformation()); // 模拟转入操作 student.setNewSchool("希望中学"); System.out.println("\n--- 完成转入之后的状态 ---"); System.out.println(student.getInformation()); } } ``` 运行结果将会显示学生的初始状况及转入后的变化情况。 --- 以上是对整个过程一个简明介绍和实现方式。你可以根据实际需求进一步扩充功能,例如添加更多的字段或其他业务逻辑处理。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值