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

For this lab, we will write a \"Company Simulator\" where different employees or

ID: 3705649 • Letter: F

Question

For this lab, we will write a "Company Simulator" where different employees or different levels will attempt to "program" stuff. However, there's a chance they might break something, and will have to call their Manager to fix it.

Download the Lab Starter Pack here: http://scrivnor.cikeys.com/files/150_s18/L06_StarterPack.zip

Task 1: Implement the Missing Code

* Employee.java

      * `equals()`

* SoftwareEngineer.java

     * `doWork()`

     * `toString()`

           * Add the job title to supers `toString` method's value.

* SoftwareManager.java

      * Also includes the additional method `fixProblem()`.

      * Essentially the same as Software Engineer, but with a different name.

* Executive.java

      * `toString()`

      * Add the job title to supers `toString` method's value.

* CompanySimulator.java

      * Constructor method

      * `initCompany()`

      * Add SoftwareEngineer's and SoftwareManager's to the company.

      * `handleProblem()`

Task 2: Make the Output Pretty

Modify the CompanySimulator.java's `displayCompany()` method to print the company in tab format (use `printf`) so it looks pretty. Your output should match:

Task 3: Read the Names From a File

Create a text file called `employees.txt` in the same directory as your java files.

Add this to the contents:

In `CompanySimulator.java`, remove the field `randomNames`.

In `CompanySimulator.java`, modify the method `initCompany()` to assign the names of the Employees from reading the file instead. The same rules as to who is a Software Manager vs. Software Engineer, using the line numbers as an index.

Recall that there may be some Exceptions you need to handle when reading from a file. You should test reading from files that do not exist as well.

Task 4

Write an abstract superclass called Number with a single abstract void method square. Write a subclass called RationalNumber that has two integer fields, numerator and denominator. Write a subclass called ComplexNumber that has two integer fields, real and complex. Implement the square() method for both subclasses which will print the number squared with a 5 decimal precision. Write a class called NumberClient and use the following main method to test for correctness.

Make sure your decimal numbers are "pretty."

??Java Class>> SoftwareEngineer edu.csuci.comp150.L06 FSoftwareEngineer) SoftwareEngineer(String,int) doWork():boolean ??Java Class GEmployee C CompanySimulator edu.csuci.comp150.L06 o toString0:String edu.csuci.comp150.L06 a name: String a id: int a randomNames: Stringl CompanySimulator) o initCompany():void e displayEmployees(:void o performWork():void e handleProblem(Employee):void o simulate(int):void SoftwareManager SoftwareManager() doWork):boolean Employee) edu.csuci.comp150.LO6 Employee(String,int) o getName():String o getld():int d doWork):boolean o toString):String o equals (Object):boolean FSoftwareManager(String,int) e fixProblem(:void e toString):String main(Stringl):void C Executive edu.csuci.comp150.L06 Manager edu.csuci.compl 50.?06 Executive() Executive(String,int) o fixProblem():void o doWork():boolean o fixProblem():void o toString0:String

Explanation / Answer

Task-4:

Number.java:

public abstract class Number {
   public abstract void square();
}

RationalNumber.java:

public class RationalNumber extends Number{

   private int numerator;
   private int denominator;
  
   public RationalNumber(int numerator, int denominator) {
       this.numerator = numerator;
       this.denominator = denominator;
   }

   public int getNumerator() {
       return numerator;
   }

   public void setNumerator(int numerator) {
       this.numerator = numerator;
   }

   public int getDenominator() {
       return denominator;
   }

   public void setDenominator(int denominator) {
       this.denominator = denominator;
   }

   public void square() {
       System.out.println("Square of " + numerator + " / " + denominator + " is " + (numerator * numerator) + " / " + (denominator * denominator));
   }

}

ComplexNumber.java:

public class ComplexNumber extends Number{

   private double real;
   private double imaginary;
  
   public ComplexNumber(double real, double imaginary) {
       this.real = real;
       this.imaginary = imaginary;
   }

   public double getReal() {
       return real;
   }

   public void setReal(double real) {
       this.real = real;
   }

   public double getImaginary() {
       return imaginary;
   }

   public void setImaginary(double imaginary) {
       this.imaginary = imaginary;
   }

   public void square() {
       System.out.println("Square of " + real + "+" + imaginary + "i is = " + (Math.pow(real, 2) - Math.pow(imaginary, 2)) + "+" + (2 * real * imaginary) + "i");
   }

}

TestNumber.java:

public class TestNumber {
  
   public static void main(String[] args){
       Number n1 = new RationalNumber(3, 4);
       Number n2 = new ComplexNumber(3, 2);
       n1.square();
       n2.square();
   }
  
}

Sample-Output:

Square of 3 / 4 is 9 / 16
Square of 3.0+2.0i is = 5.0+12.0i

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