// ------ Animal.java --------------
// This is Animal abstract class which defines default behavior of methods.
public abstract class Animal {
public void speak() {
System.out.println("This animal speaks.");
}
public void move() {
System.out.println("This animal moves forward.");
}
}
// ----------- Flying.java -------------
// This is declaration of flying behavior.
public interface Flying {
void fly();
}
// -------- Lynx.java -----------
// This Lynx extends behaviors of animal and override them.
public class Lynx extends Animal {
public Lynx() {
}
public void speak() {
System.out.println("Lynx speaks.");
}
public void move() {
System.out.println("Lynx moves forward.");
}
}
//------------ Goose.java --------------
// This Goose is extended version of animal and it implements Flying behavior.
public class Goose extends Animal implements Flying {
public Goose() {
}
public void speak() {
System.out.println("Goose speaks.");
}
public void move() {
System.out.println("Goose moves forward.");
}
@Override
public void fly() {
System.out.println(getClass().getSimpleName() + " wings flapping.");
}
}
// --------- Airplane.java ---------
// This implements flying behavior.
public class Airplane implements Flying {
public Airplane() {
}
@Override
public void fly() {
System.out.println(getClass().getSimpleName() + " engines running.");
}
}
//---------- DemoApplication.java --------------
// This class demonstrates the object creation and assignment.
public class DemoApplication {
public static void main(String[] args) {
Animal animal1 = new Goose();
animal1.speak();
Animal animal2 = new Lynx();
animal2.speak();
Flying flyingObject1 = new Goose();
flyingObject1.fly();
Flying flyingObject2 = new Airplane();
flyingObject2.fly();
}
}
// -------------- Output -------------------
Goose speaks.
Lynx speaks.
Goose wings flapping.
Airplane engines running.
Abstract Classes and Interfaces. Write the code for all the necessary classes and/or interfaces for a...
Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and interfaces. 11. Consider the following declarations. public interface Shape{ int someFunction(Shape other); //other functions not shown } public class Square implements Shape {/*implementation not shown*/} Which of the following function headings of someFunction must be added to the declaration of the Square class such that it will satisfy the Shape interface? public int someFunction (Shape other) public int someFunction (Square other) public boolean someFunction(Object...
I need some help i need to do this in C# Objectives: • Create an application that uses a dictionary collection to store information about an object. • Understanding of abstract classes and how to use them • Utilize override with an abstract class • Understanding of Interfaces and how to use them • Implement an Interface to create a “contract” between classes. • Compare and contrast inheritance and interfaces. Instructions: Interface: Create an interface called ITrainable which contains the...
IN C# Objectives: Create an application that uses a dictionary collection to store information about an object. Understanding of abstract classes and how to use them Utilize override with an abstract class Understanding of Interfaces and how to use them Implement an Interface to create a “contract” between classes. Compare and contrast inheritance and interfaces. Instructions: Interface: Create an interface called ITrainable which contains the following: Dictionary<string, string> Behaviors{ get; set; } string Perform(String signal); string Train(String signal, string behavior);...
In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an abstract class that will be the base class for other two classes. It should have: A...
Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and interfaces. 11. Consider the following declarations. public interface Shape{ int someFunction(Shape other); //other functions not shown } public class Square implements Shape {/*implementation not shown*/} Which of the following function headings of someFunction must be added to the declaration of the Square class such that it will satisfy the Shape interface? public int someFunction (Shape other) public int someFunction (Square other) public boolean someFunction(Object...
Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...
JAVA CODING: (14 points) Abstract Class exercise You are given two abstract classes with no abstract method in the NoGo.java file. The purpose of this exercise is to get familiar with abstract class and its object creation 4. Follow the steps below: (be sure common on each to score points) 1) 2) 3 points) Create a subclass Go1 with Nogo1 as its super class and create Go1() constructor 3) (2 points) Now inside the NoGo class create an instance of...
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...
C++ Programming Assignment S Mammal Lab This lab's goal is to give you some practice using inheritance, virtual functions, pointers, dynamic memory allocation, random numbers, and polymorphism. To complete the lab implement the following steps: Create a class called Mammal. All mammals have a weight and a name, so its data should be the mammal's weight and name. Provide a default constructor that sets the mammal's weight to 0 and name to null, and another constructor that allows the weight...