2011-3-15 01:15
淫濕的小笨笨
幫我解決問題
import java.util.scanner;
class book{
private string name;
private string author;
private string publisher;
private int price;
book(){
}
book(string name, string author, string publisher, int price){
this.name = name;
this.author = author;
this.publisher = publisher;
this.price = price;
}
public string tostring(){
return "書名:" + this.name + "\n作者:" + this.author +
"\n出版社:" + this.publisher + "\n訂價:" + this.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 int getprice() {
return price;
}
public void setprice(int price) {
this.price = price;
}
public double getsellprice(){
calculator calculator = new calculator();
double price = (double)this.price;
return calculator.calculate(price, 0.8);
}
}
class combook extends book{
boolean hasdisc;
string hasdisc(){
return this.hasdisc==true?"附光碟":"沒光碟";
}
void sethasdisc(boolean hasdisc){
this.hasdisc = hasdisc;
}
combook(){
}
combook(string name, string author, string publisher,
int price, boolean hasdisc){
super( name, author, publisher, price);
this.hasdisc = hasdisc;
}
}
class comic extends book{
boolean iscomic;
string iscomic(){
return this.iscomic==true?"書":"漫畫書";
}
void sethasdisc(boolean iscomic){
this.iscomic = iscomic;
}
class bookshop{
private combook[] combook = new combook[6];
bookshop(){
combook[0] = new combook("資料結構\t","曾志軒\t","碁峰文化\t",500,true);
combook[1] = new combook("j2ee\t\t\t","楊泰昇\t","博碩文化\t",380,true);
combook[2] = new comic("火影忍者\t","岸本齊史\t","東立",80,true);
combook[3] = new combook("macosx 10.5\t\t","施威銘研究室","旗標\t",560,true);
combook[4] = new comic("灌籃高手\t","井上雄彥\t","東立",80,true);
combook[5] = new combook("java程式設計藝術\t","deitel\t","全華圖書\t",650,true);
}
public string tostring(){
string result = "";
for(int i=0;i5?"\t":"\t\t");
result += combook[b].getauthor()+"\t";
result += combook[b].getpublisher()+"\t";
result += combook[b].getprice()+"\t";
if(combook[b] instanceof combook){
result += ((combook)combook[b]).hasdisc()+"\t";
}else{
result += ((iscomic)combook[b]).iscomic()+"\t";
result += combook[b].getsellprice()+"\n";
}
return result;
}
void execute(){
int item=0, sum=0;
double amount = 0, comcount=0, comiccount=0;
calculator calculator = new calculator();
scanner sc = new scanner(system.in);
system.out.print("請輸入購買書本的編號(1~6,-1代表結束):");
item = sc.nextint();
if(item>0){
sum += combook[item-1].getprice();
}
while(item!=-1);
system.out.print("你一共買了"+combook+"本電腦書與"+ iscomic +"漫畫書,共"+ sum +"元,");
}
}
class calculator{
double calculate(double number, double discount){
return number * discount;
}
}
public class work_1 {
/**
* @param args
*/
public static void main(string[] args) {
bookshop bookshop = new bookshop();
system.out.println(bookshop);
bookshop.execute();
}
}}