Try Magic Notes and save time.Try it free
Try Magic Notes and save timeCrush your year with the magic of personalized studying.Try it free
Question

A university posts its employees’ salaries at http://cs.armstrong.edu/liang/data/Salary.txt. Each line in the file consists of a faculty member’s first name, last name, rank, and salary Write a program to display the total salary for assistant professors, associate professors, full professors, and all faculty, respectively, and display the average salary for assistant professors, associate professors, full professors and all faculty, respectively.

Solution

Verified
Answered 2 months ago
Answered 2 months ago
Step 1
1 of 5
import java.io.File;
import java.io.FileNotFoundException;
import java.text.DecimalFormat;
import java.util.Scanner;

public class Process {
    public static void main(String[] args) throws FileNotFoundException {
        DecimalFormat df2 = new DecimalFormat("#.##");

        double assistantT = 0, associateT = 0, fullT = 0;
        int assistantC = 0, associateC = 0, fullC = 0;
        //URL url = new URL("http://cs.armstrong.edu/liang/data/Salary.txt");
        //Scanner input = new Scanner(url.openStream());
        Scanner input = new Scanner(
            new File("12_Chapter\\25_Process_dataset\\Salary.txt"));

        while (input.hasNextLine()) {
            String line;
            line = input.nextLine();
            String[] attributes = line.split("\\s+");
            
            switch (attributes[2]) {
                case "assistant":
                    assistantC++;
                    assistantT += Double.parseDouble(attributes[3]);
                    break;
                case "associate":
                    associateC++;
                    associateT += Double.parseDouble(attributes[3]);
                    break;
                case "full":
                    fullC++;
                    fullT += Double.parseDouble(attributes[3]);
                    break;
            }
        }

Create an account to view solutions

Create an account to view solutions

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263David A. Patterson, John L. Hennessy
226 solutions
Intro to Java Programming, Comprehensive Version 10th Edition by Y. Daniel Liang

Intro to Java Programming, Comprehensive Version

10th EditionISBN: 9780133761313Y. Daniel Liang
1,628 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
895 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
849 solutions

More related questions

1/4

1/7