2022-7-16 第三小组 甘源册 学习笔记
目录
知识点掌握情况
今天的练习,以及昨天的作业(理解)
学习心情(心路历程)
昨天的作业十分复杂,不断的修修改改,艰难的完成了这项作业,在完成作业后发现今天所讲的,所做的这些练习十分容易理解,又是收获满满的一天 (≧∇≦)(≧∇≦)(≧∇≦)
1.员工管理系统
数组版
1.1需求

1.2代码
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int id = 1001;
int count = 1001;
int[] nots = new int[2];
String[] strings = new String[2];
c:
for (; ; ) {
System.out.println("欢迎使用员工管理系统");
System.out.println("请选择功能: 1.添加员工 2.查询员工 3.修改员工 4.删除员工 5.结束程序");
String next = scanner.next();
for (int i = 0; i < nots.length - 1; i++) {
for (int i1 = i + 1; i1 < nots.length; i1++) {
if (nots[i] < nots[i1]) {
int temp = 0;
temp = nots[i1];
nots[i1] = nots[i];
nots[i] = temp;
String s1 = null;
s1 = strings[i1];
strings[i1] = strings[i];
strings[i] = s1;
}
}
}
switch (next) {
case "1":
System.out.print("请输入员工姓名:");
String name = scanner.next();
while (nots[nots.length - 1] != 0) {
int[] newNots = new int[nots.length + 1];
String[] newString = new String[nots.length + 1];
for (int i = 0; i < nots.length; i++) {
newNots[i] = nots[i];
newString[i] = strings[i];
}
nots = newNots;
strings = newString;
break;
}
nots[id - count] = id;
strings[id - count] = name;
System.out.println("添加成功,员工的姓名为“ "+strings[id-count]+" ”员工的工号为:"+nots[id-count]);
id++;
continue c;
case "2":
a:
for (; ; ) {
System.out.println("请选择功能 1.根据姓名查询 2.根据工号查询 3.查询所有");
int cx = scanner.nextInt();
if (cx == 1) {
f:for (;;) {
System.out.print("请输入员工姓名");
String anInt = scanner.next();
int c = 0;
int i;
for (i = 0; i < nots.length; i++) {
if (anInt.equals(strings[i])) {
System.out.println("该员工的工号是:" + nots[i]);
c++;
continue;
}else if ( i==nots.length-1&&c>0){
continue c;
}
else if (!anInt.equals(strings[i])&&i == nots.length - 1) {
System.out.println("该员工姓名输入错误,");
continue f;
}
}
System.out.println("名字为:"+anInt+" 的员工有"+c+"人");
continue c;
}
}else if (cx == 2) {
e:
for (; ; ) {
System.out.print("请输入员工工号:");
int ids = scanner.nextInt();
for (int i = 0; i < nots.length; i++) {
if (ids == nots[i]) {
System.out.println("该员工的姓名是:" + strings[i]);
continue c;
}
}
System.out.println("员工工号不存在");
continue e;
}
}
else if (cx == 3) {
for (int i = 0; i < nots.length; i++) {
System.out.print("员工姓名:");
System.out.print(strings[i]);
System.out.print("\t\t");
System.out.print("员工工号:");
System.out.print(nots[i]);
System.out.println();
}
continue c;
}
}
case "3":
b:
for (; ; ) {
System.out.print("请输入员工工号:");
int anInt1 = scanner.nextInt();
for (int i = 0; i < nots.length; i++) {
if (anInt1 == nots[i]) {
System.out.println("该员工的姓名是:" + strings[anInt1 - nots[0]]);
System.out.print("请输入新的员工姓名:");
String newName = scanner.next();
strings[anInt1 - nots[0]] = newName;
continue c;
}
}
System.out.println("该员工工号不存在,输入有误");
continue b;
}
case "4":
d:
for (; ; ) {
System.out.print("请输入要删除的员工工号");
int id1 = scanner.nextInt();
for (int i = 0; i < nots.length; i++) {
if (id1 == nots[i]) {
strings[nots[0]-id1] = null;
int lab = nots[0]-id1;
nots[nots[0]-id1] = 0;
while (lab < (nots.length-1)) {
int la = 0;
la = nots[lab];
nots[lab] = nots[lab + 1];
nots[lab + 1] = la;
String str = null;
str = strings[lab];
strings[lab] = strings[lab + 1];
strings[lab + 1] = str;
lab++;
}
System.out.println("该员工的工号和姓名删除成功");
continue c;
}
}
System.out.println("该员工工号不存在,输入有误");
continue d;
}
case "5":
System.out.println("感谢您的使用,再见!");
break c;
default:
System.out.println("请输入1~5");
continue c;
}
}
}
2.练习
2.1 练习1
2.1.1需求
-
输入一个数作为下标
-
返回数组元素
2.1.2代码
public static void test1(int[] arr) {
a:
for (; ; ) {
System.out.println("请输入一个下标");
Scanner scanner = new Scanner(System.in);
int anInt;
try {
anInt = scanner.nextInt();
} catch (InputMismatchException e) {
System.out.println("请输入一个数字");
continue a;
}
if (anInt < 0) {
System.out.println("数组下标不能小于0");
continue a;
} else if (anInt >= arr.length) {
System.out.println("您输入的数组下标太长,请输入0~" + (arr.length - 1));
continue a;
}
System.out.println("本数组中下标为:" + anInt + "的元素是:" + arr[anInt]);
b:
for (; ; ) {
System.out.println("是否继续进行 1.进行 2.退出");
int next = scanner.nextInt();
if (next == 1) {
continue a;
} else if (next == 2) {
System.out.println("感谢使用!");
break a;
}
continue b;
}
}
}
2.2 练习2
2.2.1需求
-
输入一个数放到数组的最后
-
以此类推
2.2.2代码
private static void test2(int[] arr) {
Scanner scanner = new Scanner(System.in);
int count = arr.length - 1;
a:
for (; ; ) {
System.out.println("请添加数字:");
if (count < 0) {
int[] newArr = new int[arr.length + 1];
for (int i = 0; i < arr.length; i++) {
newArr[i] = arr[i];
}
arr = newArr;
}
int anInt = scanner.nextInt();
arr[count] = anInt;
System.out.println("添加成功!");
count--;
System.out.println("是否继续输入, 1 结束 2,继续");
int dic = scanner.nextInt();
b:
for (; ; ) {
switch (dic) {
case 1:
System.out.print("数组为:");
for (int i : arr) {
System.out.print(i + ",");
}
break a;
case 2:
continue a;
case 3:
continue;
}
}
}
}
2.3 练习3
2.3.1需求
- 输入下标,输入数据,把数据插入到指定下标处,下标后的数据以此后移
2.3.2代码
private static void test5(int[] arr) {
Scanner scanner = new Scanner(System.in);
a:for (;;) {
System.out.println("请输入要插入数据的下标:");
int anInt = scanner.nextInt();
System.out.println("请输入要插入数据的:");
int num = scanner.nextInt();
while (arr[arr.length-1]!=0) {
int[] newArr = new int[arr.length * 2];
for (int i1 = 0; i1 < arr.length; i1++) {
newArr[i1] = arr[i1];
}
arr = newArr;
}
arr[arr.length - 1] = num;
for (int i = arr.length - 1; i > anInt; i--) {
int temp = 0;
temp = arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = temp;
}
System.out.println(Arrays.toString(arr));
}
}
3.员工管理系统(思维导图)


浙公网安备 33010602011771号