一款簡(jiǎn)單的java小程序
首先Book類奔浅,定義方法
public class Book {
private String bookName; // 圖書名稱
public Book(String bookName) {
super();
this.bookName = bookName;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
@Override
public String toString() {
return "\t" + bookName;
}
}
Save類馆纳,定義數(shù)組
public class Save {
// 靜態(tài)數(shù)組
static String[] books = { "道德經(jīng)", "山海經(jīng)", "Android藝術(shù)探索", "論程序員素養(yǎng)" };
// 動(dòng)態(tài)數(shù)組
Books[] books1 = new Books[10];
// 初始化
public void jieyue() {
books1[0] = new Books();
books1[0].names = "ss";
}
public class Books {
String names;
}
}
這里為主程序
public class System_1 extends Save {
static String[] books1 = new String[5];
public static void main(String[] args) {
// 第一界面
while (true) {
Scanner s = new Scanner(System.in);
System.out.print("請(qǐng)輸入用戶名:");
String username = s.next();
System.out.print("請(qǐng)輸入密碼:");
String passward = s.next();
System.out.println(" 歡迎進(jìn)入圖書管理系統(tǒng)");
// 主界面
while (true) {
System.out.println(" 1.借 書");
System.out.println(" 2.借閱信息");
System.out.println(" 3.還 書");
System.out.println(" 4.退 出");
System.out.println("請(qǐng)輸入對(duì)應(yīng)編號(hào):");
int a = s.nextInt();
switch (a) {
case 1:
// 子a1界面
System.out.println(" 借 書");
System.out.println(" 1.道德經(jīng)");
System.out.println(" 2.山海經(jīng)");
System.out.println(" 3.Android藝術(shù)探索");
System.out.println(" 4.論程序員素養(yǎng)");
int a1 = s.nextInt();
switch (a1) {
case 1:
System.out.println("\n" + " 您已成功借閱《"
+ books[0] + "》!");
books1[0] = "道德經(jīng)";
break;
case 2:
System.out.println("\n" + " 您已成功借閱《"
+ books[1] + "》汹桦!");
books1[1] = "山海經(jīng)";
break;
case 3:
System.out.println("\n" + " 您已成功借閱《"
+ books[2] + "》鲁驶!");
books1[2] = "Android藝術(shù)探索";
break;
case 4:
System.out.println("\n" + " 您已成功借閱《"
+ books[3] + "》!");
books1[3] = "論程序員素養(yǎng)";
break;
default:
System.out.println("請(qǐng)選擇正確編號(hào)舞骆!");
break;
}
break;
// 子a2界面
case 2:
System.out.println(" 借閱信息");
if (books1[0] == null && books1[1] == null
&& books1[2] == null && books1[3] == null) {
System.out.println(" 您的書庫空無一物钥弯!");
} else {
String xa = null, xb = null, xc = null, xd = null;
if (books1[0] == null) {
xa = " ";
} else
xa = books1[0];
if (books1[1] == null) {
xb = " ";
} else
xb = books1[1];
if (books1[2] == null) {
xc = " ";
} else
xc = books1[2];
if (books1[3] == null) {
xd = " ";
} else
xd = books1[3];
System.out.println("您借閱到的書有");
System.out.println(" " + xa + "\r" + xb + "\r"
+ xc + "\r" + xd);
}
break;
// 子a3界面
case 3:
System.out.println(" 還書");
if (books == null) {
System.out.println(" 請(qǐng)確認(rèn)借閱情況!");
} else {
books = null;
System.out.println(" 已歸還");
}
break;
// 子a4界面
case 4:
System.out.println(" 您已成功退出督禽!");
System.exit(0);
break;
default:
System.out.println("請(qǐng)選擇正確編號(hào)脆霎!");
break;
}
}
}
}
}
完結(jié)撒花