I am a newbie at java and I’m attempting to do a program to introduce myself.
Beneath is my script.
class Description
{
// Occasion variable
non-public String identify, nationwide, dob;
non-public ArrayList<String> hobbies = new ArrayList<String>();
public Description()
{
}
// Different Constructor
public Description(String identify, String nationwide, String dob)
{
this.identify = identify;
this.nationwide = nationwide;
this.dob = dob;
}
// Copy Constructor
// Accessor Methodology
non-public String getname()
{
return identify;
}
non-public String getnational()
{
return nationwide;
}
non-public String getdob()
{
return dob;
}
non-public ArrayList geHobbies(){
return hobbies;
}
// Mutator Methodology
public void setHobbies(ArrayList hobbies)
{
this.hobbies = hobbies;
}
public void printInfo()
{
System.out.println("My Data");
System.out.printf("Identify: %spercentn", getname());
System.out.printf("Nationwide: %spercentn", getnational());
System.out.printf("Date of beginning: %spercentn", getdob());
System.out.printf("I've %d hobbies %n", hobbies.dimension());
System.out.printf(" 1: %spercentn", hobbies.get(0));
System.out.printf(" 2: %spercentn", hobbies.get(1));
}
}
class Lab_1
{
public static void important (String [] args)
{
Description ds = new Description("Ron ", "Singapore", "01-01-2020");
ArrayList <Description> hobbies = new ArrayList <Description> ();
hobbies.add("Finding out");
hobbies.add("Coding");
ds.printInfo();
}
}
Nevertheless I obtained “error: incompatible varieties: String can’t be transformed to Description” after I tried to run the script. Can any knowledgeable on the market information me on how I can resolve this difficulty. Thanks! I’m additionally required to create one other arraylist name needs, and embody four needs. whereas I am nonetheless caught at hobbies, I am unable to proceed and work on the opposite arraylist.