当前位置:首页 » 编程语言 » java编写系统

java编写系统

发布时间: 2024-06-24 12:27:48

A. 使用java语言连接数据库编写一个简单的学生信息管理系统


public static void findInfo(String filePath) throws IOException {

//把之前存入到数据的文件,读取到集合中来。

ArrayList<Student> list = new ArrayList<Student>();

readData(list,filePath);

//遍历集合

for(int i=0;i<list.size();i++) {

Student stu = list.get(i);

System.out.println(stu.getId()+" "+stu.getName()+" "+stu.getAddress());

}

}

private static void readData(ArrayList<Student> list ,String filePath) throws NumberFormatException, IOException{

FileReader fr = new FileReader(filePath);

BufferedReader br = new BufferedReader(fr);

//读物文件里面的信息

String line = null;

while((line=br.readLine())!=null) {

String[] str = line.split(",");

//获取的数据封装成对象

//stu.getId()+","+stu.getName()+","+stu.getAge()

Student stu = new Student();

stu.setId(str[0]);

stu.setName(str[1]);

stu.setAge(Integer.valueOf(str[2]));

//将对象放到集合中区

list.add(stu);

}

}

//输入学生的信息

public static void addInfo(String filePath) throws IOException{

ArrayList<Student> list = new ArrayList<Student>();

Scanner sc = new Scanner(System.in);

//将输入的信息存放到集合里面去

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

System.out.println("请输入第"+i+"个学生的id");

String id = sc.next();

System.out.println("请输入第"+i+"个学生的name");

String name = sc.next();

System.out.println("请输入第"+i+"个学生的age");

int age = sc.nextInt();

Student stu = new Student();

stu.setId(id);

stu.setAge(age);

stu.setName(name);

list.add(stu);

}

//将集合里面的信息写到文件里面去

writeDate(list,filePath);

}

B. Java实现学生简易信息管理系统(java学生信息管理系统设计)

importjava.util.*;

importjava.io.*;

classStuMgr{

publicstaticclassStudent{

publicintid;

publicStringname;

publicintage;

publicStudent(intid,Stringname,intage){

this.id=id;

this.name=name;

this.age=age;

}

@Override

publicStringtoString(){

returnid","name","age;

}

}

publicListstuList=newLinkedList<>();

publicvoidadd(){

Scannersc=newScanner(System.in);

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

Stringid=sc.nextLine();

intintId=0;

try{

intId=Integer.parseInt(id);

}catch(ex){

System.out.println("学号输入有误,请输入数字!");

return;

}

if(find(intId)!=null){

System.out.println("该学号已经存在!");

return;

}

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

Stringname=sc.nextLine();

System.out.println("请输入学生年龄:");

Stringage=sc.nextLine();

intintAge=0;

try{

intAge=Integer.parseInt(age);

}catch(ex){

System.out.println("年龄输入有误,请输入绝胡激数字!");

return;

}

Studentstu=newStudent(intId,name,intAge);

stuList.add(stu);

store();

System.out.println("-----------------------");

System.out.println("学生信息已增加");

System.out.println(stu);

System.out.println("-----------------------");

}

publicvoiddel(){

Scannersc=newScanner(System.in);

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

Stringid=sc.nextLine();

intintId=0;

try{

intId=Integer.parseInt(id);

}catch(ex){

System.out.println("学号输入有误,请输入数字!");

return;

}

Studentstu=find(intId);

if(stu==null){

System.out.println("该学号不存在!");

return;

}

stuList.remove(stu);

store();

System.out.println("-----------------------");

System.out.println("学生信息已删除");

System.out.println(stu);

System.out.println("-----------------------");

}

publicvoidfind(){

Scannersc=newScanner(System.in);

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

Stringid=sc.nextLine();

intintId=0;

try{

intId=Integer.parseInt(id);

}catch(ex){

System.out.println("学号输入有误并袜,请输入数字!");

return;

}

Studentstu=find(intId);

if(stu==null){

System.out.println("该学号不存在!");

return;

}

System.out.println("-----------------------");

System.out.println("查找学生信息如下");

System.out.println(stu);

System.out.println("-----------------------");

}

publicStudentfind(intid){

for(Studentstu:stuList){

if(stu.id==id){

returnstu;

}

}

returnnull;

}

publicvoidmodify(){

store();

}

publicvoidforeach(){

System.out.println("-----------------------");

for(Studentstu:stuList){

System.out.println(stu);

}

System.out.println("-----------------------");

}

publicvoidstore(){

Iteratoriterator=stuList.iterator();

Filefile=newFile("stuList.txt");

FileWriterfw=null;

writer=null;

try{

fw=newFileWriter(file);

writer=new(fw);

while(iterator.hasNext()){

writer.write(iterator.next().toString());

writer.newLine();//换行

}

writer.flush();

}catch(e){

e.();

}catch(IOExceptione){

e.();

}finally{

try{

writer.close();

fw.close();

}catch(IOExceptione){

e.();

}

}

}

publicstaticvoidmain(String[]args){

StuMgrmgr=newStuMgr();

while(true){

System.out.println("请选择您要进行的操作:");

System.out.println("1:增加学生信息");

System.out.println("2:删除学生信息");

System.out.println("3:查找学生信息");

System.out.println("4:修改学生信息");

System.out.println("5:遍历学生信息");

System.out.println("6:退出");

System.out.println("-----------------------");

Scannersc=newScanner(System.in);

Stringop=sc.nextLine();

if("6".equals(op)){

return;

}

if("1".equals(op)){

mgr.add();

}

if("2".equals(op)){

mgr.del();

}

if("3".equals(op)){

mgr.find();

}

if("4".equals(op)){

mgr.modify();

}

if("5".equals(op)){

mgr.foreach();

}

}

}

}

时间仓促,还有一个modify方法没实现,留给你自己练手。

C. 用java基础编写一个简单的学生管理系统,有如下功能,添加学生,删除学生,查询学生。看好是用JAVA基础。

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;

class Student implements java.io.Serializable{
String number,name,specialty,grade,borth,sex;
public Student(){};
public void setNumber(String number){ this.number=number;}
public String getNumber(){ return number;}
public void setName(String name){ this.name=name;}
public String getName(){ return name;}
public void setSex(String sex){ this.sex=sex;}
public String getSex(){ return sex;}
public void setSpecialty(String specialty){ this.specialty=specialty;}
public String getSpecialty(){ return specialty;}
public void setGrade(String grade){ this.grade=grade;}
public String getGrade(){ return grade;}
public void setBorth(String borth){ this.borth=borth;}
public String getBorth(){ return borth;}
}
public class StudentManager extends JFrame{
JLabel lb=new JLabel("录入请先输入记录,查询、删除请先输入学号,修改是对查询" +
"内容改后的保存!");
JTextField 学号,姓名,专业,年级,出生;
JRadioButton 男,女;
ButtonGroup group=null;
JButton 录入,查询,删除,修改,显示;
JPanel p1,p2,p3,p4,p5,p6,pv,ph;
Student 学生=null;
Hashtable 学生散列表=null;
File file=null;
FileInputStream inOne=null;
ObjectInputStream inTwo=null;
FileOutputStream outOne=null;
ObjectOutputStream outTwo=null;
public StudentManager(){
super("学生基本信息管理系统");
学号=new JTextField(10);
姓名=new JTextField(10);
专业=new JTextField(10);
年级=new JTextField(10);
出生=new JTextField(10);
group=new ButtonGroup();
男=new JRadioButton("男",true);
女=new JRadioButton("女",false);
group.add(男);
group.add(女);
录入=new JButton("录入");
查询=new JButton("查询");
删除=new JButton("删除");
修改=new JButton("修改");
显示=new JButton("显示");
录入.addActionListener(new InputAct());
查询.addActionListener(new InquestAct());
修改.addActionListener(new ModifyAct());
删除.addActionListener(new DeleteAct());
显示.addActionListener(new ShowAct());
修改.setEnabled(false);
p1=new JPanel();
p1.add(new JLabel("学号:",JLabel.CENTER));
p1.add(学号);
p2=new JPanel();
p2.add(new JLabel("姓名:",JLabel.CENTER));
p2.add(姓名);
p3=new JPanel();
p3.add(new JLabel("性别:",JLabel.CENTER));
p3.add(男);
p3.add(女);
p4=new JPanel();
p4.add(new JLabel("专业:",JLabel.CENTER));
p4.add(专业);
p5=new JPanel();
p5.add(new JLabel("年级:",JLabel.CENTER));
p5.add(年级);
p6=new JPanel();
p6.add(new JLabel("出生:",JLabel.CENTER));
p6.add(出生);
pv=new JPanel();
pv.setLayout(new GridLayout(6,1));
pv.add(p1);
pv.add(p2);
pv.add(p3);
pv.add(p4);
pv.add(p5);
pv.add(p6);
ph=new JPanel();
ph.add(录入);
ph.add(查询);
ph.add(修改);
ph.add(删除);
ph.add(显示);
file=new File("学生信息.txt");
学生散列表=new Hashtable();
if(!file.exists()){
try{
FileOutputStream out=new FileOutputStream(file);
ObjectOutputStream objectOut=new ObjectOutputStream(out);
objectOut.writeObject(学生散列表);
objectOut.close();
out.close();
}
catch(IOException e){}
}
Container con=getContentPane();
con.setLayout(new BorderLayout());
con.add(lb, BorderLayout.NORTH);
con.add(pv, BorderLayout.CENTER);
con.add(ph, BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(100,100,600,300);
setVisible(true);

}
public static void main(String[] args) {new StudentManager();}
class InputAct implements ActionListener{
public void actionPerformed(ActionEvent e){
修改.setEnabled(false);
String number="";
number=学号.getText();
if(number.length()>0){
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
学生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee){System.out.println("创建散列表出现问题!");}
if(学生散列表.containsKey(number)){
String warning="该生信息已存在,请到修改页面修改!";
JOptionPane.showMessageDialog(null,warning,"警告",
JOptionPane.WARNING_MESSAGE);
}//end if1
else{
String m="该生信息将被录入!";
int ok=JOptionPane.showConfirmDialog(null,m,"确认",
JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
if(ok==JOptionPane.YES_OPTION){
String name=姓名.getText();
String specialty=专业.getText();
String grade=年级.getText();
String borth=出生.getText();
String sex=null;
if(男.isSelected()){sex=男.getText();}
else{sex=女.getText();}
学生=new Student();
学生.setNumber(number);
学生.setName(name);
学生.setSpecialty(specialty);
学生.setGrade(grade);
学生.setBorth(borth);
学生.setSex(sex);
try{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
学生散列表.put(number,学生);
outTwo.writeObject(学生散列表);
outTwo.close();
outOne.close();
}
catch(Exception ee){System.out.println("输出散列表出现问题!");}
学号.setText(null);
姓名.setText(null);
专业.setText(null);
年级.setText(null);
出生.setText(null);
}
}//end else1
}//end if0
else{
String warning="必须输入学号!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}//end else0
}//end actionPerformed
}//end class
class InquestAct implements ActionListener{
public void actionPerformed(ActionEvent e){
String number="";
number=学号.getText();
if(number.length()>0){
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
学生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee){System.out.println("散列表有问题!");}
if(学生散列表.containsKey(number)){
修改.setEnabled(true);
Student stu=(Student)学生散列表.get(number);
姓名.setText(stu.getName());
专业.setText(stu.getSpecialty());
年级.setText(stu.getGrade());
出生.setText(stu.getBorth());
if(stu.getSex().equals("男")){男.setSelected(true);}
else{女.setSelected(true);}
}
else{
修改.setEnabled(false);
String warning="该学号不存在!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
else{
修改.setEnabled(false);
String warning="必须输入学号!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
}
class ModifyAct implements ActionListener{
public void actionPerformed(ActionEvent e){
String number=学号.getText();
String name=姓名.getText();
String specialty=专业.getText();
String grade=年级.getText();
String borth=出生.getText();
String sex=null;
if(男.isSelected()){sex=男.getText();}
else{sex=女.getText();}
Student 学生=new Student();
学生.setNumber(number);
学生.setName(name);
学生.setSpecialty(specialty);
学生.setGrade(grade);
学生.setBorth(borth);
学生.setSex(sex);
try{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
学生散列表.put(number, 学生);
outTwo.writeObject(学生散列表);
outTwo.close();
outOne.close();
学号.setText(null);
姓名.setText(null);
专业.setText(null);
年级.setText(null);
出生.setText(null);
}
catch(Exception ee){
System.out.println("录入修改出现异常!");
修改.setEnabled(false);
}
}
}
class DeleteAct implements ActionListener{
public void actionPerformed(ActionEvent e){
修改.setEnabled(false);
String number=学号.getText();
if(number.length()>0){
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
学生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee){}
if(学生散列表.containsKey(number)){
Student stu=(Student)学生散列表.get(number);
姓名.setText(stu.getName());
专业.setText(stu.getSpecialty());
年级.setText(stu.getGrade());
出生.setText(stu.getBorth());
if(stu.getSex().equals("男")){男.setSelected(true);}
else{女.setSelected(true);}
}
String m="确定要删除该学生的记录吗?";
int ok=JOptionPane.showConfirmDialog(null,m,"确认",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(ok==JOptionPane.YES_OPTION){
学生散列表.remove(number);
try{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
outTwo.writeObject(学生散列表);
outTwo.close();
outOne.close();
学号.setText(null);
姓名.setText(null);
专业.setText(null);
年级.setText(null);
出生.setText(null);
}
catch(Exception ee){System.out.println(ee);}

}
else if(ok==JOptionPane.NO_OPTION){
学号.setText(null);
姓名.setText(null);
专业.setText(null);
年级.setText(null);
出生.setText(null);
}
else{
String warning="该学号不存在!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
else{
String warning="必须输入学号!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
}
class ShowAct implements ActionListener{
public void actionPerformed(ActionEvent e){
new StudentShow(file);
}
}
class StudentShow extends JDialog{
Hashtable 学生散列表= null;
JTextArea 显示=null;
FileInputStream inOne=null;
ObjectInputStream inTwo=null;
File file=null;
public StudentShow(File file){
super(new JFrame(),"显示对话框");
this.file=file;
显示=new JTextArea(16,30);
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
学生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee){}
if(学生散列表.isEmpty())显示.append("目前还没有学生的信息记录!\n");
else{
显示.setText("学号 姓名 性别 专业 年级 出生\n");
for(Enumeration enm=学生散列表.elements();enm.hasMoreElements();){
Student stu=(Student)enm.nextElement();
String sex="";
if(stu.getSex().equals("男"))sex="男";
else sex="女";
String str=stu.getNumber()+","+stu.getName()+","+sex+","
+stu.getSpecialty()+","+stu.getGrade()+","+stu.getBorth()+"\n";
显示.append(str);
}
}
JScrollPane scroll=new JScrollPane(显示);
Container con=getContentPane();
con.add("Center",scroll);
con.validate();
setVisible(true);
setBounds(200,200,400,300);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){setVisible(false);}
}
);
}
}
}

D. JAVA编写一个界面 用户登陆系统

import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class MainFrame extends JFrame {
JLabel lbl1 = new JLabel("用户名:");
JLabel lbl2 = new JLabel("密 码:");
JTextField txt = new JTextField("admin",20);
JPasswordField pwd = new JPasswordField(20);
JButton btn = new JButton("登录");
JPanel pnl = new JPanel();
private int error = 0;

public MainFrame(String title) throws HeadlessException {
super(title);
init();
}

private void init() {
this.setResizable(false);

pwd.setEchoChar('*');

pnl.add(lbl1);
pnl.add(txt);
pnl.add(lbl2);
pnl.add(pwd);
pnl.add(btn);
this.getContentPane().add(pnl);

btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ("admin".equals(new String(pwd.getPassword()))){
pnl.removeAll();
JLabel lbl3 = new JLabel();
ImageIcon icon = new ImageIcon(this.getClass().getResource("pic.jpg"));
lbl3.setIcon(icon);
pnl.add(lbl3);
}
else{
if(error < 3){
JOptionPane.showMessageDialog(null,"密码输入错误,请再试一次");
error++;
}
else{
JOptionPane.showMessageDialog(null,"对不起,您不是合法用户");
txt.setEnabled(false);
pwd.setEnabled(false);
btn.setEnabled(false);
}
}
}
});
}

public static void main(String[] args) {
MainFrame frm = new MainFrame("测试");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setBounds(100, 100, 300, 120);
frm.setVisible(true);
}
}

随手写的, 没调试图片, 太麻烦

E. 用java编写一个学生成绩管理系统. //1.学生类 学号 姓名 年龄 语数外三科成绩(三科成绩)

  1. 用数组可以,也可以用集合来存储各个同学的成绩。

  2. 添加删除等信息简单。

这里有个迷你图书管理系统,类似,我刚写的。你看看之后应该会有思路了。如果用集合utils做的话,也简单,知识用到了集合框架和泛型等机制。

package cn.kgc.sg.MiTuSys;


import java.util.Scanner;


public class MiNiBookSys {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

// 定义书的信息

String[] bookNames = new String[4];

int[] borrowDate = new int[5];

int[] borrowCount = new int[4];

int[] states = new int[4];

// 定义书单信息

String[] bookMeg = new String[5];

bookMeg[0] = "Java开发";

bookMeg[1] = "C#开发";

bookMeg[2] = "C语言开发";

states[2] = 0; // 0:可借阅 1:已借出


// 初始化两个图书借阅记录信息

bookNames[0] = "安徒生童话";

borrowDate[0] = 15;

borrowCount[0] = 4;

states[0] = 0; // 0:可借阅 1:已借出

bookNames[1] = "格林童话";

states[1] = 1; // 0:可借阅 1:已借出

borrowDate[1] = 26;

borrowCount[1] = 9;


// 搭建项目框架

int num = -1;// 定义用户初始输入的数字

do {

System.out.println("*********************欢迎使用图书管理系统**********************");

System.out.println(" 1.新增图书");

System.out.println(" 2.查看图书");

System.out.println(" 3.删除图书");

System.out.println(" 4.图书借阅");

System.out.println(" 5.归还图书");

System.out.println(" 6.退出系统");


System.out.print("请输入您的选择:");

int choose = sc.nextInt();

// 判断输入的选择是否正确

while (choose < 0 || choose > 6) {

System.out.print("输入有误,请重新输入:");

choose = sc.nextInt();

}

// 定义一个flag变量,来定义是否退出系统

boolean flag = true;// true:不退出系统 false:退出系统

String addName = null;

switch (choose) {

case 1:

System.out.println(" *********1.新增图书*********");

boolean isAdd = true;

System.out.println("序号 图书书名");

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

// 判断为空的不输出

if (bookMeg[i] != null) {

System.out.println((i + 1) + " " + bookMeg[i]);

}

}

System.out.print("请输入新增图书名称:");

addName = sc.next();

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

// 判断为空的不输出

if (bookMeg[i] == null) {

bookMeg[i] = addName;

break;

}

}

/*bookMeg[bookMeg.length-1] = addName; //添加图书信息

*/ System.out.println(" 序号 图书书名");

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

// 判断为空的不输出

if (bookMeg[i] != null) {

System.out.println((i + 1) + " " + bookMeg[i]);

}

}

if (!isAdd) {

System.out.println("对不起,图书已满,不能添加!!!");

}

break;


case 2:

System.out.println(" *********2.查看图书*********");

System.out.println("序号" + " 图书书名" + " 借阅次数 借阅状态 借阅日期 ");

// 遍历数组

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

// 判断信息为空的不输出

if (bookNames[i] != null) {

String borrowCounts = borrowCount[i] + "次";

String borrowDates = borrowDate[i] + "日";

String state = (states[i] == 0) ? "可借阅" : "已借出";

System.out.println((i + 1) + " " + bookNames[i] + " " + borrowCounts + " " + state

+ " " + borrowDates);

}

}

break;


case 3:

System.out.println(" *********3.删除图书*********");

System.out.println("序号 图书书名");

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

// 判断为空的不输出

if (bookMeg[i] != null) {

System.out.println((i + 1) + " " + bookMeg[i]);

}

}

System.out.print("请输入删除的图书序号:");

int delNo = sc.nextInt();

// 判断输入的序号是否有误

while (delNo < 1 || delNo > bookMeg.length) {

System.out.print("输入有误,重新输入:");

delNo = sc.nextInt();

}

// 删除图书

for (int i = 0; i <=bookMeg.length-1;i++) {

if (bookMeg[i] != null && i == delNo - 1) {

bookMeg[i] = bookMeg[i+1];

bookMeg[i+1] = null; //

// 最后置空

bookMeg[bookMeg.length - 1] = null;

}

}

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

// 判断为空的不输出

if (bookMeg[i] != null) {

System.out.println((i + 1) + " " + bookMeg[i]);

}

}

break;


case 4:

System.out.println(" *********4.图书借阅*********");

System.out.println(" 序号 图书书名 借阅状态 借阅次数 借阅日期");

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

// 判断为空的不输出

if (bookMeg[i] != null) {

String state = (states[i] == 0) ? "可借阅" : "已借出";

String borrowCi = borrowCount[i] + "次";

System.out.println((i + 1) + " " + bookMeg[i] + " " + state + " " + borrowCi + " "

+ borrowDate[i]);

}

}

System.out.print("请输入您要借阅的图书序号:");

int borrowNo = sc.nextInt();

boolean isFind = true;// false:找不到


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

// 查到了,但是状态是0可借阅,可以借阅

if (i == borrowNo - 1 && states[i] == 0) {

isFind = true;

// 改变状态为已借出

states[i] = 1;

// 借阅次数加一

borrowCount[i]++;

// 输入借阅日期

System.out.print("请输入借阅日期:");

int borrow = sc.nextInt();

// 对输入的日期判断

while (borrow < 1 || borrow > 31) {

System.out.print("您输入日期有误,请重新输入:");

borrow = sc.nextInt();

}

// 更新借阅日期

borrowDate[i] = borrow;

} else if (i == borrowNo - 1 && states[i] == 1) {

// 查到了,但是状态是1已借出,不可以借阅

isFind = true;

System.out.println("状态是已借出,不可以借阅!!!");

}

}

if (!isFind) {

System.out.println("找不到图书!");

break;

}

break;


case 5:

System.out.println(" *********5.归还图书*********");

System.out.println(" 序号 图书书名 借阅状态 借阅次数 借阅日期");

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

// 判断为空的不输出

if (bookMeg[i] != null) {

String state = (states[i] == 0) ? "可借阅" : "已借出";

String borrowCi = borrowCount[i] + "次";

System.out.println((i + 1) + " " + bookMeg[i] + " " + state + " " + borrowCi + " "

+ borrowDate[i]);

}

}

System.out.print("请输入您要归还的图书序号:");

int huanNo = sc.nextInt();

// 判断归还的序号是否合法

while (huanNo < 1 || huanNo > bookMeg.length - 1) {

System.out.print("输入的归还图书序号有误,请重新输入:");

huanNo = sc.nextInt();

}

boolean isHuan = true;// false:找不到

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

// 查到了,但是状态是1已借出,可以还

if (i == huanNo - 1 && states[i] == 1) {

isHuan = true;

// 改变状态为已借出

states[i] = 0;

// 输入归还日期

System.out.print("请输入归还日期:");

int huan = sc.nextInt();

// 对归还的日期判断,必须大于借阅日期

while (huan < 1 || huan > 31) {

System.out.print("您输入日期有误,请重新输入(1-31):");

huan = sc.nextInt();

}

while (huan < borrowDate[i]) {

System.out.print("归还日期必须大于借阅日期" + borrowDate[i] + "号,请重新输入:");

huan = sc.nextInt();

}

borrowCount[i]++;

System.out.println("归还图书成功!!!");


} else if (i == huanNo - 1 && states[i] == 0) {

// 查到了,但是状态是0可借阅,不能还

isFind = true;

System.out.println("状态是可借阅,不可以归还!!!");

}

}

if (!isHuan) {

System.out.println("抱歉,找不到图书,不能归还图书!");

break;

}

break;


case 6:

System.out.println(" *********6.退出系统*********");

flag = false;

break;

default:

flag = false;

break;

}

if (flag) {

System.out.print("输入0返回:");

num = sc.nextInt();

} else {

break;

}

} while (num == 0);

System.out.println("**********谢谢使用**********");

}

}

希望能帮到你!!!

热点内容
mxc安卓手机在哪里下载 发布:2024-06-28 18:28:52 浏览:136
抖推平台源码 发布:2024-06-28 18:26:37 浏览:130
python图片路径 发布:2024-06-28 18:14:54 浏览:930
长安univ什么配置 发布:2024-06-28 18:14:47 浏览:854
linuxpython教程 发布:2024-06-28 18:06:41 浏览:937
服务器搭建需要哪些技术 发布:2024-06-28 18:05:16 浏览:669
服务器管理中心是干什么的 发布:2024-06-28 17:39:31 浏览:943
黑色存储卡 发布:2024-06-28 17:22:43 浏览:450
php脚本运行时间 发布:2024-06-28 17:08:20 浏览:198
打开我的世界服务器连接不上 发布:2024-06-28 17:08:19 浏览:213