Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class called \'Enterprize\', ii has one private member variable called

ID: 3819428 • Letter: C

Question

Create a class called 'Enterprize', ii has one private member variable called 'category' (of character type, its value is either 'F' (for food), or C (for clothing), or 'H' (for housing)). This class should have constructor and accessor functions. b) Create a derived class (of Enterprize) called 'not_for_profit' having one private member variable called 'sponsor' (of character type, its value is either 'P' (for private), or 'G' (for government)). This derived class should also have constructor and accessor functions. c) Create another derived class (of Enterprize) called 'for_profit' having one private member variable called "revenue" (of integer type). This derived class should also have constructor and accessor functions. d) Define all the functions (no need of default constructors). e) In the main function, declare one object (called Salvation army) of class 'not_for_profit' that has private sponsor and deals with clothing. Declare another object (called HEB) of class 'for_profit' that has $1M revenue and deals with food. f) Write statements to check if Salvation_army and HEB are in the same category of Enterprize or not (food, clothing, or housing) and print appropriate messages.

Explanation / Answer

package pack1;

class Enterprize{
   private char category;
  
   public Enterprize(char category){
       this.category = category;
   }
  
   public char getCategory(){
       // Defining category in Parent class
       switch(this.category){
       case 'F':
           System.out.println("It belongs to Food");
           break;
       case 'C':
           System.out.println("It belongs to Clothing");
           break;
       case 'H':
           System.out.println("It belongs to Housing");
           break;
       default:
           System.out.println("This category is not defined");
          
       }
       return category;
   }
}
class NotForProfit extends Enterprize{
   private char sponsor;
  
   // Constructor accept two argument one for sponsor in same class and other for category in parent class
   public NotForProfit(char sponsor, char category){
       super(category);
       this.sponsor = sponsor;
   }
   public char getSponsor(){
       switch(this.sponsor){
       case 'P':
           System.out.println("Private sponsor");
           break;
       case 'G':
           System.out.println("Government sponsor");
           break;
       default:
           System.out.println("Undefined sponsor");
           break;
       }
       return sponsor;
   }
}

class ForProfit extends Enterprize{
   private int revenue;
  
   //// Constructor accept two argument one for revenue in the same class and other for category in parent class
   public ForProfit(int revenue,char category){
       super(category);
       this.revenue = revenue;
   }
  
   public int getRevenue(){
       return revenue;
      
   }
     
}


public class MainClass {
   public static void main(String[] args){
      
       // Local variables to hold value of category of different objects
       char categorySalavationArmy, categoryHEB;
  
       //Creating SalavationArmy object with appropriate arguments
       NotForProfit SalavationArmy = new NotForProfit('P','C');      
       categorySalavationArmy = SalavationArmy.getCategory();
              
       //Creating HEB object with appropriate arguments      
       ForProfit HEB = new ForProfit(1000000,'F');
       categoryHEB = HEB.getCategory();
      
       //Validating category of both the objects
       if (categorySalavationArmy == categoryHEB){
           System.out.println("Both objects are of same category");
       }
           else{
               System.out.println("Both objects are of different category");
       }
      
      
      
   }
}

In order to execute above code please follow the following guide line:

Expected Output:

"It belongs to Clothing
It belongs to Food
Both objects are of different category"

I hope this program has made sense. Thank you !!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote