Assignment 1 – review of classes and arrays Due: Wednesday January 15, 10:30 (class time)
IMPORTANT: individual work please!
What/how to submit: You should submit your work through D2L only, no paper copy. The submission should a single PDF file containing all your code. Make sure that each class starts on a new page (still in the same PDF file). You can
either print each file to PDF and then combine them into a single file, or copy-paste all the code in a MS Word document and save it as PDF.
Tasks:
Politicians like to talk about helping middle class and tax wealthy people more. Say that they would like to do something similar, but for companies. They want to identify wealthier companies (to add an extra tax to them) and poorer companies (to give them a tax reduction). You want to write an application that will identify such companies.
First, you should create a “Company” class to hold 3 instance variables: the name of the company (as String), their revenues and their expenses (both as double). The class should also contain the following methods: a constructor (for all 3 variables), an accessor method for the name, a method that returns the profit (as revenues minus expenses), and a toString method (prints the name of the company, followed by the profit amount in parentheses – profit calculated by calling the proper method).
Then, your driver class should have a main method and the following two methods implemented:
static double calculateMean(Company[] list)
static double calculateStDev(Company[] list, double mean)
Note: by making these methods “static”, it will be possible to call them directly from the main method
are X1 to Xn):
Those methods should implement the following formula respectively (assuming that the values
∑𝑛𝑛𝑚𝑚 𝑋𝑋 𝑚𝑚 𝑚𝑚 �𝑚𝑚 𝑚𝑚 = 𝑚𝑚
𝑖𝑖=1 𝑖𝑖
∑𝑛𝑛𝑖𝑖=1(𝑋𝑋𝑖𝑖 − 𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚)2
Your main method should first create an array of Company, with the following data entered (note: you can hardcode those in your code when creating the objects):
𝑠𝑠𝑠𝑠𝑠𝑠𝑚𝑚𝑠𝑠 =
name
revenues
expenses
A
100000
90000
B
123123
45000
C
300000
190000
D
100000
99900
E
90909
33333
F
11122
3344
G
200800
105100
H
123321
100000
I
90000
45000
J
99999
11111
Then you should have the proper code to get the following output:
The mean is $51,648.60
The standard deviation is $38,250.96
Wealthy companies:
C (110000.0)
G (95700.0)
There are 2 such companies
Poorer companies:
A (10000.0)
D (100.0)
F (7778.0)
There are 3 such companies
In particular:
1. Your main method should make the proper calls to the 2 static methods specified
above.
2. The mean and the stdev should be printed nicely with the NumberFormat class.
3. The list of wealthy companies are the ones with a profit higher than the mean +
stdev.
4. The list of poorer companies are the ones with a profit lower than the mean – stdev.
5. For steps 3 and 4 above, you should use the method that calculates profits and the
toString method.
6. No marks given if any of the things above are hardcoded (except for creating all
Company objects).