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

** Can you tell me what each line is doing? // example? public class Business {

ID: 3916651 • Letter: #

Question

** Can you tell me what each line is doing? // example?

public class Business {
private String name;
private String stockTicker;
private int numberOfEmployees;
private double netWorth;

public Business(String name, String stockTicker, int numberOfEmployees, double netWorth) {
this.name = name;
this.stockTicker = stockTicker;
this.numberOfEmployees = numberOfEmployees;
this.netWorth = netWorth;
}

public Business grow() {
numberOfEmployees += (0.1 * numberOfEmployees);
netWorth += 0.1 * netWorth;
return this;
}


public Business branchOut(String newName) {
String newTicker = newName.charAt(0) + "-" + newName.charAt(newName.length()-1);
int newEmps = (int)(numberOfEmployees * 0.25);
double newNet = netWorth * 0.25;

numberOfEmployees -= newEmps;
netWorth -= newNet;
return new Business(newName, newTicker, newEmps, newNet);
}

public Business joinVenture(Business b) {
String newTicker = name.charAt(0) + "&" + b.name.charAt(0);
String newName = name + "-" + b.name;
int emps1 = (int)(numberOfEmployees * 0.25);
double net1 = netWorth * 0.25;
int emps2 = (int)(b.numberOfEmployees * 0.25);
double net2 = b.netWorth * 0.25;
int newEmps = emps1 + emps2;
double newNet = net1 + net2;

numberOfEmployees -= emps1;
netWorth -= net1;
b.numberOfEmployees -= emps2;
b.netWorth -= net2;
return new Business(newName, newTicker, newEmps, newNet);
}

public Business takeOver(Business b) {
int emps = (int)(3.0/4 * b.numberOfEmployees);
double net = 3.0/4 * b.netWorth;

b.numberOfEmployees -= emps;
b.netWorth -= net;

numberOfEmployees += emps;
netWorth += net;
return this;
}

public String getStockTicker() {
return stockTicker;
}

public void setStockTicker(String stockTicker) {
this.stockTicker = stockTicker;
}

public int getNumberOfEmployees() {
return numberOfEmployees;
}

public void setNumberOfEmployees(int numberOfEmployees) {
this.numberOfEmployees = numberOfEmployees;
}

public double getNetWorth() {
return netWorth;
}

public void setNetWorth(double netWorth) {
this.netWorth = netWorth;
}

public String getName(){
return name;
}
public void setName(String name) {
this.name = name;
}

public String toString(){
return "[" + name + "]" + " " +
" " + "Stock Ticker: " + stockTicker + " " +
" " + "# of Employees: " + numberOfEmployees + " " +
" " + "Net Worth: " + String.format("%.1f", netWorth) + " ";
}
}

Explanation / Answer

public class Business {

   

    // store the name of Business

   private String name;

   

    // store the stock symbol of Business

    private String stockTicker;

   

    // store the number of employees in the company

    private int numberOfEmployees;

   

    // store the net worth of company

    private double netWorth;

    // parametarized constructor to initialize the class attributes

    public Business(String name, String stockTicker, int numberOfEmployees, double netWorth) {

        this.name = name;

        this.stockTicker = stockTicker;

        this.numberOfEmployees = numberOfEmployees;

        this.netWorth = netWorth;

    }

    // procedure to perform when the business grows

    public Business grow() {

        // increase the number of employees by 10%

        numberOfEmployees += (0.1 * numberOfEmployees);

       

        // increase the net worth by 10%

        netWorth += 0.1 * netWorth;

       

        // returnt he rederence to current pointer

        return this;

    }

    // procedure to perform when the business branches out

    public Business branchOut(String newName)

    {

        // create a new stock ticker

        String newTicker = newName.charAt(0) + "-" + newName.charAt(newName.length()-1);

       

        // set the new employees to 25% of total employees

        int newEmps = (int)(numberOfEmployees * 0.25);

       

        // set the new net worth to 25% of total ne worth

        double newNet = netWorth * 0.25;

        // decrease the employees sent to new company from original company's employee count

        numberOfEmployees -= newEmps;

       

        // decrease the net worth transferred to new company from original company's net worth

        netWorth -= newNet;

       

        // create a new object and return it

        return new Business(newName, newTicker, newEmps, newNet);

    }

    // procedure to perform when the business joins in

    public Business joinVenture(Business b) {

        // create a new stock ticker

        String newTicker = name.charAt(0) + "&" + b.name.charAt(0);

       

        // create a new name of the merged company

        String newName = name + "-" + b.name;

       

       

        // set the new employees by adding 25% of total employees

        int emps1 = (int)(numberOfEmployees * 0.25);

       

        // set the new net worth by adding 25% of total net worth

        double net1 = netWorth * 0.25;

       

        // add the employees of b

        int emps2 = (int)(b.numberOfEmployees * 0.25);

       

        double net2 = b.netWorth * 0.25;

       

      // get the new net no of employees

        int newEmps = emps1 + emps2;

       

        // get the new net worth

        double newNet = net1 + net2;

        // remove that no of employees

        numberOfEmployees -= emps1;

       

        // remove that net worth

        netWorth -= net1;

       

        // remove that no of employees from b

        b.numberOfEmployees -= emps2;

       

        // remove that net worth from b

        b.netWorth -= net2;

       

        // create a new object and return it

        return new Business(newName, newTicker, newEmps, newNet);

    }

    // in case a businesss takes over

    public Business takeOver(Business b) {

       

        // calculate the new no of employees

        int emps = (int)(3.0/4 * b.numberOfEmployees);

       

        // calculate the new net worth

        double net = 3.0/4 * b.netWorth;

        // remove the no of employees from b

        b.numberOfEmployees -= emps;

       

        // remove the net worth from b that it used to take over

        b.netWorth -= net;

        // as the number of employees

        numberOfEmployees += emps;

       

        // add the net worth

        netWorth += net;

       

        // returnt he rederence to current pointer

        return this;

    }

    // get the value of stock ticker

    public String getStockTicker() {

        return stockTicker;

    }

    // set the stock ticker as per the value passed as argument

    public void setStockTicker(String stockTicker) {

        this.stockTicker = stockTicker;

    }

    // get the number of employees

    public int getNumberOfEmployees() {

        return numberOfEmployees;

    }

    // set the no of employees as per the value passed as argument

    public void setNumberOfEmployees(int numberOfEmployees) {

        this.numberOfEmployees = numberOfEmployees;

    }

    // get the net worth

    public double getNetWorth() {

        return netWorth;

    }

    // set the net worth as per the value passed as argument

    public void setNetWorth(double netWorth) {

        this.netWorth = netWorth;

    }

    // get the name of Business

    public String getName(){

        return name;

    }

   

    // set the name as per the name passed as argument

    public void setName(String name) {

        this.name = name;

    }

    // override the toString() method in the Object class such that

    // when we pass object in System.out.print(), then it will print the String

    // returned by this function

    public String toString(){

        return "[" + name + "]" + " " +

        " " + "Stock Ticker: " + stockTicker + " " +

        " " + "# of Employees: " + numberOfEmployees + " " +

        " " + "Net Worth: " + String.format("%.1f", netWorth) + " ";

    }

}