一上来见到这些回复,谢谢大家了,不过还是有问题
以下是改过后仍然出错的程序,为什么,是不是因为数组类型的问题?
interface ComputeTotalSales
{
public double totalSalesByYear();
}
class Television implements ComputeTotalSales
{
double a;
Television(double a)
{
this.a=a;
a=155555.22;
}
public double totalSalesByYear()
{
System.out.println("电视机的年销售额:%f"+a);
return a;
}
}
class Computer implements ComputeTotalSales
{
double b;
Computer(double b)
{
this.b=b;
b=255555.22;
}
public double totalSalesByYear()
{
System.out.println("计算机的年销售额:%f"+b);
return b;
}
}
class Mobile implements ComputeTotalSales
{
double c;
Mobile(double c)
{
this.c=c;
c=355555.22;
}
public double totalSalesByYear()
{
System.out.println("移动电话的年销售额:"+c);
return c;
}
}
class Shop
{
Shop()
{
ComputeTotalSales[] cts=new ComputeTotalSales[3];
cts[0]=new Television(double a);//需要 ".class" 需要 ';'
cts[1]=new Computer(double b);//需要 ".class" 需要 ';'
cts[2]=new Mobile(double c);//需要 ".class" 需要 ';'
}
double sales(double d)
{
double d=0;
int i;
for(i=0;i<3;i++)
{
d=d+cts[i].totalSalesByYear();
}
System.out.println("总年销售额:%f"+d);
return d;
}
}
public class Salesperyear
{
public static void main (String args[])
{
Shop shop=new Shop();
shop.sales(double d);//需要 ".class" 需要 ';'
}
}
以下是改过后仍然出错的程序,为什么,是不是因为数组类型的问题?
interface ComputeTotalSales
{
public double totalSalesByYear();
}
class Television implements ComputeTotalSales
{
double a;
Television(double a)
{
this.a=a;
a=155555.22;
}
public double totalSalesByYear()
{
System.out.println("电视机的年销售额:%f"+a);
return a;
}
}
class Computer implements ComputeTotalSales
{
double b;
Computer(double b)
{
this.b=b;
b=255555.22;
}
public double totalSalesByYear()
{
System.out.println("计算机的年销售额:%f"+b);
return b;
}
}
class Mobile implements ComputeTotalSales
{
double c;
Mobile(double c)
{
this.c=c;
c=355555.22;
}
public double totalSalesByYear()
{
System.out.println("移动电话的年销售额:"+c);
return c;
}
}
class Shop
{
Shop()
{
ComputeTotalSales[] cts=new ComputeTotalSales[3];
cts[0]=new Television(double a);//需要 ".class" 需要 ';'
cts[1]=new Computer(double b);//需要 ".class" 需要 ';'
cts[2]=new Mobile(double c);//需要 ".class" 需要 ';'
}
double sales(double d)
{
double d=0;
int i;
for(i=0;i<3;i++)
{
d=d+cts[i].totalSalesByYear();
}
System.out.println("总年销售额:%f"+d);
return d;
}
}
public class Salesperyear
{
public static void main (String args[])
{
Shop shop=new Shop();
shop.sales(double d);//需要 ".class" 需要 ';'
}
}
[此贴子已经被作者于2007-10-18 16:42:21编辑过]