Question

Come up with a real-life problem (open-ended) and solve it by designing and writing a Java...

Come up with a real-life problem (open-ended) and solve it by designing and writing a Java program, which implements the following java object-oriented features:

• Interaction Design

• Class and Object

• Parameterized Constructor

• Encapsulation

• Inheritance

• Abstract Method

• Method Overloading

• Method Overriding

(Add comments to code)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Engineer.java

public abstract class Engineer {

   //Encapsulation
   //For data privacy purpose.
   // This protected variables cannot be directly accessed by the object of the class.
   protected String university;
   protected int batch;
  
  
   //Default Constructor
   public Engineer() {
      
   }
  
   //Parameterised Constructor
   //This is also an example of overloading.
   // We can an object of this class either by default constructor or Parameterised constructor.
   public Engineer(String university, int batch) {
       super();
       this.university = university;
       this.batch = batch;
   }
  
   //Below are setters and getters for the variables of this class.
   // These methods are mandatory to get and set values for the instance variables of this class
   public String getUniversity() {
       return university;
   }
   public void setUniversity(String university) {
       this.university = university;
   }
   public int getBatch() {
       return batch;
   }
   public void setBatch(int batch) {
       this.batch = batch;
   }
  
  
   //This method will be overrided in the child class to show the overriding example
   public String getEngineerInfo() {
      
       return "University : "+this.university+"\nBatch : "+this.batch;
   }
  
  
   //Absract method.It can be defined in the child class extending this calss.
   //This is an example of abstract class.
   //Abstarct class is nothing but a methos is declared but not defined. We can do that by simply adding abstract keyword.
   public abstract String getBranch();
  
  
}

ComputerEngineer.java

public class ComputerEngineer extends Engineer{

   String branch = "Computer Science";
  
  
   public ComputerEngineer(String uni,int batch) {
       super(uni,batch);
      
   }

  

   //This is the overrided method of abstract method in the parent class Engineer.
  
   public ComputerEngineer() {
       // TODO Auto-generated constructor stub
   }

   @Override
   public String getBranch() {
       // TODO Auto-generated method stub
       return this.branch;
   }
  
  
   //This method will be overrided in the child class to show the overriding example
       public String getEngineerInfo() {
          
           return "University : "+this.university+"\nBatch : "+this.batch+"\nBranch : "+this.branch;
       }

}

EngineerTest.java

import java.util.Scanner;

public class EngineerTest {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

      
       Scanner scan = new Scanner(System.in);
      
       System.out.println("Calling default Constructor");
       Engineer engineer = new ComputerEngineer();
      
       System.out.println(engineer.getEngineerInfo());
      
       System.out.println("**********************************************\n");
      
       System.out.println("Enter the university name : ");
      
       String uni = scan.next();
      
System.out.println("Enter the Batch number : ");
      
       int batch = scan.nextInt();
      
       System.out.println("Calling Parameterised Constructor");
       engineer = new ComputerEngineer(uni,batch);
      
       System.out.println(engineer.getEngineerInfo());
      
       System.out.println("**********************************************\n");
      
      
       System.out.println("Calling the abstract method implemented");
       System.out.println("Branch is : "+engineer.getBranch());
      
      
      
      
      
   }

}

Output

Calling default Constructor
University : null
Batch : 0
Branch : Computer Science
**********************************************

Enter the university name :
Stanford
Enter the Batch number :
2011
Calling Parameterised Constructor
University : Stanford
Batch : 2011
Branch : Computer Science
**********************************************

Calling the abstract method implemented
Branch is : Computer Science

Feel free to ask any doubts, if you face any difficulty in understanding.

Please upvote the answer if you find it helpful

Add a comment
Know the answer?
Add Answer to:
Come up with a real-life problem (open-ended) and solve it by designing and writing a Java...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are given a specification for some Java classes as follows.   A building has a number...

    You are given a specification for some Java classes as follows.   A building has a number of floors, and a number of windows. A house is a building. A garage is a building. (This isn’t Florida-like … it’s a detached garage.) A room has a length, width, a floor covering, and a number of closets. You can never create an instance of a building, but every object that is a building must have a method that calculates the floor space,...

  • 9. Java coder Courtney is writing a program that derives a list of unique words contained...

    9. Java coder Courtney is writing a program that derives a list of unique words contained in a given text file: the word values themselves, and a total count for the file. What Collection type would be best suited for the job? Check only one) O (a) BinarySearch (b) List □ (c) Map (d) Set D (e) Queue 10.Software-Engineer Ellie is designing a similar program to Courtney. She needs to track a count for each unique word contained in a...

  • Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables...

    Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables and 2 effectors for a new data type – the class HospitalPatient. You have the freedom to design the instance variables and effectors. instance variables effectors 1. 1. 2. 2. 3. Write the code for class HospitalPatient, according to the requirement above. Include the default constructors with no argument, and the constructor with all arguments. Provide a getter and setter for each individual instance...

  • In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

    In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...

  • Object oriented design: Write a program that implements the basic flow, the startup scenario (For a retail store) a...

    Object oriented design: Write a program that implements the basic flow, the startup scenario (For a retail store) and the alternative flow: An item with the specified identifier has already been entered in the current sale. Program increases the sold quantity of the item, and presents item description, price, and running total. You do not have to program any other alternative flows or add any other functionality. You are also not required to code the view, you may replace the...

  • 1. (TCO 7) Which of the following statements are true? (Points : 5)        Interfaces contain...

    1. (TCO 7) Which of the following statements are true? (Points : 5)        Interfaces contain one and only one implemented method, a constructor.        Interfaces are defined inside an abstract class.        All methods defined in an interface must be implemented when used by another class.        A true object-oriented design must contain as least one interface. Question 2. 2. (TCO 7) In an object-oriented program, methods with no implementation might be found in an _____ and/or a(n) ______....

  • JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...

    JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...

  • JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees....

    JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description:...

    This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT