diff --git "a/\347\254\224\350\256\260&\344\275\234\344\270\232/12.23.md" "b/\347\254\224\350\256\260&\344\275\234\344\270\232/12.23.md" new file mode 100644 index 0000000000000000000000000000000000000000..370a3daa66561bff4539777b25bb229288097482 --- /dev/null +++ "b/\347\254\224\350\256\260&\344\275\234\344\270\232/12.23.md" @@ -0,0 +1,160 @@ +# 学生管理系统 + +```java +import java.util.Scanner; + +public class H18 { +// // 把扫描器放在最外层,让所有方法都可以用 + static Scanner sc = new Scanner(System.in); + static String[] stu = new String[10]; + public static void main(String[] args) { + + + stu[0] = "苏清华"; + stu[1] = "林佳泽"; + + + aa: while (true){ + Welcome(); + int a = choice(sc.nextInt()); + if (a==1){ + break ; + } + } + + } + public static void Welcome() { + System.out.println( + "\n-----------------------" + + "\n- 欢迎使用三班学生管理系统 --" + + "\n- 1.浏览所有学生信息 -" + + "\n- 2.添加学生信息 -" + + "\n- 3.修改学生信息 -" + + "\n- 4.删除学生信息 -" + + "\n- 5.查询学生信息 -" + + "\n- 6.退出管理系统 -" + + "\n ----------------------" + + "\n请输入对应的数字选择你需要的功能:"); + } + public static int choice(int num){ + int a =0; + switch (num) { + case 1: + + Allstudent(); + break; + case 2: + + addstudent(); + break; + case 3: + + editStudent(); + break; + case 4: + + deleteStudent(); + break; + case 5: + + searchStudent(); + break; + case 6: + + System.out.println("你选择了退出系统"); + + default: + System.out.println("你输入的选项错误"); + a=1; + } + return a; + } + //删除学生信息 + private static void deleteStudent() { + System.out.println("请问你要删除哪个学生"); + String name= sc.next(); + int index =search(name); + if (index==-1){ + System.out.println("对不起,没有该学生,无法删除"); + }else { + stu[index]=null; + System.out.println("删除成功"); + } + } + //查找学生 + public static void searchStudent(){ + System.out.println("请输入要查找的学生姓名"); + String name =sc.next(); + int index =search(name); + if (index==-1){ + System.out.println("对不起,没有该学生"); + }else { + System.out.println("恭喜,找到了,Ta在第"+(index+1)+"个"); + } + } + private static void editStudent(){ + System.out.println("输入你要修改的学生"); + String name =sc.next(); + int index =search(name); + if (index==-1){ + System.out.println("对不起,没有该学生,无法修改"); + }else { + System.out.println("请问你要把【"+name+"】修改为谁:"); + String newNmae = sc.next(); + stu[index]= newNmae; + System.out.println("修改成功"); + } + } + public static void Allstudent() { + System.out.println("三现有班学生如下:"); + int count =0; + for (String name : stu) { + if (name==null){ + count++; + continue; + } + System.out.print(name + "\t"); + } + if (count== stu.length){ + System.out.println("目前还没有学生信息"); + } + } + public static void addstudent() { + System.out.println("请输入你要添加的学生"); + String name = sc.next(); + int index = search( name); + if (index != -1) { + System.out.println("该学生已经在数据库了,请不要重复添加!"); + } else { + int nullIndex = search(null); + stu[nullIndex] = name; + System.out.println("添加成功"); + Allstudent(); + + } + } + + public static int search( String str) { + int index = -1; + if (str == null) { + for (int i = 0; i < stu.length; i++) { + if (stu[i]==null){ + index = i; + break; + } + } + }else { + for (int i = 0; i < stu.length; i++) { + if (str.equals(stu[i])) { + index=i; + return index; + } + } + } + return index; + } +} +``` + + + diff --git "a/\347\254\224\350\256\260&\344\275\234\344\270\232/12.27.md" "b/\347\254\224\350\256\260&\344\275\234\344\270\232/12.27.md" new file mode 100644 index 0000000000000000000000000000000000000000..89fdfa8fbfab753e14063177cc529caf1a3e012e --- /dev/null +++ "b/\347\254\224\350\256\260&\344\275\234\344\270\232/12.27.md" @@ -0,0 +1,133 @@ +# 面向对象(集思广益) + +并不是一个技术,而是一种编程思想 + +以什么形式组织代码;以什么思想解决问题 + +#### 什么是类 + +类是对一类具有共同属性和行为的抽象 + +#### 什么是对象 + +能看得到摸的着的实体 + +**成员变量和局部变量的区别** +**成员变量:定义在类中,有初始值** +**局部变量:定义在方法中,无初始值** +**3.方法的重载** +两同三不同 +1,在同一个类中,同一个方法名 +2,参数列表不同(个数不同,顺序不同,类型不同) +方法的重载跟返回值无关 +**4.静态变量(类变量)相当于全局变量** +用static修饰的变量叫静态变量也叫类变量 +用static修饰的方法叫静态方法也叫类方法 +修饰代码块叫静态块(先于main之前调用,先块后main) +可以直接通过类名直接调用 也可以 用对象调用,但是推荐类名调用 +静态方法中只能调用静态变量 +非静态方法中不能定义静态变量 + +### 2.类与对象 + +- 什么是类:类是对现实生活中一类具有共同属性和行为的事物的抽象 +- 什么是对象:对象是能够看得见摸得着的真实存在的实体 +- 类是对象的抽象,对象是类的实体 + +### 3.对象的属性和行为 + +- 属性:对象具有的各种特征,每个对象的每个属性都拥有特定的值 +- 行为:对象能够执行的操作 + +### 4.类的属性和行为 + +- 属性:在类中通过成员变量来体现(类中方法外的变量) +- 行为:在类中通过成员方法来体现(和前面的方法相比去掉**static**关键字即可) + +### 5.对象的使用 + +- 创建对象 + 1. 格式:类名 对象名 = new 类名(); + 2. 示例:Phone p = new Phone(); +- 使用对象 + 1. 使用成员变量 + - 格式:对象名.变量名 + - 示例:p.brand + 2. 使用成员方法 + - 格式:对象名.方法名(参数); + - 示例:p.call(); + +类和对象 + +### 1.1 类和对象的理解 + +客观存在的事物皆为对象 ,所以我们也常常说万物皆对象。 + +- 类 + - 类的理解 + - 类是对现实生活中一类具有共同属性和行为的事物的抽象 + - 类是对象的数据类型,类是具有相同属性和行为的一组对象的集合 + - 简单理解:类就是对现实事物的一种描述 + - 类的组成 + - 属性:指事物的特征,例如:手机事物(品牌,价格,尺寸) + - 行为:指事物能执行的操作,例如:手机事物(打电话,发短信) +- 类和对象的关系 + - 类:类是对现实生活中一类具有共同属性和行为的事物的抽象 + - 对象:是能够看得到摸的着的真实存在的实体 + - 简单理解:**类是对事物的一种描述,对象则为具体存在的事物** + +### 1.2 类的定义 + +类的组成是由属性和行为两部分组成 + +- 属性:在类中通过成员变量来体现(类中方法外的变量) +- 行为:在类中通过成员方法来体现(和前面的方法相比去掉static关键字即可) + +类的定义步骤: + +①定义类 + +②编写类的成员变量 + +③编写类的成员方法 + +```Java +public class H1 { + String eat; + double lhq; + String clear; + String study; + + + public void english(){ + System.out.println( study+"学习英语"); + } + public void chinese(){ + System.out.println(study+"学习语文"); + } +} + + + + +public class H2 { + public static void main(String[] args) { + H1 xiaoming =new H1(); + xiaoming.eat="干饭"; + xiaoming.clear="打扫卫生"; + xiaoming.study="好好学习"; + System.out.println("小明正在"+xiaoming.eat); + System.out.println("小明正在"+xiaoming.clear); + System.out.println("小明正在"+xiaoming.study); + xiaoming.english(); + xiaoming.chinese(); + + H1 xiaoqiang =new H1(); + xiaoqiang.eat="鸭屎了你"; + System.out.println("小强正在吃饭看见了灭霸突然说:"+xiaoqiang.eat); + xiaoqiang.study="小强"; + xiaoqiang.english(); + } +} +``` + diff --git "a/\347\254\224\350\256\260&\344\275\234\344\270\232/img/2022-12-13_114811.png" "b/\347\254\224\350\256\260&\344\275\234\344\270\232/img/2022-12-13_114811.png" deleted file mode 100644 index bd7cb8ef74da486ae11f4fac165aa4834970c5d3..0000000000000000000000000000000000000000 Binary files "a/\347\254\224\350\256\260&\344\275\234\344\270\232/img/2022-12-13_114811.png" and /dev/null differ