/**
成都創(chuàng)新互聯(lián)公司是專業(yè)的西工網(wǎng)站建設(shè)公司,西工接單;提供成都網(wǎng)站制作、做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行西工網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
*?書籍
*/
public?class?Book?{
private?String?name;?//書名
private?String?author;?//作者
private?String?publisher;?//出版社
private?Integer?price;?//價(jià)格,分為單位,不使用浮點(diǎn)數(shù)防止精度丟失
public?Book(String?name,?String?author,?String?publisher,?Integer?price)?{
this.name?=?name;
this.author?=?author;
this.publisher?=?publisher;
this.price?=?price;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?String?getAuthor()?{
return?author;
}
public?void?setAuthor(String?author)?{
this.author?=?author;
}
public?String?getPublisher()?{
return?publisher;
}
public?void?setPublisher(String?publisher)?{
this.publisher?=?publisher;
}
public?Integer?getPrice()?{
return?price;
}
public?void?setPrice(Integer?price)?{
this.price?=?price;
}
@Override
public?String?toString()?{
return?"Book{"?+
"name='"?+?name?+?'\''?+
",?author='"?+?author?+?'\''?+
",?publisher='"?+?publisher?+?'\''?+
",?price="?+?price?+
'}';
}
}
import?java.util.ArrayList;
import?java.util.List;
/**
*?購(gòu)物車
*?Created?by?admin?on?2016/5/17.
*/
public?class?Cart?{
ListBook?books?=?new?ArrayList();
/**
*?添加書籍
*
*?@param?book
*/
public?void?addBook(Book?book)?{
books.add(book);
}
/**
*?獲取book信息
*
*?@return
*/
public?String?getBookInfo()?{
return?books.toString();
}
/**
*?獲取book總價(jià)
*
*?@return
*/
public?Integer?getTotalPrice()?{
Integer?totalPrice?=?0;
if?(null?!=?books??books.size()??0)?{
for?(Book?book?:?books)?{
totalPrice?+=?book.getPrice();
}
}
return?totalPrice;
}
public?String?getTotalInfo()?{
return?"書籍信息:\r\n"?+?getBookInfo()?+?"\r\n"?+?"總價(jià)格:"?+?getYuanPrice(getTotalPrice())?+?"元";
}
/**
*?把分轉(zhuǎn)換成元
*
*?@param?price
*?@return
*/
public?static?String?getYuanPrice(Integer?price)?{
String?strPrice?=?String.valueOf(price);
while?(strPrice.length()??3)?{
strPrice?=?"0"?+?strPrice;
}
strPrice?=?strPrice.substring(0,?strPrice.length()?-?2)?+?"."?+?strPrice.substring(strPrice.length()?-?2);
return?strPrice;
}
public?static?void?main(String?args[])?{
Cart?cart?=?new?Cart();
cart.addBook(new?Book("書名",?"作者",?"出版社",?1245));
cart.addBook(new?Book("書名1",?"作者1",?"出版社1",?3458));
cart.addBook(new?Book("書名2",?"作者2",?"出版社2",?7859));
System.out.println(cart.getTotalInfo());
}
}
這是兩個(gè)類,分別放到Book.java?跟Cart.java兩個(gè)類文件中,直接執(zhí)行Cart里的main方法就可以了
輸出如下:
package?cn.book;
public?class?Book?{
private?String?auther="吳承恩";
private?String?name="西游記";
private?String?number="1";
private?double?price=100;
public?String?getAuther()?{
return?auther;
}
public?void?setAuther(String?auther)?{
this.auther?=?auther;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?String?getNumber()?{
return?number;
}
public?void?setNumber(String?number)?{
this.number?=?number;
}
public?double?getPrice()?{
return?price;
}
public?void?setPrice(double?price)?{
this.price?=?price;
}
@Override
public?String?toString()?{
return?"?作者:"?+?auther?+?",?書名:"?+?name?+?",?書號(hào):"?+?number?+?",?價(jià)格:"?+?price?;
}
//可以從這調(diào)用get?set?方法?設(shè)置屬性
public?static?void?main(String[]?args)?{
Book?book?=?new?Book();
System.out.println(book.toString());
}
}
//它包含圖書的作者、書名、書號(hào)、月銷售量屬性,
//另有兩個(gè)構(gòu)造方法(一個(gè)帶參數(shù),一個(gè)不帶參數(shù)),
//有一個(gè)成員方法printBook()用于輸出數(shù)據(jù)。設(shè)置一測(cè)試類測(cè)試并輸出。
public class Book {
private String author;
private String title;
private String num;
private int sale;
public Book(){}
public Book(String auther, String title, String num, int sale){
this.author = auther;
this.title = title;
this.num = num;
this.sale = sale;
}
public void printBook(){
System.out.println("author:" + author + ", title:" + title + ", num:" + num + ", sale:"+sale);
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public int getSale() {
return sale;
}
public void setSale(int sale) {
this.sale = sale;
}
}
測(cè)試類:
public static void main(String[] args) {
Book b = new Book("author","title","123456798",1000);
b.printBook();
}
我看到數(shù)據(jù)好像是保存在文件中的,這樣解析很不給力。
建議使用 access 數(shù)據(jù)庫(kù),小巧又好用。
其他的這幾個(gè)功能也不難,樓主,你哪里不會(huì),你的思路是什么,可以講一講,可以協(xié)助你完成。
1,先說(shuō)明的這個(gè)系統(tǒng)是要干什么,包含什么功能,做成什么樣(b/s,c/s??)
2、用java語(yǔ)言完成這個(gè)目標(biāo),需要用到j(luò)ava那些技術(shù),用什么數(shù)據(jù)庫(kù)?EJB?jsf?jsp?JPA?ssh?swing?
3、逐一簡(jiǎn)單的介紹一下你選用的技術(shù)框架,并說(shuō)明優(yōu)缺點(diǎn);
4、簡(jiǎn)單的系統(tǒng)的概要設(shè)計(jì)(包含的功能框架)
5、核心代碼的介紹
6、完成的成果(具體成果的展示,可以貼圖表示)
7、簡(jiǎn)單的總結(jié)