问题描述
我一直在从事这个项目,所以我知道如何使用自定义对象和自定义对象类型。我遇到的问题是当我写出System.out.println(fe1.TestAuto);时。它说应该是标识符,但我不知道为什么。我试图打印出该对象,但是它不起作用。我遇到的另一个问题是,当我想使用DiscountValue()方法提供成本折扣时,它说不能将double转换为Feature,我也不知道为什么。
DiscountValue()方法从double c中接受输入,然后在Feature Class中用double d减去输入。
下面是我的代码。有人可以帮我吗。
public class Auto
{
public String name;
public double size;
public Auto(String s,double sz){
name = s;
size = sz;
}
//step 2: method showFeature()
public Feature showFeature(Feature f){
System.out.println("The feature " +f+" costs: "+f.cost);
}
public Feature discountValue(String s,double c,double d){
//Step 3: method to give discount on cost
double z = c - d.cost;
return z;
}
}
public class TestAuto
{
public static void main(String args[]){
//instantiate an Auto object
Auto at = new Auto("AMG",73.5);
//instantiate a Feature object
Feature fe = new Feature("Leather Seat",3000);
//execute method addFeature with Feature object
at.showFeature(fe);
//prepare a new Feature object for receving information
Feature fe1 = new Feature("",0);
//Run method discountValue with a feature and a new value
fe1 = at.discountValue("GPS",15000,0.2);
//print out the object
System.out.println(fe1);
}
}
public class Feature
{
public String name;
public double cost;
public Feature(String s,double d){
//step 1
name = s;
cost = d;
}
//step 4
System.out.println(fe1.TestAuto);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)