Welcome to Dream.In.Code
Become a Java Expert!

Join 150,131 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,119 people online right now. Registration is fast and FREE... Join Now!




DATA STRUCTURE

 
Reply to this topicStart new topic

DATA STRUCTURE, LAB 4

redzuan
2 Aug, 2008 - 09:36 AM
Post #1

New D.I.C Head
*

Joined: 21 Jul, 2008
Posts: 47


My Contributions
Hye again this my new assignment for data struc. Lets have fun with it.Attached File  Lab_4.doc ( 60k ) Number of downloads: 11

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: DATA STRUCTURE
2 Aug, 2008 - 09:46 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
We have a site policy that states a person must show their "best effort" attempt at solving the problem themselves. We can then jump in where you are stuck and help pull you through. And please, don't just paste your skeleton code there, actually try to code up the cat or dog class and we can then help you out from there.

This assignment is pretty straight forward if you know about inheritance. Thanks for helping us help you! smile.gif
User is offlineProfile CardPM
+Quote Post

vik09
RE: DATA STRUCTURE
3 Aug, 2008 - 07:16 AM
Post #3

New D.I.C Head
*

Joined: 8 Jul, 2008
Posts: 32


My Contributions
@redzuan
Just out of curiosity, how old are you and what class are you in?
User is offlineProfile CardPM
+Quote Post

lordms12
RE: DATA STRUCTURE
3 Aug, 2008 - 10:45 AM
Post #4

D.I.C Regular
Group Icon

Joined: 16 Feb, 2008
Posts: 322



Thanked: 17 times
Dream Kudos: 225
My Contributions
Please do not attach files, it is easier for most to check your question here rather than downloading your assignment files.

This post has been edited by lordms12: 3 Aug, 2008 - 10:36 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: DATA STRUCTURE
3 Aug, 2008 - 10:47 AM
Post #5

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Attaching files are ok as long as they are relevant to your question (and try to make them something like PDF in the future). Just be sure to actually post some code you are using to accomplish the goals set out on your attachment. smile.gif
User is offlineProfile CardPM
+Quote Post

pbl
RE: DATA STRUCTURE
3 Aug, 2008 - 12:28 PM
Post #6

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(redzuan @ 2 Aug, 2008 - 10:36 AM) *

Hye again this my new assignment for data struc. Lets have fun with it.Attached File  Lab_4.doc ( 60k ) Number of downloads: 11


Why don't you try to have fun yourself ?

User is offlineProfile CardPM
+Quote Post

lordms12
RE: DATA STRUCTURE
3 Aug, 2008 - 02:19 PM
Post #7

D.I.C Regular
Group Icon

Joined: 16 Feb, 2008
Posts: 322



Thanked: 17 times
Dream Kudos: 225
My Contributions
QUOTE(Martyr2 @ 3 Aug, 2008 - 11:47 AM) *

Attaching files are ok as long as they are relevant to your question (and try to make them something like PDF in the future). Just be sure to actually post some code you are using to accomplish the goals set out on your attachment. smile.gif

ya, but it just extra work for no need to download the file then open and wasting some time waiting reader to open
User is offlineProfile CardPM
+Quote Post

redzuan
RE: DATA STRUCTURE
3 Aug, 2008 - 08:32 PM
Post #8

New D.I.C Head
*

Joined: 21 Jul, 2008
Posts: 47


My Contributions
QUOTE(lordms12 @ 3 Aug, 2008 - 03:19 PM) *

QUOTE(Martyr2 @ 3 Aug, 2008 - 11:47 AM) *

Attaching files are ok as long as they are relevant to your question (and try to make them something like PDF in the future). Just be sure to actually post some code you are using to accomplish the goals set out on your attachment. smile.gif

ya, but it just extra work for no need to download the file then open and wasting some time waiting reader to open

relax man...if u don't want so don't open it...actually i'm still working with the assignment...as soon i finish it i will post it....duuhh~...i just only show the question..is there a problem man?...

QUOTE(vik09 @ 3 Aug, 2008 - 08:16 AM) *

@redzuan
Just out of curiosity, how old are you and what class are you in?

haha find ur self

QUOTE(pbl @ 3 Aug, 2008 - 01:28 PM) *

QUOTE(redzuan @ 2 Aug, 2008 - 10:36 AM) *

Hye again this my new assignment for data struc. Lets have fun with it.Attached File  Lab_4.doc ( 60k ) Number of downloads: 11


Why don't you try to have fun yourself ?


yeah still working....once finish i post it
User is offlineProfile CardPM
+Quote Post

lordms12
RE: DATA STRUCTURE
3 Aug, 2008 - 10:31 PM
Post #9

D.I.C Regular
Group Icon

Joined: 16 Feb, 2008
Posts: 322



Thanked: 17 times
Dream Kudos: 225
My Contributions
QUOTE(redzuan @ 3 Aug, 2008 - 09:32 PM) *

QUOTE(lordms12 @ 3 Aug, 2008 - 03:19 PM) *

QUOTE(Martyr2 @ 3 Aug, 2008 - 11:47 AM) *

Attaching files are ok as long as they are relevant to your question (and try to make them something like PDF in the future). Just be sure to actually post some code you are using to accomplish the goals set out on your attachment. smile.gif

ya, but it just extra work for no need to download the file then open and wasting some time waiting reader to open

relax man...if u don't want so don't open it...actually i'm still working with the assignment...as soon i finish it i will post it....duuhh~...i just only show the question..is there a problem man?...

No Comment!!! huh.gif

This post has been edited by lordms12: 5 Aug, 2008 - 05:31 AM
User is offlineProfile CardPM
+Quote Post

redzuan
RE: DATA STRUCTURE
6 Aug, 2008 - 04:57 AM
Post #10

New D.I.C Head
*

Joined: 21 Jul, 2008
Posts: 47


My Contributions
here is my answer
CODE

import java.util.*;
/**
*
* @author Mohd Redzuan Omar
*/
public class Main
{
    //outputs a description of the animal followed by
    //"Speak!" and the sound the animal makes
    

    public static void announce(Animal a)
    {
        System.out.println(a.toString() + a.sound());
    }
    
    //change the name of animal
    public static void changeName(Animal a, String name)
    {
        
        String changeName = name;
      
      if(a instanceof Cat )
      {
          ((Cat)a).setName(changeName);
          System.out.println(((Cat)a).toString());
      }else
      {
          ((Dog)a).setName(changeName);
          System.out.println(((Dog)a).toString());
      }
            
    }
    
    public static void main(String[] args) {
        Dog myDog =new Dog("dog","Murphy","Poodle ");
        Cat myCat = new Cat("cat","Debbie","Siamese ");
        
        //create output statements that describe the objects
        System.out.println(myDog.toString());
        System.out.println(myCat.toString());
        
        
        
        //call announce() with the myDog and myCat
        announce(myDog);
        announce(myCat);
        
        //change the names for the dog and cat
        changeName(myDog, "Murph");
        changeName(myCat, "DB");
        
        //create output statements that describe newly named
        //objects
        
      
        
        
        
    }

}
public abstract class Animal {

    protected String animalType;
    
    public Animal()
    {
        
    }
    
    public Animal(String type)
    {
        animalType = type;
    }
    
    public String toString()
    {
        return animalType;
    }
    
    public abstract String sound();
    
        
    
}

public class Cat extends Animal{
    private String name;
    private String breed;
    
    public Cat()
    {
        
    }
    
    public Cat(String type, String catName, String catBreed)
    {
        super(type);
        name = catName;
        breed = catBreed;
    }
    
    public void setName(String catName)
    {
        
    }
    
    public String toString()
    {
        return "A "+super.toString()+" , "+name+" the "+breed;
    }
    
    public String sound()
    {
        return"Speak! meow meow";
    }
}
public class Dog extends Animal {

    private String name;
    private String breed;
    public Dog()
    {
        
    }
    public Dog (String type, String dogName, String dogBreed)
    {
        super(type);
        name = dogName;
        breed = dogBreed;
    }
    
    public void setName(String dogName)
    {
        name = dogName;
    }
    
    public String toString()
    {
        
        return "A "+super.toString()+" , "+name+" the "+breed;
    }
    
    public String sound()
    {
        return"Speak! woof woof";
    }
    
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:45AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month