Click here to Skip to main content
15,910,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

Java
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);
   }
  }


}
Posted
Updated 24-Jul-16 21:21pm
v3
Comments
Patrice T 24-Jul-16 16:20pm    
Plan to tell us which error messages and where ?
or we have to guess ?
Priyanshu Patel 24-Jul-16 16:24pm    
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
Patrice T 24-Jul-16 16:34pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

Here is a few bugs corrections:
Java
for(int i=0; i<n;>i++)   {
  arr[i]=n.nextLine();
}

You void function returns something!
Java
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:
Java
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.
 
Share this answer
 
v4
Comments
Priyanshu Patel 24-Jul-16 16:47pm    
Hi, I really appreciate your prompt response, I am really new to java so I am having more problems with this.
Priyanshu Patel 24-Jul-16 16:53pm    
I wanted to print user input which is stored in an array.
I strongly suggest you go to The Java Tutorials[^] and spend some time learning the language and most used classes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900