elroytiow
asked on
a simple program
Access modifier Description of some methods in the above diagram
# => protected + walk() => takes in no argument, returns no value
+ => public + getName() : String => takes in no arguments, returns a
- => private String value
+ setName( name:String) => takes in one String
argument, returns no value
Question 1 [ 40 marks ]
Based on the above diagram,
a) Create the Animal class, which is the abstract superclass of all animals.
[ 2 marks ]
i. Declare a protected integer attribute called legs, which records the number of legs for this animal. [ 2 marks ]
ii. Define a protected constructor that initializes the legs attribute
[ 2 marks ]
iii. Declare an abstract method eat. [ 2 marks ]
iv. Declare a concrete method walk that displays how the animal walks, including the number of legs. [ 3 marks ]
b) Create the Cat class that inherits from the Animal class. [ 2 marks ]
i. This class has a String attribute to store the name of the pet.
[ 2 marks ]
ii. Define a constructor that takes a String parameter that specifies the cat’s name. This constructor must also call the superclass constructor to specify that all cats have four legs. [ 4 marks ]
iii. Overload the constructor so that this constructor takes no argument, and it calls the constructor in part d(ii) and pass an empty string as the argument. [ 3 marks ]
c) Create the Fish class as specified by the UML diagram above. Override the Animal methods to specify that fish cannot walk and do not have legs.
[ 18 marks ]
Question 2 [ 60 marks ]
Write a program called MyPet that create the Cat and Fish objects and store the objects in a reference-based linked list data structure. You may create a GUI or non-GUI program. Either program will entitle you to a maximum of 15 marks. [ 15 marks ]
This program allows you to
a) create a list of Cat objects, sorted based on its name. Each cat has a unique name. [ 10 marks ]
b) create a list of Fish objects, sorted based on its name. Each fish has a unique name too. [ 5 marks ]
c) display the details of each cat and fish, including what it can do. [ 10 marks ]
d) change the name of your pets [ 10 marks ]
Additional features such as include the status of the fish, delete a dead cat or dead fish, or other functions. [ 10 marks ]
# => protected + walk() => takes in no argument, returns no value
+ => public + getName() : String => takes in no arguments, returns a
- => private String value
+ setName( name:String) => takes in one String
argument, returns no value
Question 1 [ 40 marks ]
Based on the above diagram,
a) Create the Animal class, which is the abstract superclass of all animals.
[ 2 marks ]
i. Declare a protected integer attribute called legs, which records the number of legs for this animal. [ 2 marks ]
ii. Define a protected constructor that initializes the legs attribute
[ 2 marks ]
iii. Declare an abstract method eat. [ 2 marks ]
iv. Declare a concrete method walk that displays how the animal walks, including the number of legs. [ 3 marks ]
b) Create the Cat class that inherits from the Animal class. [ 2 marks ]
i. This class has a String attribute to store the name of the pet.
[ 2 marks ]
ii. Define a constructor that takes a String parameter that specifies the cat’s name. This constructor must also call the superclass constructor to specify that all cats have four legs. [ 4 marks ]
iii. Overload the constructor so that this constructor takes no argument, and it calls the constructor in part d(ii) and pass an empty string as the argument. [ 3 marks ]
c) Create the Fish class as specified by the UML diagram above. Override the Animal methods to specify that fish cannot walk and do not have legs.
[ 18 marks ]
Question 2 [ 60 marks ]
Write a program called MyPet that create the Cat and Fish objects and store the objects in a reference-based linked list data structure. You may create a GUI or non-GUI program. Either program will entitle you to a maximum of 15 marks. [ 15 marks ]
This program allows you to
a) create a list of Cat objects, sorted based on its name. Each cat has a unique name. [ 10 marks ]
b) create a list of Fish objects, sorted based on its name. Each fish has a unique name too. [ 5 marks ]
c) display the details of each cat and fish, including what it can do. [ 10 marks ]
d) change the name of your pets [ 10 marks ]
Additional features such as include the status of the fish, delete a dead cat or dead fish, or other functions. [ 10 marks ]
>>>.it is also in the wrong TA,
The real wrong TA it is in; is the cross-posted version in Community Support ...LOL
Cd&
The real wrong TA it is in; is the cross-posted version in Community Support ...LOL
Cd&
elroytiow,
We would like to see you come up with some initial coding efforts from your own side before we start helping.
We would like to see you come up with some initial coding efforts from your own side before we start helping.
ASKER
Below are my coding
import java.io.*;
import javax.swing.*;
import java.awt.*;
class node{
private string catname;
private string fishname;
private node next;
name=catname;
name2=fisname;
public void setcatname(string catname){
catname=newname;
}
public string getcatname(){
return catname;
}
public void setfishname(string fishname){
fishname=newfishname;
}
public string getfishname(){
return fishname;
}
public void setnext(node next){
next=node next;
}
public node getnext(){
return next;
}
public interface interfaceSLList{
public void add(string catname,string fishname);
public void delete(string name);
public void search(string name);
public void printall();
public int size();
}
public class Mypet implementing interfaceSLList{
private node head;
public Mypet(){
head=null;
}
node node1=new node();
node1.setcatname("Miao");
node1.setfishname("Nemo");
}
public int size(){
if(head==null)
return 0;
node.probe==head;
int count=0;
do{
count=count +1;
probe=probe.getnext;
}while(probe != null);
return count;
}}
add newnode(){
node head=null;
node newnode=new node();
newnode.setnode();
head=newnode;
newnode.setnext(null);
}
public void printall(){
if(head==null)
{system.out.println("The list is empty");
return;}
node probe=head;
system.out.println("All item in the list are:");
do{
system.out.println("probe. getcatname ()+"is cat name"+probe.getfishname()" is fish name");
probe=probe.getnext();
}while(probe!=null);
}
public void search(string name){
if(head==null)
{system.out.println("The list is empty");
}
node.probe=head;
do{
if(probe.getname().equals( name)){
system.out.println(name+" is cat name.");
else
system.out.println(name2" is fish name.");
return;
}
probe=probe.getnext();
while(probe!=null);
system.out.println(name&&n ame2 +"is not in the list");
}
node before=head;
node after=head.getnext();
while(before.getnext()!=nu ll && after.getnext()!=null)
{
before=before.getnext();
after=after.getnext();
}
before.setnext(null);
remove();
import java.io.*;
import javax.swing.*;
import java.awt.*;
class node{
private string catname;
private string fishname;
private node next;
name=catname;
name2=fisname;
public void setcatname(string catname){
catname=newname;
}
public string getcatname(){
return catname;
}
public void setfishname(string fishname){
fishname=newfishname;
}
public string getfishname(){
return fishname;
}
public void setnext(node next){
next=node next;
}
public node getnext(){
return next;
}
public interface interfaceSLList{
public void add(string catname,string fishname);
public void delete(string name);
public void search(string name);
public void printall();
public int size();
}
public class Mypet implementing interfaceSLList{
private node head;
public Mypet(){
head=null;
}
node node1=new node();
node1.setcatname("Miao");
node1.setfishname("Nemo");
}
public int size(){
if(head==null)
return 0;
node.probe==head;
int count=0;
do{
count=count +1;
probe=probe.getnext;
}while(probe != null);
return count;
}}
add newnode(){
node head=null;
node newnode=new node();
newnode.setnode();
head=newnode;
newnode.setnext(null);
}
public void printall(){
if(head==null)
{system.out.println("The list is empty");
return;}
node probe=head;
system.out.println("All item in the list are:");
do{
system.out.println("probe.
probe=probe.getnext();
}while(probe!=null);
}
public void search(string name){
if(head==null)
{system.out.println("The list is empty");
}
node.probe=head;
do{
if(probe.getname().equals(
system.out.println(name+" is cat name.");
else
system.out.println(name2" is fish name.");
return;
}
probe=probe.getnext();
while(probe!=null);
system.out.println(name&&n
}
node before=head;
node after=head.getnext();
while(before.getnext()!=nu
{
before=before.getnext();
after=after.getnext();
}
before.setnext(null);
remove();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
elroytiow, if you do not do your own home work and learn nothing from your courses will end being unemployable.