java初学者学了点学生信息管理系统
student的类
package box;publicclassstudent{
privatedouble grade;/* 成绩 */
private String gender;/* 性别 */
privateint number;/* 学号 */
private String name;/* 姓名 */
publicbooleansetname(String name)
{
this.name=name;
returntrue;
}
publicbooleansetgrade(double grade)
{
this.grade=grade;
returntrue;
}
publicbooleansetgender(String gender)
{
this.gender=gender;
returntrue;
}
publicbooleansetnumber(int number)
{
this.number=number;
returntrue;
}
publicdoubleoutgrade()
{
returnthis.grade;
}
public String outgender()
{
returnthis.gender;
}
publicintoutnumber()
{
returnthis.number;
}
public String outname()
{
returnthis.name;
}
publicintfindinnum()
{
return number;
}
public String all()
{
String alltext="";
alltext =alltext+"姓名:"+outname()+"学号:"+this.number+"性别:"+outgender()+"成绩"+this.grade;
return alltext;
}
}
teacher的类
public class teacher {
private String key="8888";
private String teachername;
public void setKey(String key) {
this.key = key;
}
public void setTeachername(String teachername) {
this.teachername = teachername;
}
public String outkey()
{
return key;
}
}
其实现方式
import java.sql.Date;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
import javax.swing.text.DateFormatter;
import javax.xml.crypto.Data;
import box.*;/* 导入box包内的类 */
publicclassApp{
publicstatic String compare(student s1[],int n)
{ student f[]=newstudent[1];
String r="";
for(int o=0;o<n;o++)
{for(int i=0;i<o;i++)
{
if(s1[i].outgrade()<s1[i+1].outgrade())
{f[0]=s1[i];
s1[i]=s1[i+1];
s1[i+1]=f[0];
}
}
}
for(int x=0;x<n;x++)
{
r=r+s1[x].outnumber()+' ';
}
return r;
}
publicstaticbooleanprovekey(teacher t,String keyword)
{if(t.outkey()==keyword)
returntrue;
else
returnfalse;
}
publicstaticintfind(int number,student stu[],int sum)//学号,stu集合,学生总数
{int n=0;
for(n=0;n<=sum;n++)
{
if(stu[n].outnumber()==number)
return n;
}
return-1;
}
publicstaticbooleandel(int no,student stu[],int sum)
{
int no1=find(no, stu, sum);
if(no1!=-1)
{
for(int j = no1; j<stu.length-1; j++)
{
stu[j]= stu[j+1];
}//后面元素补一下
stu[stu.length-1]=null;
returntrue;
}
else
returnfalse;
}
publicstaticvoidmain(String[] args)throws Exception
{
Scanner input=newScanner(System.in);
teacher t1=newteacher();//不完善只能一个老师
System.out.println("*********欢迎来到学生管理系统**********");
System.out.println("请输入密码(初始密码8888)");
while(true)
{
String keyword=input.next();
if(provekey(t1, keyword))
break;
else
{
System.out.println("输入有误重新输入");
continue;
}
}//验证系统
System.out.println("需要构建几个学生呢?");
int sum=input.nextInt();
student stu[]=newstudent[sum];/* 构造sum个同学的结构体 */
while(true)
{int num=0;//循环了第n名学生了
System.out.println("增加学生信息扣0");
System.out.println("改学生成绩扣1");
System.out.println("更改密码扣2");
System.out.println("查询学生信息扣3");
System.out.println("删除学生信息扣4");
System.out.println("查询当前时间扣5");
int op=input.nextInt();
switch(op)
{
case(0):
{int x=num+1;
System.out.println("请输入学生姓名");
stu[num].setname(input.next());
System.out.println("请输入学生学号");
stu[num].setnumber(input.nextInt());
System.out.println("请输入学生性别");
stu[num].setgender(input.next());
System.out.println("请输入学生成绩");
stu[num].setgrade(input.nextDouble());
System.out.println("第"+x+"位学生信息录入成功");
num++;
}
case(1):
{ System.out.println("请输入所需更改学生的学号");
int number=input.nextInt();
int o=find(number, stu, sum);//找到位置
if(o!=-1)
{ System.out.println("请输入所需更改的成绩是:");
int after=input.nextInt();
stu[o].setgrade(after);
}
}
break;
case(2):
{ System.out.println("请输入原密码");
String old=input.next();
while(true)
{if(provekey(t1, old))
{ System.out.println("请输入密码");
t1.setKey(input.next());
break;
}
else
{
System.out.println("原密码输入错误,请重新输入");
continue;
}
}
}
break;
case(3):
{
System.out.println("请输入所需更改学生的学号");
int number=input.nextInt();
int o=find(number, stu, sum);//找到位置
if(o!=-1)
{ System.out.println("所要查询的信息是");
System.out.println(stu[0].all());
}
}
break;
case(4):
{
System.out.println("请输入所删除学生学号");//用名字更好点
int x=input.nextInt();
if(del(x,stu,sum))
System.out.println("删除成功");
else
System.out.println("删除失败");
}
case(5):
{
LocalDateTime dateTime=LocalDateTime.now();/* 获取当前时间 */
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println(dateTime.format(formatter));
}
default:System.err.println("选项输入有误");
}
}
}
}
–请大家批评指正–2020.11.6
PE ASCII HTML Single backticks'Isn't this fun?'
‘Isn’t this fun?’Quotes"Isn't this fun?"
“Isn’t this fun?”Dashes-- is en-dash, --- is em-dash
– is en-dash, — is em-dash
以上是 java初学者学了点学生信息管理系统 的全部内容, 来源链接: utcz.com/z/515650.html