package bookbuy;
public class BookList {
private int id;
private String name;
private double price;
public BookList(int id, String name, double price) {
super();
this.id = id;
this.name = name;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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 String toString() {
return id +"\t"+name +"\t"+price +"\t";
}
}
package bookbuy;
public class Order {
private int id;
private BookList sc = new BookList(1, null, 0);
private int num;
public Order(int id, BookList sc, int num) {
super();
this.id = id;
this.sc = sc;
this.num = num;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public BookList getSc() {
return sc;
}
public void setSc(BookList sc) {
this.sc = sc;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
@Override
public String toString() {
return id +"\t"+sc +"\t"+num+"\t";
}
}
package bookbuy;
public class Ordermath {
private double totalMoney;
private Order sc = new Order(1, null, 0);
public Ordermath(double totalMoney, Order sc) {
super();
this.totalMoney = totalMoney;
this.sc = sc;
}
public double getTotalMoney() {
return totalMoney;
}
public void setTotalMoney(double totalMoney) {
this.totalMoney = totalMoney;
}
public Order getSc() {
return sc;
}
public void setSc(Order sc) {
this.sc = sc;
}
public double String() {
return totalMoney;
}
}
package bookbuy;
import java.util.Scanner;
public class Bookmian {
public static void main(String[] args) {
BookList[] Books = getData();
putData(Books);
total(Books);
showOrdermath(Ordermaths);
}
public static BookList[] getData()
{
BookList Books[] = new BookList[3];
Books[0] = new BookList(1,"Java基础",29.8);
Books[1] = new BookList(2,"Jsp教程",45.0);
Books[2] = new BookList(3,"SSH框架",39.8);
return Books;
}
public static void putData(BookList[] Books)
{
System.out.println("书籍列表:");
System.out.println("------------------------------");
for(BookList b:Books)
{
System.out.println(b.toString());
}
System.out.println("------------------------------");
}
public static Ordermath total(BookList[] Books){
int bid = 1;
int num = 0;
double totalMoney = 0;
String choice = "";
Scanner sc = new Scanner(System.in);
Ordermath Ordermaths[] = new Ordermath[3];
Order Orders[] = new Order[3];
do{
System.out.println("请输入购买书籍序列号:");
bid = sc.nextInt();
System.out.println("请输入购买书籍数量:");
num = sc.nextInt();
Orders[bid-1] = new Order(bid,Books[bid-1],num);
totalMoney += num*Books[bid-1].getPrice();
Ordermaths[bid-1] = new Ordermath(totalMoney,Orders[bid-1]);
System.out.println("是否继续(Y|y or anykey)");
choice = sc.nextLine();
}
while(choice.equals("Y")|choice.equals("Y")){
Ordermaths[bid-1] = new Ordermath(totalMoney,Orders[bid-1]);
return Ordermaths[bid-1];
}
}
public static void showOrdermath(Ordermath[] Ordermaths) {
System.out.println("订单信息:");
System.out.println("------------------------------");
for(Ordermath c:Ordermaths){
System.out.println(c.toString());
}
System.out.println("------------------------------");
}
}
为啥子运行不了,还是我逻辑有问题吗