大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
/**
成都创新互联公司是专业的西工网站建设公司,西工接单;提供成都网站制作、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行西工网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
* 书籍
*/
public class Book {
private String name; //书名
private String author; //作者
private String publisher; //出版社
private Integer price; //价格,分为单位,不使用浮点数防止精度丢失
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;
/**
* 购物车
* 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总价
*
* @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" + "总价格:" + getYuanPrice(getTotalPrice()) + "元";
}
/**
* 把分转换成元
*
* @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());
}
}
这是两个类,分别放到Book.java 跟Cart.java两个类文件中,直接执行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 + ", 书号:" + number + ", 价格:" + price ;
}
//可以从这调用get set 方法 设置属性
public static void main(String[] args) {
Book book = new Book();
System.out.println(book.toString());
}
}
//它包含图书的作者、书名、书号、月销售量属性,
//另有两个构造方法(一个带参数,一个不带参数),
//有一个成员方法printBook()用于输出数据。设置一测试类测试并输出。
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;
}
}
测试类:
public static void main(String[] args) {
Book b = new Book("author","title","123456798",1000);
b.printBook();
}
我看到数据好像是保存在文件中的,这样解析很不给力。
建议使用 access 数据库,小巧又好用。
其他的这几个功能也不难,楼主,你哪里不会,你的思路是什么,可以讲一讲,可以协助你完成。
1,先说明的这个系统是要干什么,包含什么功能,做成什么样(b/s,c/s??)
2、用java语言完成这个目标,需要用到java那些技术,用什么数据库?EJB?jsf?jsp?JPA?ssh?swing?
3、逐一简单的介绍一下你选用的技术框架,并说明优缺点;
4、简单的系统的概要设计(包含的功能框架)
5、核心代码的介绍
6、完成的成果(具体成果的展示,可以贴图表示)
7、简单的总结