解决我遇到的14个错误 [英] Solve the 14 errors which I came across

查看:57
本文介绍了解决我遇到的14个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求做以下6个步骤,但我遇到了错误。如果有人可以帮我这么做真的很棒。





鉴于以下界面和抽象类,创建非抽象类Chef如下:

1. Chef应继承Person类并实现Skills界面。

2. Chef构造函数应该取两个String参数并设置超类实例变量。

3.重写toString方法以返回字符串我是厨师。

4. printInfo方法应该打印名字和姓氏,后跟调用Chef类的toString方法的结果。您的输出格式应与样本输出格式完全匹配。

5. createSkills方法应创建一个大小为n的String数组,提示用户输入每项技能并读入输入的值。该方法应返回一个String数组,其中包含用户输入的所有技能。您可以假设已创建Scanner对象(请参阅第一页上的说明)。您的输出格式应与样本输出格式完全匹配。

6. printSkills方法应打印出我的技能为:,并且数组参数的每个元素都在其自己的行上。您的输出格式应与样本输出格式完全匹配。



嗯,这些是错误



< pre lang =text> ---- jGRASP exec:javac -g Chef.java
Chef.java:1:错误:Chef不是抽象的,并且不会覆盖技能中的抽象方法printSkills(String [])
公共类Chef扩展Person实现技能
^
Chef.java:8:错误:在超类型构造函数被调用之前无法引用
super(first);
^
Chef.java:8:错误:构造函数类Person中的Person不能应用于给定的类型;
super(第一个);
^
required:String,String
found:String
reason:实际和形式参数列表长度不同
Chef.java:9:错误:调用super必须是构造函数中的第一个语句
super(last);
^
Chef.java:22:错误:无法从静态上下文引用非静态方法toString()
Chef.toString();
^
Chef.java:27:错误:找不到符号
扫描仪读卡器=新扫描仪(System.in);
^
符号:类扫描仪
位置:类厨师
Chef.java:27:错误:找不到符号
扫描仪读卡器=新扫描仪(System.in) ;
^
符号:class Scanner
location:class Chef
Chef.java:29:错误:变量n已在方法createSkills(String [])中定义
String n = reader.nextLine();
^
Chef.java:30:错误:不兼容类型:意外返回值
return(n);
^
Chef.java:30:错误:不兼容的类型:字符串无法转换为void
return(n);

Chef.java:35:错误:找不到符号
String arr [] = new String [n];
^
符号:变量n
位置:类厨师
Chef.java:36:错误:找不到符号
for(int i = 0; i< n ; i ++)=^ =符号:=变量=n =location:=class =chef =chef.java:38:=错误:=不能=find =symbol =arr [i] =n.nextLine(); chef.java:40:=incompatible =types:=string =be =converted =to =int =for(int =i:=arr )=14 =错误< =div => < div id =EditDialogPlaceholder>< / div> < div id =ReplyDialogPlaceholder>< / div>< / n;>





我的尝试:



  public   class  Chef  extends  Person  implements 技能
{
private 首先字符串;
private String last;

public Chef( String f,字符串 l)
{
super (第一个);
super (last);
}

@覆盖
public String toString()
{
String str = 我是厨师;
return (str);
}

public void printInfo()
{
super .toString();
Chef.toString();
}

public void createSkills( String [] n)
{
Scanner reader = new Scanner(System.in);
System.out.println( 输入你的技能:);
String n = reader.nextLine();
return (n);
}

public void printSkills()
{
String arr [] = new String [n];
for int i = 0; i< n;> {
arr [i] = n.nextLine();
}
for int i:arr)
{
System.out.println(i);
}
}


}

解决方案

这里有一些错误更正:

  for  int  i = 0; i< n;>  i ++) {
arr [ i] = n.nextLine();
}



你的void函数返回一些东西!

  public   void  createSkills( String  [] n)
{
Scanner reader = new Scanner(System.in);
System.out.println( 输入您的滑雪ll:);
String n = reader.nextLine();
return (n);
}



你自己无法纠正这个问题。



这里我甚至不明白你的意图:

  for  int  i:arr)
{
System.out。的println(ⅰ);
}





只是想知道,你知道Java语法的基础吗?。



[更新]

建议:暂时忘掉你的项目。

认真学习Java,阅读语言文档,关注tutos,don跳过步骤。


我强烈建议你去 Java教程 [ ^ ]并花一些时间学习语言和最常用的类。


I was asked to do the following 6 steps but I am running into errors. It would be really great if someone can help me along with this.


Given the below interface and abstract class, create the non-abstract class Chef as follows:
1. Chef should inherit from the Person class and implement the Skills interface.
2. The Chef constructor should take two String parameters and set the superclass instance variables.
3. Override the toString method to return the String "I am a Chef".
4. The printInfo method should print the first and last names, followed by the result from calling the toString method of the Chef class. Your output format should match the sample output format exactly.
5. The createSkills method should create a String array of size n, prompt the user to enter each of the skills and read in the values entered. The method should return a String array that contains all the skills entered by the user. You can assume that the Scanner object has been created (see instructions on first page). Your output format should match the sample output format exactly.
6. The printSkills method should print out "My skills are: " with each element of the array parameter on its own line. Your output format should match the sample output format exactly.

Well, these are the errors

----jGRASP exec: javac -g Chef.java
 Chef.java:1: error: Chef is not abstract and does not override abstract                        method printSkills(String[]) in Skills
public class Chef extends Person implements Skills
  ^
Chef.java:8: error: cannot reference first before supertype constructor has        been called
 super(first);
       ^
 Chef.java:8: error: constructor Person in class Person cannot be applied   to given types;
 super(first);
 ^
required: String,String
found: String
reason: actual and formal argument lists differ in length
Chef.java:9: error: call to super must be first statement in constructor
 super(last);
      ^
Chef.java:22: error: non-static method toString() cannot be referenced from    a static context
 Chef.toString();
    ^
Chef.java:27: error: cannot find symbol
 Scanner reader = new Scanner(System.in);
 ^
symbol:   class Scanner
location: class Chef
Chef.java:27: error: cannot find symbol
 Scanner reader = new Scanner(System.in);
                      ^
symbol:   class Scanner
location: class Chef
Chef.java:29: error: variable n is already defined in method          createSkills(String[])
 String n = reader.nextLine();
        ^
 Chef.java:30: error: incompatible types: unexpected return value
 return(n);
       ^
Chef.java:30: error: incompatible types: String cannot be converted to void
 return(n);

Chef.java:35: error: cannot find symbol
  String arr[]=new String[n];
                          ^
 symbol:   variable n
 location: class Chef
 Chef.java:36: error: cannot find symbol
  for(int i=0; i<n; i++)="" ^="" symbol:="" variable="" n="" location:="" class="" chef="" chef.java:38:="" error:="" cannot="" find="" symbol="" arr[i]="n.nextLine();" chef.java:40:="" incompatible="" types:="" string="" be="" converted="" to="" int="" for(int="" i:="" arr)="" 14="" errors<="" div="">   <div id="EditDialogPlaceholder"></div>  <div id="ReplyDialogPlaceholder"></div></n;>



What I have tried:

public class Chef extends Person implements Skills
{
private String first;
private String last;

public Chef(String f, String l)
{
  super(first);
  super(last);
}

@Override
public String toString()
{
  String str="I am a Chef";
  return(str);
}

public void printInfo()
{
 super.toString();
 Chef.toString();
}

public void createSkills(String[] n)
{
  Scanner reader = new Scanner(System.in);
  System.out.println("Enter your Skill: ");
  String n = reader.nextLine();
  return(n);
 }

 public void printSkills()
 {
   String arr[]=new String[n];
   for(int i=0; i<n;>   {
     arr[i]=n.nextLine();
   }
   for(int i: arr)
   { 
    System.out.println(i);
   }
  }


}

解决方案

Here is a few bugs corrections:

for(int i=0; i<n;>i++)   {
  arr[i]=n.nextLine();
}


You void function returns something!

public void createSkills(String[] n)
{
  Scanner reader = new Scanner(System.in);
  System.out.println("Enter your Skill: ");
  String n = reader.nextLine();
  return(n);
 }


you were unable to correct this yourself.

Here I don't even understand what is your intend:

for(int i: arr)
{
 System.out.println(i);
}



Just wondering, do you know the basics of Java syntax ?.

[Update]
Advice: Forget your project for now.
Learn Java seriously, read language documentation, follow tutos, don't skip steps.


I strongly suggest you go to The Java Tutorials[^] and spend some time learning the language and most used classes.


这篇关于解决我遇到的14个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆