java成績管理系統
public class Test04
{
public static List<Students> list = new ArrayList<Students>();
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int t;
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("7.退出");
System.out.println("請輸入你的操作(1-7):");
String s = scan.nextLine();
if (null==s||"".equals(s))
{
continue;
}else {
t = Integer.parseInt(s);
}
if (0==t)
{
break;
}
}
}
}
class Students{
int id;
String name;
}
後面可以自己做判斷,寫方法實現
❷ java編寫學生成績管理系統
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Admin {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Scanner in = new Scanner(System.in);
int studentNum = 5;
List<Student> result = new ArrayList<Student>();
for (int i = 0; i < studentNum; i++) {
Student bean = new Student();
System.out.print("輸入第" + (i + 1) + "個學生學號:");
bean.setNo(in.next());
System.out.print("輸入第" + (i + 1) + "個學生姓名:");
bean.setName(in.next());
System.out.print("輸入第" + (i + 1) + "個學生數學成績:");
bean.setShuxue(in.nextDouble());
System.out.print("輸入第" + (i + 1) + "個學生語文成績:");
bean.setYuwen(in.nextDouble());
result.add(bean);
}
while (true) {
System.out.println("1.保存到文件;2.總成績;3.平均成績;4.不及格比例;5.及格比例;6,優良比例;0.退出.");
int i = in.nextInt();
if (i == 0) {
System.exit(0);
}
if (i == 1) {
save(result);
}
if (i == 2) {
for (int j = 0; j < result.size(); j++) {
Student s = result.get(j);
System.out.println("學生" + s.getName() + "的總成績是:" + s.all());
}
}
if (i == 3) {
int jigeSum = 0;
for (int j = 0; j < result.size(); j++) {
Student s = result.get(j);
if (!s.isJige()) {
jigeSum++;
}
}
System.out.println("不及格比例:" + jigeSum + "/" + result.size());
}
if (i == 4) {
// 篇幅受限,自行開發
}
if (i == 5) {
// 篇幅受限,自行開發
}
}
}
private static void save(List result) throws IOException {
FileOutputStream fs = new FileOutputStream("d:/a.txt");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(result);
os.flush();
os.close();
fs.close();
}
}
class Student implements Serializable {
private String no;
private String name;
private double shuxue;
private double yuwen;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public double getShuxue() {
return shuxue;
}
public void setShuxue(double shuxue) {
this.shuxue = shuxue;
}
public double getYuwen() {
return yuwen;
}
public void setYuwen(double yuwen) {
this.yuwen = yuwen;
}
public double all() {
return shuxue + yuwen;
}
public double avg() {
return all() / 2;
}
public boolean isJige() {
return avg() > 60;
}
}
❸ java設計一個學生成績管理系統
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
String exit="";
Map<String, List<Float>> map1=new HashMap();
while(!exit.equals("exit")) {
System.out.println("請出入學生姓名");
List<Float> list = new ArrayList<Float>();
map1.put(sc.next(), list);
for(int i=0;i<3;i++) {
System.out.println("請出入學生成績");
list.add(sc.nextFloat());
}
System.out.println("輸入 exit 退出成績錄入,其他則繼續錄入");
exit=sc.next();
}
for(String key :map1.keySet()) {
List<Float> list =map1.get(key);
float avage =0l;
for(Float box :list) {
avage += box;
}
System.out.println(key+"的平均成績:"+ avage/list.size());
}
}
//只做了第一題,追加分數,可得第二題答案
❹ JAVA程序設計 學生成績管理系統(資料庫版)
那個不好意思,我來當壞人吧,沒人會鳥你的,這世界好人沒人想的那麼多,最簡單的自己在網路搜一個,但是一般資料庫或者jdk版本會不兼容,還有你的懸賞太少了,根本沒有人會來回答的,我建議你還自己堆起來吧,這個不難,只是堆代碼而已,現在eclipse都可以拖放swing部件了
❺ 用java做一個學生成績管理系統需要哪些技術
用java做一個學生成績管理系統,可以用到如下技術:
後台:SSH框架,不用框架的話,單純地用JSP + Servlet也可以。
前台:html + css + js + jquery
資料庫:掌握sql語言的編寫,資料庫的連接。復雜的項目還需要用到存儲過程。
❻ 求用Java編寫的學生成績管理系統的完整代碼
packagejdbcproj;
importjava.sql.*;
importjava.awt.BorderLayout;
importjava.awt.EventQueue;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
importjavax.swing.border.EmptyBorder;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JTextField;
importjavax.swing.JButton;
importjava.awt.event.ActionListener;
importjava.sql.Connection;
importjava.sql.PreparedStatement;
importjava.sql.SQLException;
importjava.awt.event.ActionEvent;
{
privateJPanelcontentPane;
privateJTextFieldtxtname;
privateJTextFieldtxtpassword;
/**
*Launchtheapplication.
*/
publicstaticvoidmain(String[]args){
EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
try{
MainFrameframe=newMainFrame();
frame.setVisible(true);
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
/**
*Createtheframe.
*/
publicMainFrame(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,661,399);
contentPane=newJPanel();
contentPane.setBorder(newEmptyBorder(5,5,5,5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabellblNewLabel=newJLabel("u7528u6237u540D");
lblNewLabel.setBounds(114,51,72,18);
contentPane.add(lblNewLabel);
JLabellblNewLabel_1=newJLabel("u5BC6u7801");
lblNewLabel_1.setBounds(114,106,72,18);
contentPane.add(lblNewLabel_1);
txtname=newJTextField();
txtname.setBounds(261,48,86,24);
contentPane.add(txtname);
txtname.setColumns(10);
txtpassword=newJTextField();
txtpassword.setBounds(261,103,86,24);
contentPane.add(txtpassword);
txtpassword.setColumns(10);
JButtonbtnadd=newJButton("u589Eu52A0");
btnadd.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(txtname.getText().equals("")||txtpassword.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),"用戶名和密碼不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Usersu=newUsers();
u.setPwd(txtpassword.getText());
u.setUsername(txtname.getText());
UserDAOusdo=newUserDAO();
usdo.addUser(u);
}
}
});
btnadd.setBounds(45,205,113,27);
contentPane.add(btnadd);
JButtonbtndelete=newJButton("u5220u9664");
btndelete.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
if(txtname.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),"用戶名不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
UserDAOusdo=newUserDAO();
usdo.delUser(txtname.getText());;
}
}
});
btndelete.setBounds(172,205,113,27);
contentPane.add(btndelete);
JButtonbtnupdate=newJButton("u4FEEu6539");
btnupdate.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(txtname.getText().equals("")||txtpassword.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),"用戶名和密碼不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Usersu=newUsers();
u.setPwd(txtpassword.getText());
u.setUsername(txtname.getText());
UserDAOusdo=newUserDAO();
usdo.updateUser(u);;
}
}
});
btnupdate.setBounds(300,205,113,27);
contentPane.add(btnupdate);
JButtonbtnfind=newJButton("u67E5u8BE2");
btnfind.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(txtname.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),"用戶名不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Usersu=newUsers();
UserDAOusdo=newUserDAO();
u=usdo.findUser(txtname.getText(),txtpassword.getText());
if(u!=null){
JOptionPane.showMessageDialog(getContentPane(),"該用戶存在!","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
JOptionPane.showMessageDialog(getContentPane(),"該用戶不存在!","提示信息框",JOptionPane.WARNING_MESSAGE);
}
}
}
});
btnfind.setBounds(427,205,113,27);
contentPane.add(btnfind);
//記得要寫這個
setVisible(true);
}
}
❼ JAVA:編寫一個學生成績管理系統。學生的屬性包括學號、姓名、年齡等。
classStudent{
Stringname;
Stringid;
intage;
Couse[]course;
}
classCourse{
Stringcoursename;
floatpscourse;
floatqzcourse;
floatsxcourse;
floatqmcourse;
floatzpcourse;
}
這個要寫好長時間的,定義幾個類;然後實現具體的功能。用數組或者集合來存儲學生信息還有成績信息,最後定義一個測試類。你可以找我私聊,1368270359qq
❽ 基於java設計一個學生成績管理系統,要求有界面,且有增加,查詢,修改,刪除,退出功能,代碼如何寫
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import javax.swing.JButton;
public class Stmessege {
Font font = new Font("楷體", Font.BOLD, 18);
private Frame m = new Frame("登陸成功界面");
protected Window f;
public Stmessege() {
m.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
m.setVisible(false);
m.dispose();
System.exit(0);
}
});
m.setSize(460, 360);
m.setBackground(Color.green);
m.setLayout(null);
m.setLocationRelativeTo(null);
Label l0 = new Label("管理員信息");
Font font1 = new Font("楷體", Font.BOLD, 32);
l0.setForeground(Color.blue);
l0.setSize(180, 50);
l0.setLocation(150, 30);
l0.setFont(font1);
final Label l1 = new Label("姓名:");
l1.setSize(60, 20);
l1.setLocation(10, 100);
l1.setFont(font);
TextField tf1 = new TextField("黃朋");
tf1.setForeground(Color.blue);
tf1.setBackground(Color.white);
tf1.setSize(50, 20);
tf1.setLocation(70, 100);
final Label l2 = new Label("學號:");
l2.setSize(60, 20);
l2.setLocation(140, 100);
l2.setFont(font);
TextField tf2 = new TextField("111265");
tf2.setForeground(Color.blue);
tf2.setBackground(Color.white);
tf2.setSize(60, 20);
tf2.setLocation(190, 100);
final Label l3 = new Label("性別:");
l3.setSize(60, 20);
l3.setLocation(280, 100);
l3.setFont(font);
TextField tf3 = new TextField("男");
tf3.setForeground(Color.blue);
tf3.setBackground(Color.white);
tf3.setSize(40, 20);
tf3.setLocation(360, 100);
final Label l4 = new Label("班級:");
l4.setSize(60, 20);
l4.setLocation(10, 170);
l4.setFont(font);
TextField tf4 = new TextField("611231");
tf4.setForeground(Color.blue);
tf4.setBackground(Color.white);
tf4.setSize(60, 20);
tf4.setLocation(67, 170);
final Label l5 = new Label("系別:");
l5.setSize(60, 20);
l5.setLocation(140, 170);
l5.setFont(font);
TextField tf5 = new TextField("計算機工程系");
tf5.setForeground(Color.blue);
tf5.setBackground(Color.white);
tf5.setSize(80, 20);
tf5.setLocation(200, 170);
final Label l6 = new Label("成績:");
l6.setSize(60, 20);
l6.setLocation(280, 170);
l6.setFont(font);
TextField tf6 = new TextField("95");
tf6.setForeground(Color.blue);
tf6.setBackground(Color.white);
tf6.setSize(40, 20);
tf6.setLocation(360, 170);
final Label l7 = new Label("專業:");
l7.setSize(60, 20);
l7.setLocation(10, 230);
l7.setFont(font);
TextField tf7 = new TextField("軟體技術");
tf7.setForeground(Color.blue);
tf7.setBackground(Color.white);
tf7.setSize(60, 20);
tf7.setLocation(70, 230);
JButton btn1 = new JButton("添加");
btn1.setForeground(Color.blue);
btn1.setSize(80, 38);
btn1.setLocation(35, 300);
btn1.setFont(font);
btn1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 插入();
m.setVisible(true);
}
});
JButton btn2 = new JButton("查詢學生學籍信息");
btn2.setForeground(Color.blue);
btn2.setSize(200, 38);
btn2.setLocation(135, 300);
btn2.setFont(font);
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Stmessege1 f;
try {
f = new Stmessege1();
f.Stmessege11();
m.setVisible(true);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
JButton btn3 = new JButton("刪除");
btn3.setForeground(Color.blue);
btn3.setSize(80, 38);
btn3.setLocation(350, 300);
btn3.setFont(font);
btn3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 刪除();
//f.setVisible(false);
m.setVisible(true);
}
});
JButton btn4 = new JButton("更新");
btn4.setForeground(Color.blue);
btn4.setSize(80, 38);
btn4.setLocation(200, 230);
btn4.setFont(font);
btn4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 更新();
m.setVisible(true);
}
});
m.add(l0);
m.add(l1);
m.add(tf1);
m.add(l2);
m.add(tf2);
m.add(l3);
m.add(tf3);
m.add(l4);
m.add(tf4);
m.add(l5);
m.add(tf5);
m.add(l6);
m.add(tf6);
m.add(l7);
m.add(tf7);
m.add(btn1);
m.add(btn2);
m.add(btn3);
m.add(btn4);
m.setVisible(true);
}
public static void main(String[] args) {
new Stmessege();
}
}
可以仿照我的做一下,希望採納,我才一級哦
❾ 如何用Java語言編寫學生成績管理系統
寫過一個類似的給了你吧
packagestudent;
importjava.util.Scanner;
publicclassteststudent{
publicstaticvoidmain(Stringargs[]){
System.out.println("************************學生成績管理系統*********************");
System.out.println("請輸入要管理的學生人數:");
Scannersc=newScanner(System.in);
intn=sc.nextInt();
studentMassagestum=newstudentMassage(n);
intflag=1;
while(flag==1){
System.out.println("1.輸入學生信息");
System.out.println("2.通過姓名查找學生信息");
System.out.println("3.顯示全部學生信息");
System.out.println("4.退出系統");
intop=sc.nextInt();
switch(op){
case1:stum.addStudent(n);
newScanner(System.in).nextLine();
break;
case2:
System.out.println("輸入學生姓名:");
Stringname=sc.next();
stum.FindStudent(name);
newScanner(System.in).nextLine();
break;
case3:
stum.showallStudent();
newScanner(System.in).nextLine();
break;
case4:
flag=0;
System.out.println("已退出系統!");
break;
default:
System.out.println("輸入有誤!");
newScanner(System.in).nextLine();
}
}
}
}
classDate{
intyear;
intmonth;
intday;
/*publicDate(intyear,intmonth,intday){
this.year=year;
this.month=month;
this.day=day;
}
publicDate(){}*/
publicStringshowDate(){
returnyear+"/"+month+"/"+day;
}
}
classstudent{
intid;
Stringname;
Datedate;
floatscore;
publicstudent(){
id=0;
name=null;
date=null;
score=0f;
}
publicvoidshowStudent(){
System.out.println(id+""+name+""+""+date.showDate()+""+score);
}
}
classstudentMassage{
privatestudent[]stu;
privateintflag;
publicstudentMassage(intn){
flag=0;
if(stu==null){
stu=newstudent[n];
for(inti=0;i<n;++i){
stu[i]=newstudent();
}
}
}
publicvoidaddStudent(intn){
flag=1;
Scannersc=newScanner(System.in);
System.out.println("請輸入"+n+"個學生信息");
for(inti=0;i<stu.length;++i){
stu[i].date=newDate();
System.out.println("請輸入第"+(i+1)+"個學生學號:");
stu[i].id=sc.nextInt();
System.out.println("請輸入第"+(i+1)+"個學生姓名:");
stu[i].name=sc.next();
System.out.println("請輸入第"+(i+1)+"個學生出生年份:");
stu[i].date.year=sc.nextInt();
System.out.println("請輸入第"+(i+1)+"個學生出生月份:");
stu[i].date.month=sc.nextInt();
System.out.println("請輸入第"+(i+1)+"個學生出生日期:");
stu[i].date.day=sc.nextInt();
//stu[i].date=newDate(year,month,day);
System.out.println("請輸入第"+(i+1)+"個學生分數:");
stu[i].score=sc.nextFloat();
}
}
publicvoidFindStudent(Stringsname){
studentfind=null;
if(flag!=0){
for(inti=0;i<stu.length;++i){
if(sname.equals(stu[i].name))
find=stu[i];
}
if(find==null)
System.out.println("查無此人!");
else
find.showStudent();
}else
System.out.println("沒有輸入學生信息!");
}
publicvoidshowallStudent(){
System.out.println("所有學生的信息如下:");
System.out.println("學號姓名生日分數");
for(inti=0;i<stu.length;++i){
stu[i].showStudent();
}
}
}
❿ 用java編寫一個學生成績管理系統. //1.學生類 學號 姓名 年齡 語數外三科成績(三科成績)
用數組可以,也可以用集合來存儲各個同學的成績。
添加刪除等信息簡單。
這里有個迷你圖書管理系統,類似,我剛寫的。你看看之後應該會有思路了。如果用集合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("**********謝謝使用**********");
}
}
希望能幫到你!!!