Hi, can i get some help with this, im struggling to make it work: You must creat
ID: 3914414 • Letter: H
Question
Hi, can i get some help with this, im struggling to make it work:
You must create two Java files. One is called LastNameFirstNameWeek7Prog.java, and the other is called Business.java.
Ensure you include ALL the java files required to make your program compile and run. I would like to see only your .java files.)
Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter.
Only submit the .java files needed to make the program run. Do not submit the .class file or any other file.
5%
Style Components
Include properly formatted prologue, comments, indenting, and other style elements as shown in Chapter 2 starting page 64 and Appendix 5 page 881-892.
5%
LastNameFirstNameWeek7Prog.java
Write a driver class that uses the Business class. This driver class will use the main method provided below exactly. You must copy it inside your driver class and not change it. Any change in the main method will deduct points.
public static void main (String[] args) throws Exception {
Scanner stdIn = new Scanner(System.in);
String name; //Auxiliar Business name
String stockTicker; //Auxiliar Business Stock Ticker
int numberOfEmployees; //Auxiliar Number OF Employees
double netWorth; // Auxiliar net worth
Business a, b, c, d; // Business objects
System.out.println("Enter name of first Business");
name = stdIn.nextLine();
System.out.println("Enter Stock Ticker for first Business");
stockTicker = stdIn.nextLine();
System.out.println("Enter Number Of Employees for first Business");
numberOfEmployees = Integer.parseInt(stdIn.nextLine());
System.out.println("Enter Net Worth for first Business");
netWorth = Double.parseDouble(stdIn.nextLine());
a = new Business(name, stockTicker, numberOfEmployees, netWorth);
System.out.println("Enter name of second Business");
name = stdIn.nextLine();
System.out.println("Enter Stock Ticker for second Business");
stockTicker = stdIn.nextLine();
System.out.println("Enter Number Of Employees for second Business");
numberOfEmployees = Integer.parseInt(stdIn.nextLine());
System.out.println("Enter Net Worth for second Business");
netWorth = Double.parseDouble(stdIn.nextLine());
b = new Business(name, stockTicker, numberOfEmployees, netWorth);
System.out.println("Initial set of Business");
System.out.println("a: "+a);
System.out.println("b: "+b);
System.out.println("Business a after growth of 10%");
a.grow();
System.out.println("a: "+a);
System.out.println("Businesses b and c, after business b grows 10% and branch out to create c");
c = b.grow().branchOut("Branch of "+b.getName());
System.out.println("b: "+b);
System.out.println("c: "+c);
System.out.println("Businesses a, c & d, after creation of d, a joint venture of a and c");
d = a.joinVenture(c);
System.out.println("a: "+a);
System.out.println("c: "+c);
System.out.println("d: "+d);
System.out.println("Businesses a & b, after a takes over b");
a.takeOver(b);
System.out.println("a: "+a);
System.out.println("b: "+b);
} // end main
This demonstration driver does not call all accessor and mutator methods but it is normal to create them regardless of an immediate use. They may be needed in the future. Sample output is provided below. Be sure to be able to reproduce it.
30%
Business.java
Write a Business class inside the Business.java file. This class describe a fictitious Business Company that contains four attributes: the Strings name and StockTicker, the integer numberOfEmployees, and the double netWorth. This class will implement the following methods:
· Accessor (get) and Mutator (set) methods for all its attributes.
· Default constructor and an Alternate Constructor with parameters for all its attributes.
· toString – This method will take no parameters. It will return a new String containing all information of the Business object. For example, in the sample output below, the toString method produces the following String for object a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 1000
Net Worth: 1000000.0
· grow – This method receives no parameters. It increases the number of employees and the net worth of the current company (this) by 10%. After doing that the method returns the current object (return this).
· branchOut – This method creates a new Business object that will branch out from the current object. The method receives one parameter: the name of the new Business object. A new Business object must be created inside this method. This new Business objects takes a quarter of the employees and a quarter of the net worth from the current Business (this). The method will subtract the number of employees and money in the parameters from the current object and assign it to a new Business object. The stock ticker for the new Business object will be made of the first character of the name of the new object followed by “-“, followed by the last character of the name of the new object. The method will return the newly created Business object.
· joinVenture – This method creates a new Business object that obtains employees and net worth from the current object and another object. The method receives one parameter: a Business object (let us call it b). The method subtracts a quarter of employees and net worth from both, the current object and the Business object b, to be added to the number of employees and net worth of a new Business object that needs to be created. The name of the new Business object is the name of the current object followed by “-”, and the name of object b. The stock ticker for the new Business object will be made of the first character of the name of the current object followed by “&“, then followed by the first character of the name of object b. The method will return the newly created Business object.
· takeOver – This method takes another Business object as a parameter. The current object (this) takes three quarters of the employees and three quarters of the net worth from the Business object in the parameter and return the current object (return this). The Business object parameter will end up with only one quarter of its original employees and net worth.
Do not use Arrays or any other advanced concept that was not reviewed in the class to solve this assignment. Assignments that use these concepts will only be graded 10% for presentation.
55
NOTE: Complete your activity and submit it by clicking “Submit Assignment”
5%
Total Percentage
100%
Sample
Enter name of first Business
National Business Machines
Enter Stock Ticker for first Business
NBM
Enter Number Of Employees for first Business
1000
Enter Net Worth for first Business
1000000.0
Enter name of second Business
Good Week Inc.
Enter Stock Ticker for second Business
GWI
Enter Number Of Employees for second Business
2000
Enter Net Worth for second Business
4000000.0
Initial set of Business
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 1000
Net Worth: 1000000.0
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 2000
Net Worth: 4000000.0
Business a after growth of 10%
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 1100
Net Worth: 1100000.0
Businesses b and c, after business b grows 10% and branch out to create c
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 1650
Net Worth: 3300000.0
c:
[Branch of Good Week Inc.]
Stock Ticker: B-.
# of Employees: 550
Net Worth: 1100000.0
Businesses a, c & d, after creation of d, a joint venture of a and c
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 825
Net Worth: 825000.0
c:
[Branch of Good Week Inc.]
Stock Ticker: B-.
# of Employees: 413
Net Worth: 825000.0
d:
[National Business Machines-Branch of Good Week Inc.]
Stock Ticker: N&B
# of Employees: 412
Net Worth: 550000.0
Businesses a & b, after a takes over b
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 2062
Net Worth: 3300000.0
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 413
Net Worth: 825000.0
You must create two Java files. One is called LastNameFirstNameWeek7Prog.java, and the other is called Business.java.
Ensure you include ALL the java files required to make your program compile and run. I would like to see only your .java files.)
Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter.
Only submit the .java files needed to make the program run. Do not submit the .class file or any other file.
5%
Style Components
Include properly formatted prologue, comments, indenting, and other style elements as shown in Chapter 2 starting page 64 and Appendix 5 page 881-892.
5%
LastNameFirstNameWeek7Prog.java
Write a driver class that uses the Business class. This driver class will use the main method provided below exactly. You must copy it inside your driver class and not change it. Any change in the main method will deduct points.
public static void main (String[] args) throws Exception {
Scanner stdIn = new Scanner(System.in);
String name; //Auxiliar Business name
String stockTicker; //Auxiliar Business Stock Ticker
int numberOfEmployees; //Auxiliar Number OF Employees
double netWorth; // Auxiliar net worth
Business a, b, c, d; // Business objects
System.out.println("Enter name of first Business");
name = stdIn.nextLine();
System.out.println("Enter Stock Ticker for first Business");
stockTicker = stdIn.nextLine();
System.out.println("Enter Number Of Employees for first Business");
numberOfEmployees = Integer.parseInt(stdIn.nextLine());
System.out.println("Enter Net Worth for first Business");
netWorth = Double.parseDouble(stdIn.nextLine());
a = new Business(name, stockTicker, numberOfEmployees, netWorth);
System.out.println("Enter name of second Business");
name = stdIn.nextLine();
System.out.println("Enter Stock Ticker for second Business");
stockTicker = stdIn.nextLine();
System.out.println("Enter Number Of Employees for second Business");
numberOfEmployees = Integer.parseInt(stdIn.nextLine());
System.out.println("Enter Net Worth for second Business");
netWorth = Double.parseDouble(stdIn.nextLine());
b = new Business(name, stockTicker, numberOfEmployees, netWorth);
System.out.println("Initial set of Business");
System.out.println("a: "+a);
System.out.println("b: "+b);
System.out.println("Business a after growth of 10%");
a.grow();
System.out.println("a: "+a);
System.out.println("Businesses b and c, after business b grows 10% and branch out to create c");
c = b.grow().branchOut("Branch of "+b.getName());
System.out.println("b: "+b);
System.out.println("c: "+c);
System.out.println("Businesses a, c & d, after creation of d, a joint venture of a and c");
d = a.joinVenture(c);
System.out.println("a: "+a);
System.out.println("c: "+c);
System.out.println("d: "+d);
System.out.println("Businesses a & b, after a takes over b");
a.takeOver(b);
System.out.println("a: "+a);
System.out.println("b: "+b);
} // end main
This demonstration driver does not call all accessor and mutator methods but it is normal to create them regardless of an immediate use. They may be needed in the future. Sample output is provided below. Be sure to be able to reproduce it.
30%
Business.java
Write a Business class inside the Business.java file. This class describe a fictitious Business Company that contains four attributes: the Strings name and StockTicker, the integer numberOfEmployees, and the double netWorth. This class will implement the following methods:
· Accessor (get) and Mutator (set) methods for all its attributes.
· Default constructor and an Alternate Constructor with parameters for all its attributes.
· toString – This method will take no parameters. It will return a new String containing all information of the Business object. For example, in the sample output below, the toString method produces the following String for object a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 1000
Net Worth: 1000000.0
· grow – This method receives no parameters. It increases the number of employees and the net worth of the current company (this) by 10%. After doing that the method returns the current object (return this).
· branchOut – This method creates a new Business object that will branch out from the current object. The method receives one parameter: the name of the new Business object. A new Business object must be created inside this method. This new Business objects takes a quarter of the employees and a quarter of the net worth from the current Business (this). The method will subtract the number of employees and money in the parameters from the current object and assign it to a new Business object. The stock ticker for the new Business object will be made of the first character of the name of the new object followed by “-“, followed by the last character of the name of the new object. The method will return the newly created Business object.
· joinVenture – This method creates a new Business object that obtains employees and net worth from the current object and another object. The method receives one parameter: a Business object (let us call it b). The method subtracts a quarter of employees and net worth from both, the current object and the Business object b, to be added to the number of employees and net worth of a new Business object that needs to be created. The name of the new Business object is the name of the current object followed by “-”, and the name of object b. The stock ticker for the new Business object will be made of the first character of the name of the current object followed by “&“, then followed by the first character of the name of object b. The method will return the newly created Business object.
· takeOver – This method takes another Business object as a parameter. The current object (this) takes three quarters of the employees and three quarters of the net worth from the Business object in the parameter and return the current object (return this). The Business object parameter will end up with only one quarter of its original employees and net worth.
Do not use Arrays or any other advanced concept that was not reviewed in the class to solve this assignment. Assignments that use these concepts will only be graded 10% for presentation.
55
NOTE: Complete your activity and submit it by clicking “Submit Assignment”
5%
Total Percentage
100%
Sample
Enter name of first Business
National Business Machines
Enter Stock Ticker for first Business
NBM
Enter Number Of Employees for first Business
1000
Enter Net Worth for first Business
1000000.0
Enter name of second Business
Good Week Inc.
Enter Stock Ticker for second Business
GWI
Enter Number Of Employees for second Business
2000
Enter Net Worth for second Business
4000000.0
Initial set of Business
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 1000
Net Worth: 1000000.0
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 2000
Net Worth: 4000000.0
Business a after growth of 10%
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 1100
Net Worth: 1100000.0
Businesses b and c, after business b grows 10% and branch out to create c
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 1650
Net Worth: 3300000.0
c:
[Branch of Good Week Inc.]
Stock Ticker: B-.
# of Employees: 550
Net Worth: 1100000.0
Businesses a, c & d, after creation of d, a joint venture of a and c
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 825
Net Worth: 825000.0
c:
[Branch of Good Week Inc.]
Stock Ticker: B-.
# of Employees: 413
Net Worth: 825000.0
d:
[National Business Machines-Branch of Good Week Inc.]
Stock Ticker: N&B
# of Employees: 412
Net Worth: 550000.0
Businesses a & b, after a takes over b
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 2062
Net Worth: 3300000.0
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 413
Net Worth: 825000.0
Explanation / Answer
Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
Business.java
------
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) + " ";
}
}
LastNameFirstNameWeek7Prog.java
------------------
import java.util.Scanner;
public class LastNameFirstNameWeek7Prog {
public static void main (String[] args) throws Exception {
Scanner stdIn = new Scanner(System.in);
String name; //Auxiliar Business name
String stockTicker; //Auxiliar Business Stock Ticker
int numberOfEmployees; //Auxiliar Number OF Employees
double netWorth; // Auxiliar net worth
Business a, b, c, d; // Business objects
System.out.println("Enter name of first Business");
name = stdIn.nextLine();
System.out.println("Enter Stock Ticker for first Business");
stockTicker = stdIn.nextLine();
System.out.println("Enter Number Of Employees for first Business");
numberOfEmployees = Integer.parseInt(stdIn.nextLine());
System.out.println("Enter Net Worth for first Business");
netWorth = Double.parseDouble(stdIn.nextLine());
a = new Business(name, stockTicker, numberOfEmployees, netWorth);
System.out.println("Enter name of second Business");
name = stdIn.nextLine();
System.out.println("Enter Stock Ticker for second Business");
stockTicker = stdIn.nextLine();
System.out.println("Enter Number Of Employees for second Business");
numberOfEmployees = Integer.parseInt(stdIn.nextLine());
System.out.println("Enter Net Worth for second Business");
netWorth = Double.parseDouble(stdIn.nextLine());
b = new Business(name, stockTicker, numberOfEmployees, netWorth);
System.out.println("Initial set of Business");
System.out.println("a: "+a);
System.out.println("b: "+b);
System.out.println("Business a after growth of 10%");
a.grow();
System.out.println("a: "+a);
System.out.println("Businesses b and c, after business b grows 10% and branch out to create c");
c = b.grow().branchOut("Branch of "+b.getName());
System.out.println("b: "+b);
System.out.println("c: "+c);
System.out.println("Businesses a, c & d, after creation of d, a joint venture of a and c");
d = a.joinVenture(c);
System.out.println("a: "+a);
System.out.println("c: "+c);
System.out.println("d: "+d);
System.out.println("Businesses a & b, after a takes over b");
a.takeOver(b);
System.out.println("a: "+a);
System.out.println("b: "+b);
} // end main
}
output
-----
Enter name of first Business
National Business Machines
Enter Stock Ticker for first Business
NBM
Enter Number Of Employees for first Business
1000
Enter Net Worth for first Business
1000000.0
Enter name of second Business
Good Week Inc.
Enter Stock Ticker for second Business
GWI
Enter Number Of Employees for second Business
2000
Enter Net Worth for second Business
4000000.0
Initial set of Business
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 1000
Net Worth: 1000000.0
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 2000
Net Worth: 4000000.0
Business a after growth of 10%
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 1100
Net Worth: 1100000.0
Businesses b and c, after business b grows 10% and branch out to create c
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 1650
Net Worth: 3300000.0
c:
[Branch of Good Week Inc.]
Stock Ticker: B-.
# of Employees: 550
Net Worth: 1100000.0
Businesses a, c & d, after creation of d, a joint venture of a and c
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 825
Net Worth: 825000.0
c:
[Branch of Good Week Inc.]
Stock Ticker: B-.
# of Employees: 413
Net Worth: 825000.0
d:
[National Business Machines-Branch of Good Week Inc.]
Stock Ticker: N&B
# of Employees: 412
Net Worth: 550000.0
Businesses a & b, after a takes over b
a:
[National Business Machines]
Stock Ticker: NBM
# of Employees: 2062
Net Worth: 3300000.0
b:
[Good Week Inc.]
Stock Ticker: GWI
# of Employees: 413
Net Worth: 825000.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.