Create a Java application of your choice that includes or uses at least 4 classe
ID: 3816478 • Letter: C
Question
Create a Java application of your choice that includes or uses at least 4 classes: one of your main (and any other) method(s). Your program must meet the following: 1. It compiles, runs without errors. 2. The main () method is packaged in its own separate class and drives the application. It should call all of the methods of your extended class. All user interaction should be done in the driver class. 3. Define a base class (may be abstract), then define a class that extends that base class (is a). 4. Define overridden method in your extended class. 5. Define another class that will use or be used by the extended class above (has a). 6. Define and implement an interface that requires at least one method (does a).7.fun Define and use a collection of your class type not primitive type. 8. Interact with the user (in driver class) you can use the Scanner class if you like. Displayed output is spelled and aligned to look neat and professional. All data is accompanied by a brief explanation. Your classes meet the following specs: JavaDoc comments are used to introduce the class itself.The opening comments include a helpful descriptive purpose statement, the programmer’s name and date the application was written. 2. JavaDoc comments are used to introduce all methods:Constructors, mutator and accessor methods and custom methods.There is on Javadoc comment per method.Include a @param or @return tag as appropriate for the type of method being described.3. Other comments are used as needed to clarify use of identifiers or blocks of code (like loop or decision structures).4. Identifier names conform to standard Java conventions (class names begin with an uppercase character and identifier names begin with lower case character).5. White space is used to separate functional parts of the program.6.Indentation is consistent for methods and internal blocks of code.7. Block braces are placed consistently.
Explanation / Answer
Answer:
In my own decision I am creating the classes altogether four classes has been created. On that one is a main class, the overridden methods are also implemented. The code is placed below.
AnimalClass.java:
interface fourclasses
{
void Sleep_Method();
void Eat_Method();
}
public class AnimalClass
{
public AnimalClass()
{
System.out.println("A NEW ANIMAL HAS BEEN CREATED!");
}
public void Sleep_Method()
{
System.out.println("AN ANIMAL SLEEPS...");
}
public void Eat_Method()
{
System.out.println("AN ANIMAL EATS...");
}
}
BirdClass.java:
public class BirdClass extends AnimalClass
{
public BirdClass()
{
super();
System.out.println("A NEW BIRD HAS BEEN CREATED!");
}
@Override
public void Sleep_Method()
{
System.out.println("A BIRD SLEEPS...");
}
@Override
public void Eat_Method()
{
System.out.println("A bird eats...");
}
}
DogClass.java:
public class DogClass extends AnimalClass
{
public DogClass()
{
super();
System.out.println("A NEW DOG HAS BEEN CREATED!");
}
@Override
public void Sleep_Method()
{
System.out.println("A DOG SLEEPS...");
}
@Override
public void Eat_Method() {
System.out.println("A DOG EATS...");
}
}
MainClasses.java:
import java.util.*;
public class MainClasses
{
public static void main(String[] args)
{
AnimalClass an = new AnimalClass();
BirdClass bd = new BirdClass();
DogClass dg = new DogClass();
Scanner inp=new Scanner(System.in);
System.out.println("1.Animal Details");
System.out.println("2.Bird Details");
System.out.println("3.Dog Details");
System.out.println("4.Exit");
System.out.println("Enter your choice");
int result=inp.nextInt();
do
{
switch(result)
{
case 1:
System.out.println("Animal details");
an.Sleep_Method();
an.Eat_Method();
break;
case 2:
System.out.println("BirdClass details");
bd.Sleep_Method();
bd.Eat_Method();
break;
case 3:
System.out.println("DogClass details");
dg.Sleep_Method();
dg.Eat_Method();
break;
default:
System.out.println("No details");
break;
}
}while(result!=4);
}
}
Sample Output:
D:Program FilesJavajdk1.8.0_40in>java MainClasses
A new animal has been created!
A new animal has been created!
A new bird has been created!
A new animal has been created!
A new dog has been created!
1.Animal Details
2.Bird Details
3.Dog Details
4.Exit
Enter your choice