你的程序中錯誤很多,下面是我修改后的程序,其中的錯誤在程序的注釋中說明了,希望可以幫到你#include//usingnamespacestd;由于VC的Debug出現(xiàn)了fatalerrorC1001:INTERNALCOMPILERERROR錯誤,//將這個注釋掉,上面寫成#includeclass Vect{//向量表示 float *p;//指向向量的指針 int n;//向量的元素個數(shù)public: Vect(floata[]){ n=10; //這里初始化n,為了簡單,暫時給n賦10 p=newfloat[10]; //你需要給你的指針分配空間才可以給指針賦值 for(inti=0;in!=v.n) return0; //this是指針,不能用this.a,error沒有定義,不能隨便用 for(inti=0;ip[i]+v.p[i]; //這里不能用this.p[i],因為this是指針,要用this-p[i] returna;}Vectoperator-(Vectv1,Vectv2) //你程序中VectVECT::operator-(Vectv),‘-’重載的運算符是友元而不是類的成員函數(shù){ //友元函數(shù)重載的雙目運算符,形參需要兩個,因為友元函數(shù)既然不屬于類,那么自然沒有隱含this指針 floatb[10]={0}; Vecta(b); if(v1.n!=v2.n)return0; //同理,error沒有定義,不能隨便用 for(inti=0;i
創(chuàng)新互聯(lián)專注于四川網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供四川營銷型網(wǎng)站建設,四川網(wǎng)站制作、四川網(wǎng)頁設計、四川網(wǎng)站官網(wǎng)定制、成都微信小程序服務,打造四川網(wǎng)絡公司原創(chuàng)品牌,更為您提供四川網(wǎng)站排名全網(wǎng)營銷落地服務。
import?java.io.BufferedReader;
import?java.io.File;
import?java.io.FileReader;
import?java.util.ArrayList;
import?java.util.List;
import?java.util.Scanner;
public?class?BookWork?{
static?ListBook?data;
private?static?Scanner?input;
public?static?void?main(String[]?args)?{
if?(!initBook("d:/book.txt"))?{
System.out.println("初始圖書列表失敗?..");
return;
}
input?=?new?Scanner(System.in);
while?(true)?{
try?{
System.out.println("請輸入操作:");
System.out.println("1.找書??2.刪除圖書?3.退出");
int?number?=?Integer.parseInt(input.next());
if?(number?==?1)?{
findBook();
}?else?if?(number?==?2)?{
delBook();
}?else?if?(number?==?3)?{
System.out.println("退出");
break;
}?else?{
System.out.println("這個不是我要的...重來...");
System.out.println();
}
}?catch?(Exception?e)?{
e.printStackTrace();
System.out.println("這個不是我要的...重來...");
System.out.println();
}
}
}
private?static?void?delBook()?{
System.out.println("請輸入要刪除的書名或編號:");
String?key?=?input.next();
if?(key?!=?null??!key.equals(""))?{
for?(Book?book?:?data)?{
if?(book.number.equals(key)?||?book.name.contains(key))?{
data.remove(book);
System.out.println("?圖書?"?+?book.toString()?+?"?已刪除");
return;
}
}
}
System.out.println("沒有您要刪除的");
}
private?static?void?findBook()?{
System.out.println("請輸入要查找的書名或編號:");
String?key?=?input.next();
if?(key?!=?null??!key.equals(""))?{
for?(Book?book?:?data)?{
if?(book.number.equals(key)?||?book.name.contains(key))?{
System.out.println("找到了?圖書?"?+?book.toString());
return;
}
}
}
System.out.println("沒有您要找的");
}
private?static?boolean?initBook(String?string)?{
try?{
System.out.println("圖書導入中...");
System.out.println("列表文件?--?"?+?string);
File?file?=?new?File(string);
if?(!file.exists())?{
return?false;
}
data?=?new?ArrayListBook();
BufferedReader?bufferedReader?=?new?BufferedReader(new?FileReader(file));
String?line?=?"";
while?((line?=?bufferedReader.readLine())?!=?null)?{
String[]?strings?=?line.split(",");
Book?b?=?new?Book(strings[0],?strings[1]);
data.add(b);
System.out.println("導入"?+?b.toString());
}
}?catch?(Exception?e)?{
e.printStackTrace();
return?false;
}
return?true;
}
public?static?class?Book?{
String?number;
String?name;
public?Book(String?number,?String?name)?{
super();
this.number?=?number;
this.name?=?name;
}
@Override
public?String?toString()?{
return?"Book?[編碼:"?+?number?+?",?名稱:"?+?name?+?"]";
}
}
}
001,金瓶梅
002,雜事秘辛
003,飛燕外傳
004,控鶴監(jiān)秘記
005,漢宮春色
1.先用jdbc連接數(shù)據(jù)庫,這個網(wǎng)上好多你去搜下就有
2.借書還書就是對某張表的更新操作,你借書還書的時候可以得到該書的一個id,這時,你通過這個id從數(shù)據(jù)庫中找到所對應的數(shù)據(jù),更改書得庫存量即可。
自己動手做一遍,其實不難的,加油!
---------------------------------------------------
給你修改了三個地方:
1.borrowBooks方法中,將System.out.println("你要借嗎?"); 改為:
System.out.println("你要借嗎?輸入1表示借,其他數(shù)字表示不借。");
保證輸入的時候輸入的數(shù)字,否則會報出異常。
2.borrowBooks方法中,將self[score] = all[9]; 改為:self[score] = all[i];
如果是all[9],那么就始終是最后一本書籍信息了。
3.have方法中,你是想將所借的書籍信息都打印出來。修改的比較多,下面注釋代碼是原來的。
void have(Books[] self) {
// for (int i = 0; i 2; i++) {
// self[i].showBookInfo();
// }
for (int i = 0; i 3; i++) {
if(self[i]!=null)
self[i].showBookInfo();
}
}
****************** 附上所有代碼:*************************
import java.util.Scanner;
public class TestBook {
public static void main(String[] args) {
Books all[] = new Books[10];
Books self[] = new Books[3];
all[0] = new Books("java", 1, "12345", "tom", 34.0f, "人民出版社");
all[1] = new Books("c", 2, "12346", "tnn", 31.0f, "人民出版社");
all[2] = new Books("c++", 3, "12445", "mm", 35.0f, "人民出版社");
all[3] = new Books("c#", 4, "12365", "tt", 38.0f, "人民出版社");
all[4] = new Books("j2se", 5, "13345", "tosm", 31.1f, "人民出版社");
all[5] = new Books("j2ee", 6, "18345", "ttm", 32.0f, "人民出版社");
all[6] = new Books("jsp", 7, "12335", "cc", 33.0f, "人民出版社");
all[7] = new Books("net", 8, "12341", "bb", 36.0f, "人民出版社");
all[8] = new Books("ip", 9, "12343", "aa", 37.0f, "人民出版社");
all[9] = new Books("tcp", 10, "22345", "jj", 39.0f, "人民出版社");
Readers r = new Readers("xiaoming", 101, "1", 3);
r.searchAllBooks(all);
r.borrowBooks(all, self);
r.have(self);
r.give(all, self);
}
}
class Readers {
Scanner scan = new Scanner(System.in);
String names;
int nums;
String classes;
int grade;
int score = 0;
// Books self[]=new Books[3];
Readers(String n, int u, String c, int g) {
names = n;
nums = u;
classes = c;
grade = g;
}
void searchAllBooks(Books[] all) {// 查書
for (int i = 0; i 10; i++)
all[i].showBookInfo();
// self[score]=all[0];
}
void give(Books[] all, Books[] self) {// 還書
System.out.println("請輸入您要還的書的書號");
int n = scan.nextInt();
for (int i = 0; i 10; i++) {
if (n == all[i].num) {
for (int j = 0; j 3; j++) {
if (self[j] == all[i]) {
self[j] = null;
System.out.println("還書成功");
}
}
}
}
}
void have(Books[] self) {
// for (int i = 0; i 2; i++) {
// self[i].showBookInfo();
// }
for (int i = 0; i 3; i++) {
if(self[i]!=null)
self[i].showBookInfo();
}
}
void giveMoney() {
}
void borrowBooks(Books[] all, Books[] self) {
System.out.println("請輸入您要查找的書名:");
String n = scan.next();
int i;
for (i = 0; i 10; i++) {
if (n.equals(all[i].name)) {
all[i].showBookInfo();
break;
}
}
//System.out.println("你要借嗎?");
System.out.println("你要借嗎?輸入1表示借,其他數(shù)字表示不借。");
int j;
j = scan.nextInt();
if (j == 1) {
System.out.println("借閱成功");
//self[score] = all[9];
self[score] = all[i];
score += 1;
}
if (score 4) {
System.out.println("您還可以借閱" + (3 - score) + "本");
} else {
System.out.println("對不起,一個人只能借3本");
}
}
}
class Books {
String name;
int num;
String ISBN;
String writer;
float price;
String publisher;
Books(String n, int u, String i, String w, float p, String l) {
name = n;
num = u;
ISBN = i;
writer = w;
price = p;
publisher = l;
}
void showBookInfo() {
System.out.println("**************************");
System.out.println("書名:" + name);
System.out.println("索書號:" + num);
System.out.println("ISBN號:" + ISBN);
System.out.println("價格:" + price);
System.out.println("出版社:" + publisher);
System.out.println("**************************");
}
}
----------------------------------------------------
當前題目:java更新圖書代碼 java圖書類代碼
瀏覽地址:http://jinyejixie.com/article48/dopcshp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計、定制開發(fā)、網(wǎng)站維護、網(wǎng)站建設、域名注冊、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)