Java作业,跪求大神帮帮忙,非常感谢,拜托了!!!

2025-05-09 23:14:53
推荐回答(2个)
回答1:

import org.apache.commons.lang.StringUtils;

import java.util.Scanner;

public class Student{

String sNO ;//学号

String sName;//姓名

String sSex;//性别

String sClass;//班级

public Student(String sNO, String sName, String sSex, String sClass) {

this.sNO = sNO;

this.sName = sName;

this.sSex = sSex;

this.sClass = sClass;

}

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 String getsSex() {

return sSex;

}

public void setsSex(String sSex) {

this.sSex = sSex;

}

public String getsClass() {

return sClass;

}

public void setsClass(String sClass) {

this.sClass = sClass;

}

@Override

public String toString() {

return "学生信息: [" + (sNO != null ? "学号=" + sNO + ", " : "") + "姓名=" + (sName != null ? sName : "") + "性别=" + (sSex != null ? sSex : "") + "班级=" + (sClass != null ? sClass : "") +"]";

}

public static void main(String[] args) {

System.out.println("开始录入学生信息");

Student[] s = new Student[10];

for (int i = 1; i <= 10; i++) {

System.out.println("请录入第"+i+"位学生信息:");

Scanner sc = new Scanner(System.in);

System.out.println("请输入学号:");

String sno = sc.nextLine();

System.out.println("请输入姓名:");

String sname = sc.nextLine();

System.out.println("请输入性别:");

String ssex = sc.nextLine();

System.out.println("请输入班级:");

String sclass = sc.nextLine();

Student stu = new Student(sno, sname, ssex, sclass);

s[i-1] = stu;

System.out.println("录入第"+i+"位学生信息成功!");

System.out.println(stu.toString());

}

System.out.println("录入学生信息结束!");

while (true){

System.out.println("请输入要查询的学号(输入end可结束查询):");

Scanner sc = new Scanner(System.in);

String sno= sc.nextLine();

if (StringUtils.equals("end", sno)){

break;

}

for (int i = 0; i < s.length; i++) {

Student student = s[i];

if (student.getsNO().equals(sno)){

System.out.println("查询结果为:");

System.out.println(student.toString());

}

}

}

System.out.println("程序结束!");

}

}

程序运行结果

上边是整个的代码,如果符合要求的话就采纳一下,不符合的话随时联系我。

回答2:

你想问就问
只要我会我可以给你答案