import acm.program.*;
import acm.util.*;
public class Order {
public int ocode;
public String cname ;
public String cphone ;
public double price ;
public double discount ;
public int delay;
double finalprice ;
public Order (int ocode, Item aItems, String cname, String cphone, String odate) {
this.cname= cname;
this.cphone= cphone;
this.odate= odate;
this.ocode = ocode;
price = aItems.getPrice() ;
if (aItems instanceof Peripherals){
discount = price*0.25 ;
}
else if (aItems instanceof Hardware){
discount = price * 0.3 ;
}
finalprice = price - discount ;
delay = rgen.nextInt(1,40) ;
}
RandomGenerator rgen= RandomGenerator.getInstance() ;
public Item getItem() {
return aItems;
}
public String getCname() {
return cname;
}
public String getCphone () {
return cphone;
}
public String getOdate () {
return odate;
}
public void print() {
if(aItems instanceof Monitor){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered Monitor: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " and your order will delay " +delay + " days" );
}
if(aItems instanceof Mouse){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered Mouse: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " " + delay );
}
if(aItems instanceof Printer){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered Printer: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " " + delay );
}
if(aItems instanceof Keyboard){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered Keyboard: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " " + delay );
}
if(aItems instanceof Proccesor){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered Processor: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " " + delay );
}
if(aItems instanceof Motherboard){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered Motherboard: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " " + delay );
}
if(aItems instanceof Ram){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered Ram Memory: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " " + delay );
}
if(aItems instanceof Gcard){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered Graphics card: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " " + delay );
}
if(aItems instanceof HardDrive){
println( "Order Number: " + "( " + ocode + " )" + " ,Ordered HardDrive: " + aItems + " ,Final price: " + finalprice + " ,Customer's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " " + delay );
}
}
}
当我尝试编译它时,它给了我这些错误:
Order.java:54: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red Monitor: " + aItems + " ,Final price: " + finalprice + " ,Customer's nam
e: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + "
and your order will delay " +delay + " days" );
^
symbol: method println(String)
location: class Order
Order.java:58: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red Mouse: " + aItems + " ,Final price: " + finalprice + " ,Customer's name:
" + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + " "
+ delay );
^
symbol: method println(String)
location: class Order
Order.java:62: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red Printer: " + aItems + " ,Final price: " + finalprice + " ,Customer's nam
e: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + "
" + delay );
^
symbol: method println(String)
location: class Order
Order.java:66: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red Keyboard: " + aItems + " ,Final price: " + finalprice + " ,Customer's na
me: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate + "
" + delay );
^
symbol: method println(String)
location: class Order
Order.java:70: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red Processor: " + aItems + " ,Final price: " + finalprice + " ,Customer's n
ame: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate +
" " + delay );
^
symbol: method println(String)
location: class Order
Order.java:75: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red Motherboard: " + aItems + " ,Final price: " + finalprice + " ,Customer's
name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate
+ " " + delay );
^
symbol: method println(String)
location: class Order
Order.java:80: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red Ram Memory: " + aItems + " ,Final price: " + finalprice + " ,Customer's
name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate +
" " + delay );
^
symbol: method println(String)
location: class Order
Order.java:84: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red Graphics card: " + aItems + " ,Final price: " + finalprice + " ,Customer
's name: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odat
e + " " + delay );
^
symbol: method println(String)
location: class Order
Order.java:89: error: cannot find symbol
println( "Order Number: " + "( " + ocode + " )" + " ,Orde
red HardDrive: " + aItems + " ,Final price: " + finalprice + " ,Customer's n
ame: " + cname + " ,Customers phone: " + cphone + " ,Date of order: " + odate +
" " + delay );
^
symbol: method println(String)
location: class Order
9 errors
那是什么? javac不明白这些是字符串吗?如果现在,为什么?
请帮我编译这个东西。类主要由主类调用,它创建了表示在线商店订单的类顺序对象。
答案 0 :(得分:1)
尝试使用System.out.println()而不是println()
答案 1 :(得分:0)
如果acm
,方法println
是IOModel
接口的一部分。因此,除非您的类实现此接口,否则您无法使用它 - 您只是尝试从继承自Object
的类中调用它。显然,Object
类本身没有这样的方法。但是,如果您将Order
类放在继承自acm.program.Program
或acm.program.ConsoleProgram
的某个类中,则可以使用它。
答案 2 :(得分:0)
我会像这样写
System.out.println( "Order Number: " + "( " + ocode + " )"
+ " ,Ordered " + aItems.getClass().getSimpleName()
+ ": " + aItems
+ " ,Final price: " + finalprice
+ " ,Customer's name: " + cname
+ " ,Customers phone: " + cphone
+ " ,Date of order: " + odate
+ " and your order will delay " +delay + " days" );
这样可以节省每种类型物品的println。