java无数据库.docx
- 文档编号:6198442
- 上传时间:2023-01-04
- 格式:DOCX
- 页数:14
- 大小:74.56KB
java无数据库.docx
《java无数据库.docx》由会员分享,可在线阅读,更多相关《java无数据库.docx(14页珍藏版)》请在冰豆网上搜索。
java无数据库
packagestudentManager;
publicclassCourse{
privateStringid;
privateStringname;
publicCourse(Stringid,Stringname){
this.id=id;
this.name=name;
}
publicCourse(){
}
publicStringgetId(){
returnid;
}
publicvoidsetId(Stringid){
this.id=id;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicstaticvoidmain(String[]args){
}
}
packagestudentManager;
publicclassCoursecourse{
privateCoursecourse;
publicCourseScore(){
}
publicCourseScore(Coursecourse,floatscore){
this.course=course;
this.score=score;
}
privatefloatscore;
publicCoursegetCourse(){
returncourse;
}
publicvoidsetCourse(Coursecourse){
this.course=course;
}
publicfloatgetScore(){
returnscore;
}
publicvoidsetScore(floatscore){
this.score=score;
}
}
packagestudentManager;
importjava.util.List;
publicclassStudent{
privateStringid;
privateStringname;
privateintage;
privateList
publicStudent(){
}
publicStudent(Stringid,Stringname,intage,List
super();
this.id=id;
this.name=name;
this.age=age;
this.courseScore=courseScore;
}
publicStringgetId(){
returnid;
}
publicvoidsetId(Stringid){
this.id=id;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetAge(){
returnage;
}
publicvoidsetAge(intage){
this.age=age;
}
publicList
returncourseScore;
}
publicvoidsetCourseScore(List
this.courseScore=courseScore;
}
publicStringtoString(List
StringBufferstudent=newStringBuffer("学号:
"+this.id+"姓名:
"+this.name+"年龄:
"+this.age);
for(CourseScorec:
list){
Stringcourse="课程号:
"+c.getCourse().getId()+"课程名:
"+c.getCourse().getName()+"课程成绩:
"+c.getScore();
student.append(course);
}
returnstudent.toString();
}
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
}
}
packagestudentManager;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Scanner;
publicclassStudentManager{
List
privateScannerscanner=newScanner(System.in);
publicbooleanadd(Studentstu)throwsStuIdHasExistedException{
booleansuccess=false;
if(stuList.isEmpty()){
stuList.add(stu);
System.out.println("添加成功");
System.out.println(stu.toString(stu.getCourseScore()));
success=true;
display();
returnsuccess;
}else{
for(Students:
stuList){
if(s.getId().equals(stu.getId())){
System.out.println("该学生已存在,添加失败");
display();
returnsuccess;
}else{
stuList.add(stu);
System.out.println("添加成功");
System.out.println(stu.toString(stu.getCourseScore()));
success=true;
display();
returnsuccess;
}
}
}
System.out.println(stuList.size());
returnsuccess;
}
publicbooleandelete(StringstuId){
booleansuccess=false;
if(stuList.isEmpty()){
System.out.println("学生信息表为空,删除失败!
");
display();
returnsuccess;
}else{
for(inti=0;i if(stuList.get(i).getId().equals(stuId)){ System.out.println(stuList.get(i).getId()); stuList.remove(i); System.out.println("删除成功"); display(); success=true; returnsuccess; }else{ System.out.println("不存在此学生,删除失败"); display(); } } } returnsuccess; } publicbooleanupdate(Stringstuid){ booleansuccess=false; if(stuList.isEmpty()){ System.out.println("学生信息表为空,无法修改"); display(); returnsuccess; }else{ for(inti=0;i if(stuList.get(i).getId().equals(stuid)){ System.out.println("姓名: "); Stringname=scanner.next(); System.out.println("年龄: "); intage=scanner.nextInt(); List for(CourseScorec: list){ System.out.println(c.getCourse().getName()+"成绩"); floatscore=scanner.nextFloat(); c.setScore(score); } stuList.get(i).setName(name); stuList.get(i).setAge(age); stuList.get(i).setCourseScore(list); System.out.println("修改成功"); System.out.println(stuList.get(i).toString(stuList.get(i).getCourseScore())); display(); }else{ System.out.println("此学生不存在,修改失败"); display(); } } } returnsuccess; } publicStudentqueryById(StringstuId){ if(stuList.isEmpty()){ System.out.println("学生信息表为空,查询失败"); display(); }else{ System.out.println(stuList.size()); for(inti=0;i if(stuList.get(i).getId().equals(stuId)){ System.out.println(stuList.get(i).toString(stuList.get(i).getCourseScore())); display(); }else{ System.out.println("学生信息表中没有这个学生,查询失败"); display(); } } } returnnull; } publicList List for(inti=0;i if(((Student)(list.get(i))).getName().indexOf(stuName)<=-1){ list.remove(i); } } returnlist; } privatebooleanstuIdExisted(Stringid){ booleanexisted=false; for(inti=0;i Students=stuList.get(i); StringstuId=s.getId(); if(stuId.equals(id)){ System.out.println("此学生存在"); existed=true; display(); returnexisted; }else{ System.out.println("此学生不存在"); display(); } } returnexisted; } publicvoidprint(){ if(stuList.isEmpty()){ System.out.println("学生信息表为空"); display(); }else{ for(Students: stuList){ System.out.println(s.toString(s.getCourseScore())); } System.out.println("以上为所有学生信息"); display(); } } publicvoiddisplay(){ System.out.println("********************************************"); System.out.println("******"); System.out.println("***学生成绩信息管理系统***"); System.out.println("*1.增加***"); System.out.println("*2.删除***"); System.out.println("*3.查找***"); System.out.println("*4.修改***"); System.out.println("****"); System.out.println("********************************************"); System.out.print("请选择: "); Stringnum=scanner.next(); if("1".equals(num)){ System.out.println("请输入需要添加的学生详细信息: "); System.out.println("请输入学号"); Stringid=scanner.next(); System.out.println("请输入姓名"); Stringname=scanner.next(); System.out.println("请输入年龄"); intage=scanner.nextInt(); System.out.println("请输入本学期的课程数量"); intn=scanner.nextInt(); List for(inti=0;i System.out.println("请输入课程号"); Stringcid=scanner.next(); System.out.println("请输入课程名"); Stringcname=scanner.next(); System.out.println("请输入课程对应的成绩"); floatscore=scanner.nextFloat(); Coursecourse=newCourse(cid,cname); CourseScorecourseScore=newCourseScore(course,score); courseScore1.add(courseScore); } Students=newStudent(id,name,age,courseScore1); try{ add(s); }catch(StuIdHasExistedExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } }elseif("2".equals(num)){ System.out.println("请输入要删除的学号: "); Stringid=scanner.next(); delete(id); }elseif("3".equals(num)){ System.out.print("请输入需要查找的学号: "); Stringid=scanner.next(); queryById(id); }elseif("4".equals(num)){ System.out.print("请输入要修改的学号: "); Stringid=scanner.next(); update(id); } } publicstaticvoidmain(String[]args){ StudentManagersn=newStudentManager(); sn.display(); } } classStuIdHasExistedExceptionextendsException{ privatestaticfinallongserialVersionUID=109796981710404453L; StuIdHasExistedException(Stringmsg){ super(msg); } } 开始运行并输入学生信息 查找学生信息 修改学生信息 删除学生信息
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 数据库
![提示](https://static.bdocx.com/images/bang_tan.gif)