use the animal examples and recreate your animal project you created for the Polymorphism project and use interfaces instead of classes.
=============================================================================
public class Animal {
public void makeSound(){
System.out.println("“The animal is making a sound...”.");
}
}
=============================================================================
public class Horse extends Animal {
@Override
public void makeSound() {
System.out.println(" “Whinny”, “Neigh”or “Hi, I’m Mr. Ed.”");
}
}
=============================================================================
public class Cow extends Animal {
@Override
public void makeSound() {
System.out.println(" “BoWow”, BoWoW, Cow Cow");
}
}
=============================================================================
public class Dog extends Animal {
@Override
public void makeSound() {
System.out.println("Bark Bark !! !! Bark");
}
}
=============================================================================
public class Hen extends Animal {
@Override
public void makeSound() {
System.out.println("Chirp!Chirp!!Chirp!!! Hen");
}
}
=============================================================================
public class AnimalWorld {
public static void main(String[] args) {
Animal horse = new Horse();
Animal dog = new Dog();
Animal cow = new Cow();
Animal hen = new Hen();
System.out.print("Horse sounds:");
horse.makeSound();
System.out.print("Dog sounds:");
dog.makeSound();
System.out.print("Cow sounds:");
cow.makeSound();
System.out.print("Hen sounds:");
hen.makeSound();
}
}public class Animal {
public void makeSound(){
System.out.println("“The animal is making a sound...”.");
}
}
=============================================================================
public class Horse extends Animal {
@Override
public void makeSound() {
System.out.println(" “Whinny”, “Neigh”or “Hi, I’m Mr.
Ed.”");
}
}
=============================================================================
public class Cow extends Animal {
@Override
public void makeSound() {
System.out.println(" “BoWow”, BoWoW, Cow Cow");
}
}
=============================================================================
public class Dog extends Animal {
@Override
public void makeSound() {
System.out.println("Bark Bark !! !! Bark");
}
}
=============================================================================
public class Hen extends Animal {
@Override
public void makeSound() {
System.out.println("Chirp!Chirp!!Chirp!!! Hen");
}
}
=============================================================================
public class AnimalWorld {
public static void main(String[] args) {
Animal horse = new Horse();
Animal dog = new Dog();
Animal cow = new Cow();
Animal hen = new Hen();
System.out.print("Horse sounds:");
horse.makeSound();
System.out.print("Dog sounds:");
dog.makeSound();
System.out.print("Cow sounds:");
cow.makeSound();
System.out.print("Hen sounds:");
hen.makeSound();
}
}
use the animal examples and recreate your animal project you created for the Polymorphism project and...
Examples: Example 1-Runtime Polymorphism: Lets say we have a class Animal that has a method sound(). Since this is a generic class so we can't give it a implementation like: Roar, Meow, Oink etc. We had to give a generic message public class Animal public void sound System.out.println("Animal is making a sound"); Now lets say we a subclass of Animal class. Horse that extends Animal class. We can provide the implementation to the same method like this: class Horse extends...
What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...
******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...
Java:Netbeans-Use the LinkedList class to simulate a queue, and use the add method to simulate the enqueue, and the remove method to simulate the dequeue method for a Queue. Remember to use FIFO. Need help with 0. Add New Microchips pushMicroChip(), popMicroChip() and . To simulate this, you will create a menu option 0, which will generate 100 microchip long objects, and place them into a stack of microchips. Those microchip objects will be generated by using the System.nanotime() method. ...
Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...
Create a program called GeneralizedBubbleSort that will make use of the Comparable Interface in the same way it is used in the GeneralizedSelectionSort. You should use the attached ComparableDemo to test your program. public class ComparableDemo { public static void main(String[] args) { Double[] d = new Double[10]; for (int i = 0; i < d.length; i++) d[i] = new Double(d.length - i); System.out.println("Before sorting:"); int i; for (i = 0; i < d.length; i++) System.out.print(d[i].doubleValue( ) + ", ");...
Can you fix my error? I created a program that changes labels every second in Java. But, it does not change. And, it will starts with second label. This is also an error. import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; public class Map2 extends JFrame{ JPanel panel; JLabel pic; Timer tm; int x = 0; String ly = "<html> " + "<br> <font size='10' color='red'> <b> 111111111 <b/> </font>...
I have this java program that I need to add an abstract method and polymorphism to it : import java.util.Scanner; //class and encapsulation class BookTheTicket { private String movieName; private String theatreName; private int ticketCost; void myAllmovies() { System.out.println("-------Listing the movies:------"); System.out.println(" 1.DDLJ ------------ $40 \n 2.kkr---------$.50 \n 3.game-movie --------$60 \n 4.fun movie ----- $.70 "); } } // inheritence class theater extends BookTheTicket{ private int numOfTickets; void theater() { System.out.println("*******Listing the theatre:******* \n 1.coco cola tld \n 2.koi gandhi...
I have a java project that I need help trying to finish. I have most of it completed but the issue I am running into is adding numbers with different lengths. Project requirements: . Use a Stack ADT with the implementation of your choice (Array or Link), it should not make a difference 2.Read two “integer” numbers from the user. Hint: You don’t need to use an int type when you read, it may be easier to parse the input...