RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
图书信息修改java代码 用java添加图书信息的代码

java多层list实现图书的增删改查?

import java.util.ArrayList;

10多年的神池网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整神池建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“神池网站设计”,“神池网站推广”以来,每个客户项目都认真落实执行。

import java.util.List;

/**

* 测试类

*

* @author 时间在流

*

*/

public class Test {

/**

* 这个属性用来模仿书房

*/

private ListListString room = new ArrayListListString();

/**

* 向书房里添加一个书架

*

* @return 新添加书架的索尘蠢搜引

*/

public int addBookShelf() {

room.add(new ArrayListString());

return room.size() - 1;

}

/**

* 向书架里添加一本书

*

* @param bookShelfIndex 书架索引

* @param book 书。这里就用一个字符串代表一本书了,你要愿意也可以单独创建一个派历书类

* @return 新添加书籍的索引

*/

public int addBook(int bookShelfIndex, String book) {

ListString shelf = room.get(bookShelfIndex);

shelf.add(book);

return shelf.size() - 1;

}

// 更新书架我就不写了。

/**

* 更新书架上的某本书

*

* @param bookShelfIndex 书架索引

* @param bookIndex 旧书索引

* @param newBook 新书

*/

public void setBook(int bookShelfIndex, int bookIndex, String newBook) {

ListString shelf = room.get(bookShelfIndex);

shelf.set(bookIndex, newBook);

}

/**

* 移除一个书架

*

* @param bookShelfIndex 书架索引

* @return 剩余档御书架的个数

*/

public int removeBookShelf(int bookShelfIndex) {

room.remove(bookShelfIndex);

return room.size();

}

/**

* 移除书架上的某本书

*

* @param bookShelfIndex 书架索引

* @param bookIndex 书籍索引

* @return 该书架剩余书的数量

*/

public int removeBook(int bookShelfIndex, int bookIndex) {

ListString shelf = room.get(bookShelfIndex);

shelf.remove(bookIndex);

return shelf.size();

}

/**

* 获得一个书架

*

* @param bookShelfIndex 书架索引

* @return 书架

*/

public ListString getBookShelf(int bookShelfIndex) {

return room.get(bookShelfIndex);

}

/**

* 获得书架上的某本书。在现实生活中拿走了一本书,书架上应该会少一本

*

* @param bookShelfIndex 书架索引

* @param bookIndex 书籍索引

* @return 书籍

*/

public String getBook(int bookShelfIndex, int bookIndex) {

ListString shelf = room.get(bookShelfIndex);

return shelf.get(bookIndex);

}

public static void main(String[] args) {

Test test = new Test();

int shelf1Index = test.addBookShelf();

int shelf2Index = test.addBookShelf();

int book1Index = test.addBook(shelf1Index, "鬼吹灯");

int book2Index = test.addBook(shelf1Index, "盗墓笔记");

int book3Index = test.addBook(shelf2Index, "斗破苍穹");

int book4Index = test.addBook(shelf2Index, "斗罗大陆");

test.setBook(shelf2Index, book4Index, "吞噬星空");

System.out.println("2号书架的第2本书是" + test.getBook(shelf2Index, book4Index));

System.out.println("移除了2号书架的第2本书,2号书架还剩" + test.removeBook(shelf2Index, book4Index) + "本书");

System.out.println("移除了第2个书架,现在还剩" + test.removeBookShelf(shelf2Index) + "个书架");

ListString shelf = test.getBookShelf(shelf1Index);

System.out.println("1号书架书籍列表:");

for (String book : shelf) {

System.out.println(book);

}

}

}

用Java编写一个图书类程序:1.属性:图书编号,图书名称,出版社,库存量。2.构造方法:至少两个

package com.hua.excep;

public class Libary {

private int id;

private String name;

private String shop;

private int num;

//两个构造方法

/答判并/无清迹参

public Libary() {

}

//四个参数

public Libary(int id, String name, String shop, int num) {

this.id = id;

this.name = name;

this.shop = shop;

this.num = num;

}

//输入图书信息

public void inputBook(int id,String name,String shop){

this.id=id;

this.name=name;

this.shop=shop;

}

//冲兄输出三个图书信息

public int getId() {

return id;

}

public String getName() {

return name;

}

public String getShop() {

return shop;

}

//修改库存

public void setNum(int num) {

this.num = num;

}

}

用java编写一个 图书馆图书借阅管理系统

---------------------------------------------------

给你修改了三个地方:

1.borrowBooks方法中,将System.out.println("你要借吗?"); 改为:

System.out.println("你要借吗闷前?输入1表示借,其他数字表示不借。");

保证输入的时候输入的数字,否则会报裂隐出异常。

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表示借,其他数字表示不借。");

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语言设计一款小型图书管理系统颂中,能够通过主卜漏界面根据关键字查询图书信息,能够型樱烂添加图书信息和删除过去图书信息


网站标题:图书信息修改java代码 用java添加图书信息的代码
网页路径:http://cqwzjz.cn/article/ddpjcdo.html