接口的使用 Java PTA

这种错误怎么改呀

img

下面是代码

public interface ComputeWeight{
  double ComputeWeight();
}
public class ComputeWeight implements Television
{
    double w1;
    Television(double w1)
    {
        super();
        this.w1 = w1;
    }
    return double w1;
} 
public class ComputeWeight implements AirConditioner
{
    double w2;
    AirConditioner(double w2)
    {
        super();
        this.w2 = w2;
    }
    return w2;
} 
public class ComputeWeight implements WashMachine
{
   double w3;
    WashMachine(double w3)
    {      
        super();
        this.w3 = w3;  
    }
    return w3;
} 
public class Truck {
  private ComputeWeight goods[];
   Truck(ComputerWeight[] goods) 
   {
        super();
        this.goods = goods;
    }
 public double getTotalWeight()
  {
     double sum = 0;
     for (i = 0;i<goods.length ;i++)
     {
     type=input.nextInt();                
            if (type==1)                                
               sum = sum +16.6;
            else if (type==2)
                sum = sum + 40.0;
            else if (type==3)
                sum = sum +60.0;
     }
     return sum;
   }  
 }


构造方法 要和 当前类 同名, 你都是 和 父类或接口同名 ,这是错误的

img

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这个问题的回答你可以参考下: https://ask.csdn.net/questions/7670557
  • 你也可以参考下这篇文章:【Java PTA作业】当老师一口气布置八个作业( 8 / 8 )
  • 除此之外, 这篇博客: 沈师 Java程序设计 PTA 编程题答案中的 58. 伪随机数 (10 分) 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    在java.util这个包里面提供了一个Random的类,我们可以新建一个Random的对象来产生随机数,他可以产生随机整数、随机float、随机double,随机long。Random的对象有两种构建方式:带种子和不带种子。不带种子的方式将会返回随机的数字,每次运行结果不一样。无论程序运行多少次,带种子方式构建的Random对象会返回一样的结果。
    请编写程序,使用第一种方式构建Random对象,并完成下面输入输出要求。
    输入格式:
    在一行中输入3个不超过10000的正整数n,m,k。
    输出格式:
    在一行中输出以k为种子建立的Random对象产生的第n个0到m-1之间的伪随机数。
    输入样例:
    10 100 1000
    输出样例:
    50
    答案:

    
    import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int m = sc.nextInt();
            int k = sc.nextInt();
            List<Integer> ss = new ArrayList<Integer>();
            //Set<Integer> ss = new HashSet<Integer>();
            Random rand = new Random(k);
            for(int i = 0;i < n;i++)
            {
            	ss.add(rand.nextInt(m));
            	if(i==n-1)
            		System.out.println(ss.get(i));
            }
            
    	}
     
    }
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^