用java编写一个程序 急求

1创建一个图书类(Book),图书类中有成员变量:图书名称(bookname)、图书编号(bookno)、图书单价(bookprice)、图书库存量(bookamount... 1 创建一个图书类(Book),
图书类中有成员变量:图书名称(bookname)、图书编号(bookno)、图书单价(bookprice)、图书库存量(bookamount);
图书类中有成员方法:
setBookNo()
getBookNo()
setBookName()
getBookName()
setBookPrice()
getBookPrice()
setBookAmount()
setBookAmount()
这些方法能实现:输入图书编号能给出图书的详细信息。
2.用图书类创建一个对象“数据结构课本”(data_structure),
该书的图书编号为:9787900643223,
图书名称为:“数据结构”,
图书单价为:46,
图书库存量为:256本。
3.
试着输入图书编号9787900643223,输出该编号对应图书的详细信息。
以上3题都写在一个java文件中
展开
 我来答
testhdg
2013-03-20 · 超过19用户采纳过TA的回答
知道答主
回答量:119
采纳率:0%
帮助的人:62万
展开全部
import java.util.Scanner;
public class Book { private String bookname;
private String bookno;
private double bookprice;
private int bookamount;

public Book(String bookname, String bookno, double bookprice, int bookamount) { super();
this.bookname = bookname;
this.bookno = bookno;
this.bookprice = bookprice;
this.bookamount = bookamount;
}

public String getBookname() { return bookname;
}

public void setBookname(String bookname) { this.bookname = bookname;
}

public String getBookno() { return bookno;
}

public void setBookno(String bookno) { this.bookno = bookno;
}

public double getBookprice() { return bookprice;
}

public void setBookprice(double bookprice) { this.bookprice = bookprice;
}

public int getBookamount() { return bookamount;
}

public void setBookamount(int bookamount) { this.bookamount = bookamount;
}

public static void main(String[] args) { Book book = new Book("数据结构", "9787900643223", 46, 256);
System.out.println("请输入图书编号:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
if (str.equals(book.getBookno())) {
System.out.println("该编号对应图书的详细信息:" + book.getBookamount());
System.out.println("该编号对应图书的详细信息:" + book.getBookname());
System.out.println("该编号对应图书的详细信息:" + book.getBookno());
System.out.println("该编号对应图书的详细信息:" + book.getBookprice());
}
}
}
冰火两重天
2013-03-20 · TA获得超过1425个赞
知道小有建树答主
回答量:1489
采纳率:0%
帮助的人:989万
展开全部
import java.util.Scanner;
public class BookTest {
/**
* @param args
*/
public static void main(String[] args) {
Book data_structure = new Book("9787900643223","数据结构",46d,256);
Scanner scan = new Scanner(System.in);
System.out.println("请输入图书编号:");
String bookno = scan.next();
if (data_structure.getBookno().equals(bookno)) {
System.out.println("查找到的图书:" + data_structure);
}
else {
System.out.println("未找到图书!");
}
}

}
class Book {
private String bookno;
private String bookname;
private Double bookprice;
private Integer bookamount;

public Book(String bookno, String bookname, Double bookprice,
Integer bookamount) {
super();
this.bookno = bookno;
this.bookname = bookname;
this.bookprice = bookprice;
this.bookamount = bookamount;
}
public Book() {
super();
// TODO Auto-generated constructor stub
}
public String getBookno() {
return bookno;
}
public void setBookno(String bookno) {
this.bookno = bookno;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public Double getBookprice() {
return bookprice;
}
public void setBookprice(Double bookprice) {
this.bookprice = bookprice;
}
public Integer getBookamount() {
return bookamount;
}
public void setBookamount(Integer bookamount) {
this.bookamount = bookamount;
}
@Override
public String toString() {
return "Book [bookno=" + bookno + ", bookname=" + bookname
+ ", bookprice=" + bookprice + ", bookamount=" + bookamount
+ "]";
}

}

望采纳!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
hb_wxd
2013-03-20 · 超过33用户采纳过TA的回答
知道答主
回答量:131
采纳率:0%
帮助的人:91.4万
展开全部
package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.ObjectFileConvert;
/**
* @author wxiangd
*
*/
public class Book implements Serializable {
private String no;
private String name;
private double price;
private int amount;
public Book() {
}

public Book(String no, String name, double price, int amount) {
this.no = no;
this.name = name;
this.price = price;
this.amount = amount;
}

public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
/**
* 文件转化为Object
* @param fileName
* @return byte[]
*/
public static Object file2Object(String fileName) {

FileInputStream fis = null;
ObjectInputStream ois = null;
try {
fis = new FileInputStream(fileName);
ois = new ObjectInputStream(fis);
Object object = ois.readObject();
return object;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (ois != null) {
try {
ois.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
}
return null;
}

/**
* 把Object输出到文件
* @param obj
* @param outputFile
*/
public static void object2File(Object obj, String outputFile) {
ObjectOutputStream oos = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(outputFile));
oos = new ObjectOutputStream(fos);
oos.writeObject(obj);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
}
}

public static void main(String[] args) {

String fileName = "d:/test/object.obj";
List<Book> list = new ArrayList<Book>();
Book data_structure = new Book("9787900643223", "数据结构", 46, 256);
Book yellow = new Book("9787900643224", "金瓶梅", 180, 1);
list.add(data_structure);
list.add(yellow);

object2File(list, fileName);
System.out.println("success write List<String> to file.");

List<Book> tmpList = (List<Book>)file2Object(fileName);
for (Book tmp : tmpList) {
if(tmp.no.equals("9787900643223")){
System.out.println("no: "+tmp.no);
System.out.println("name: "+tmp.name);
System.out.println("price"+tmp.price);
System.out.println("amount: "+tmp.amount);
}
}
}
}
//混蛋,不是应该这样做的么
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
健康生活小PP
2013-03-20 · TA获得超过930个赞
知道小有建树答主
回答量:1217
采纳率:33%
帮助的人:428万
展开全部
明显JAVA基础作业= =
更多追问追答
追问
那你帮忙编一下啊
追答
自己写 这个是你的作业又不是别人的 编程工具里点几下敲几十个字符就完事 
哪怕你用记事本 所有步骤书上都有写 你为什么就不尝试自己写出来呢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-03-20
展开全部
懒得写,分太少
追问
多少分你才写啊  不要说100我没有
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
同碧曼00F
2013-03-20 · TA获得超过357个赞
知道小有建树答主
回答量:649
采纳率:0%
帮助的人:297万
展开全部
public class Book {
private String bookname;// 图书名称
private String bookno;// 图书编号
private double bookprice;// 图书单价
private int bookamount;// 图书库存量

public String getBookname() {
return bookname;
}

public void setBookname(String bookname) {
this.bookname = bookname;
}

public String getBookno() {
return bookno;
}

public void setBookno(String bookno) {
this.bookno = bookno;
}

public double getBookprice() {
return bookprice;
}

public void setBookprice(double bookprice) {
this.bookprice = bookprice;
}

public int getBookamount() {
return bookamount;
}

public void setBookamount(int bookamount) {
this.bookamount = bookamount;
}

public static void main(String[] args) {
//第一本书对象
Book data_structure=new Book();
data_structure.setBookno("9787900643223");
data_structure.setBookname("数据结构");
data_structure.setBookprice(46);
data_structure.setBookamount(256);
//第一本书对象
Book data_struct=new Book();
data_struct.setBookno("9787900643200");
data_struct.setBookname("软件工程");
data_struct.setBookprice(55);
data_struct.setBookamount(203);
Scanner scanner=new Scanner(System.in);
String dataNo;
while (true) {
System.out.println("请输入图书编号:0为退出循环");
dataNo=scanner.next();
if (dataNo.equals("9787900643223")) {
System.out.println("图书信息如下:");
System.out.println("图书编号: "+data_structure.getBookno());
System.out.println("图书名称: "+data_structure.getBookname());
System.out.println("图书价格: "+data_structure.getBookprice());
System.out.println("图书存储量: "+data_structure.getBookamount());
}else if(dataNo.equals("9787900643200")){
System.out.println("图书编号: "+data_struct.getBookno());
System.out.println("图书名称: "+data_struct.getBookname());
System.out.println("图书价格: "+data_struct.getBookprice());
System.out.println("图书存储量: "+data_struct.getBookamount());
}
}
}
}
这里我创建两本书对象,望采纳。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(4)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式