QuestionQuestion

Worksheet for Lab 9
1. Each Major object has four instance variables. Write code to declare these four instance variables:
a. startSalary2014, an int
b. startSalary2013, an int
c. percentIncrease, a double, and
d. description, a String.
2. The constructor has three parameters, corresponding to the instances variables except percentIncrease, which is computed in the constructor and assigned. It represents the percentage increase in 2014 starting offers compared to 2013 offers.
The percentageIncrease is computed as follows: the difference between startSalary2014 and startSalary2013 indicates the increase in salary. This increase is divided by startSalary2013 to obtain the fractional increase.This fractional increase is multiplied by 100 to obtain the percentageIncrease.   
3. Write four getter methods for the four instance variables.
The following code will be used in the TopEarner Class
4. Create a Scanner object named keyboard to handle keyboard input to read a file name entered by the user.
5. Create a File Object named inFile, given the name of the file as inFileName. The variables have already been declared.
6. Create a Scanner object named input, given the File object inFile. The variables have already been declared.
7. Create an array named careers to hold Major objects (256 components). The variables have already been declared.
8. Create a Major object named newMajor with data obtained from file sal2014, sal2013, and description. See the constructor written earlier.
9. Close the Scanner object input and thus the file.
10. As created already, careers is an array of Major objects. Also, as written earlier, Major objects have several getter methods. We wish to use the appropriate getter method on Major objects to perform the following. Write an appropriate if statement that will fit in to the bubble sort code.   
Compare startSalary2014 of careers[index] and startSalary2014 of careers[index-1] and swap careers[index] and careers[index-1] if necessary, so that the array careers is sorted in decreasing order of order of startSalary2014 
11. Print the first 10 components of the array careers. Recognize that careers is an array of Major objects, and the Major class includes the toString method.
12. Print the last 10 components of the array careers, in reverse order. That is, the last component is printed first, and then the one before, and so on. Recognize that careers is an array of Major objects, and the Major class includes the toString method. Also, the array careers is not fully populated; only numMajors components are used.


Fundamentals of Computer Science
Learning Objectives:
• Exploring BlueJ IDE with Java SE 8 (JDK)
• Program Coding and Testing – Arrays and file processing
Purpose: The National Association of Colleges and Employers (NACE) conducts an annual survey and publishes data regarding average starting salary offers for graduates of bachelor’s degree programs in many disciplines. A text file named Salary.txt is available for us to process and determine majors that are top earners. Each line of the file has three entries. For example, consider the following line:
45500 44800 Agricultural Sciences
It indicates that majors in Agricultural Sciences received average starting salary offers of $45,500 in 2014 and $44,800 in 2013.
For the purpose of keeping information about majors, we will define a class named Major. As each line of information is read, we will create a Major object and place a reference to it in an array named careers. Eventually we sort this array of Major objects on the basis of 2014 starting salary and print a report. Assume that the file has all the fields in proper place in each line and there are no problem records.

Specification of Major class
a. Each Major object has four instance variables:
• startSalary2014, an int
• startSalary2013, an int
• percentIncrease, a double, and
• description, a String.
b. The constructor has three parameters, corresponding to all instances variables except percentIncrease, which is computed in the constructor and assigned. It represents the percentage increase in 2014 starting offers compared to 2013 offers. Compute the difference between startSalary2014 and startSalary2013 and divide it by startSalary2013 to obtain the fractional increase. (Remember that an int divided by an int results in an int in Java. But we need a fraction between 0 and 1.) This fractional increase is multiplied by 100 to obtain the percentIncrease.
c. There are four getter methods, again one corresponding to each of the four instance variables.   
d. The toString method returns a String. It is the concatenation of the values of the four instances variables, with the values suitably formatted. The code for this is given. See the use of the DecimalFormat class to format the salary and the percentage figures.

Specification of the TopEarner class
a. It contains just one main method. All the code for file processing, sorting, etc., are in this method. For the purpose of the program, it is appropriate to assume that there are at most 256 major records in the file.
b. The main method should display the purpose of the program and prompt the user to for the name of the input data file and read it. The main method should attempt to open the file. If the file does not exist or there is problem in opening the file, report an error and exit. Else, process the file.
c. After all the major records are read, sort the array of Major objects in decreasing order of startSalary2014.   Finally, print the top 10 and bottom 10 earners. Notice the order of printing of the bottom 10 earners.

1. Create a BlueJ project named LAB09 as follows:
a. Open the P drive and create a folder named BlueJ, if it does not exist already. Under this folder, create another subfolder named CSC203 for this course, if it does not exist already.
b. Launch BlueJ and create a BlueJ project named LAB09 under the CSC203 folder mentioned in the previous step.

2. Create a class named Major. Open the editor and delete all the code placed in it automatically by BlueJ. Choose Options and Preferences and then check Display Line Numbers. Also, choose the options Class and Page Setup... and set the Orientation to Landscape. Use a web browser, access the class site on Blackboard, locate the file named Major.java, open it, copy and then paste it as code for the class Major. Replace my name with that of yours and change the date suitably Make sure to delete blank lines on top and bottom. Complete the code:
• Declare the instance variables.
• Write the constructor method with three parameters as described in the previous page.
• Write the four getter methods.
3. Compile the code. One of the major advantages to using the BlueJ IDE is that the code for the Major class can be tested interactively without having to develop an application code (like TopEarner.java) presented later. In the project window, right mouse click on the class and choose the constructor which contains the word new. In the pop up window, type computerScience as the instance name and type 67300, 64800, and "Computer Science" as three parameters.
a. The computerScience object will be created in the work bench. Inspect the instance variables associated with the object. First right mouse click on the object and choose inspect. Ensure that the values are as they should be. In particular, see that the percentIncrease is computed as 3.8580...
b. On the computerScience object, choose the toString method and inspect the returned String. Specifically, see how the salary figures and percentIncrease are formatted by the use of methods in the DecimalFormat class.
4. Create a class named TopEarner. Open the editor and delete all the code placed in it automatically by BlueJ. Use a web browser, access the class site on Blackboard, locate the file named TopEarner.java, open it, copy and then paste it as code for the class TopEarner. Replace my name with that of yours and change the date suitably. Make sure to delete blank lines on top and bottom. The code for TopEarner class is incomplete. Write appropriate lines of code as indicated by the comment lines.
5. Open the P drive and create a folder named Data. Use a web browser, access the class site on Blackboard, locate the file named Salary.txt, open it, copy and then paste into Notepad. Save the Notepad file as Salary.txt under the folder Data in P drive. Run the program for two test cases:
• P:\Data\Salary.txt
• P:\Data\Salry.txt (file name misspelled)
6. After you are sure the program works fine and the output is what you need, clear the terminal window. In the terminal Window, choose Options and select Unlimited buffering and Clear screen at method call. Thus, the terminal window is automatically cleared when the TopEarner program is executed and the terminal window retains all test cases however many there are. Run the TopEarner program for the above test cases. Print the terminal window to an ADOBE pdf printer, in landscape orientation, and name the file TopEarnerOutput.pdf.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/**
*
* Data from National Association of Colleges and
* Employer's Surveys are used for starting salaries.
*
import java.text.*;
{
    // instance variables
    private int startSalary2014;
    private int startSalary2013;
    private double percentIncrease;
    private String description;
   
    /**
    * Constructor for objects of class Major
    */
    public Major(int startSalary2014, int startSalary2013, String description) {
       this.startSalary2014 = startSalary2014;
       this.startSalary2013 = startSalary2013;
       this.percentIncrease = 100.0 * (startSalary2014 - startSalary2013) / startSalary2013;
       this.description = description;
    }

   
    /**
    * getter methods
    */
    public int getStartSalary2014() {
       return startSalary2014;
    }
   
    public int getStartSalary2013() {
       return startSalary2013;
    }
   
    public double getPercentIncrease() {
       return...

By purchasing this solution you'll be able to access the following files:
Solution.docx, Solution.pdf and Solution.zip.

$45.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats