Question

In this project, you will write a Java program that randomly generates annual salaries for professors...

In this project, you will write a Java program that randomly generates annual salaries for professors
in the Computer Science and Engineering Technology (CSET) program at the University of Toledo
in the past 10 years. Assume that there are five CSET professors. You should have a twodimensional array of values representing salaries. The first dimension represents the professors
and the second dimension represents the years of the salaries. You should have a constructor that
takes two integers representing the number of professors and the number of years, then randomly
generate the salaries and fill the array.
You should include the following methods.
✓ A method returning the index of the professor that made the least salary over the 10 years
✓ A method returning the average salary made by all the professors over the 10 years
✓ A method returning the year when the lowest salary was earned
✓ A method returning the total amount of money made by all the professors over the 10 years
Deliverables
1) Clearly written and well-documented java code. The code must provide a description of what
the code accomplishes. Comments must be provided in the code as needed. (20 Points).
2) A technical project report that outlines the processes involved in writing the code, how the
concepts learned in class were helpful in the project, clear milestones from start to finish of the
project, challenges and how you overcame them. (5 Points)
Grading Criteria
1) Does the code achieve the stated objective accurately and without any error?
2) Does the code have well-written comments to guide the reader?
3) Does the code flow logically from one point to the next
4) Is the code lean, clean, and elegant?
6) Are the variables well defined?
7) Does the code follow the java naming convention?

Homework Answers

Answer #1

The following is the code for above question. This code has met all the requirements that are stated in the question.

import java.util.*;
public class Main  // java class with name Main
{  private static int professors, years; //Declare the variables professors and years as private static of type int. Declaring static will help us to access them in static methods.
   private static int[][] salary;  //Two-Dimensional array to store salaries of professors over past years
    Main(int professors,int years)  //Constructor passing number of professors and years
    {
       this.professors=professors;
       this.years=years;
       this.salary=new int[professors][years]; //we will now declare the size of salary 2d array
       for(int i=0;i<professors;i++) //Now generate the random salaries when the Constructor is called.
       {
           for(int j=0;j<years;j++)
           {
               salary[i][j]=(int)(Math.random() * (50000 - 35000 + 1) + 35000); //Here 50000 is the max value and 35000 is the min value
           }
       }
    }
    public static int least_salary()  //method to return the index of professor having least salary
    { int min,index=0;
         min=salary[0][0]; //we first initialize min with salary[0][0]
        for(int i=0;i<professors;i++)
        {
            for(int j=0;j<years;j++)  //over the loop
            {
                if(min>salary[i][j])  // if there is any value which is less tha min, the update the min value with salary[i][j]
                {
                    min=salary[i][j];
                    index=i+1;  //Also update the index value.
                }
            }
        }
        return index;  //return professor index value
    }
    public static double average_salary()  //function to calculate the average salary
    {
        double sum=0,avg;  //initialize sum=0
        for(int i=0;i<professors;i++)
        {
            for(int j=0;j<years;j++)
            {
                sum=sum+salary[i][j];  //add salaries of professors to sum
            }
        }
        avg=sum/professors; //Now average_salary will be the sum divide by number of professors
        return avg;  //return avg
    }
    public static int lowest_salary_year()  //function to calculate the lowest_salary_year
    {
     int min,year=0;
         min=salary[0][0];
        for(int i=0;i<professors;i++)
        {
            for(int j=0;j<years;j++)
            {
                if(min>salary[i][j])   //if min is > salary, then update the min value. Also the year value
                {
                    min=salary[i][j];
                    year=j+1;        //Now its j not i. Because in our 2d array j represents year.
                }
            }
        }
        return year;  
    }
     public static double total_salary()  //functiom to calculate total_salary
    {
        double sum=0;
        for(int i=0;i<professors;i++)
        {
            for(int j=0;j<years;j++)
            {
                sum=sum+salary[i][j];  //add salary to sum
            }
        }
        return sum;
    }
        public static void main(String[] args) {  //main function
                    Main professor=new Main(4,5);  //create an object professor with number od professors as 4 and years as 5
                    System.out.println("The index value of professor having least salary is "+professor.least_salary());
                    System.out.println("The average salary of all the professors is "+professor.average_salary());
                    System.out.println("The index value of year having lowest salary is "+professor.lowest_salary_year());
                    System.out.println("The total salary of all the professors is "+professor.total_salary());
        }
}

The above code will create a 2-dimensional array of type int to store salaries of professors over the years. The functions created will help us to calculate average salary, professor with least salary, year with lowest salary and sum of the salaries of all the professors which are randomly generated.

I am also attaching the output for your reference.

Output:

The index value of professor having least salary is 1
The average salary of all the professors is 218086.5
The index value of year having lowest salary is 4
The total salary of all the professors is 872346.0

#Please dont forget to upvote if you find the solution helpful. Feel free to ask doubts if any, in the comments section. Thank you.


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Java program that randomly generates an array of 500,000 integers between 0 and 499,999,...
Write a Java program that randomly generates an array of 500,000 integers between 0 and 499,999, and then prompts the user for a search key value. Estimate the execution time of invoking the linearSearch method in Listing A below. Sort the array and estimate the execution time of invoking the binarySearch method in Listing B below. You can use the following code template to obtain the execution time: long startTime = System.currentTimeMillis(); perform the task; long endTime = System.currentTimeMillis(); long...
Please write a java program Instructions Your goal is to take N integer inputs from the...
Please write a java program Instructions Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
Hi, I need this program written in Java for my intro CS class. Thank you in...
Hi, I need this program written in Java for my intro CS class. Thank you in advance. (also here is the description given in class for the code) Write a program that displays all the leap years, ten per line, from 101 to 2100, separated by exactly one space. Also display the number of leap years in this period. - You should use the method isLeap which returns "true" if the year is a leap year, otherwise it should return...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
JAVA PROGRAMMING: Write a program called TimeSymbolTables that creates three symbol tables, each of a different...
JAVA PROGRAMMING: Write a program called TimeSymbolTables that creates three symbol tables, each of a different implementation. Each symbol table will contain as a key a word read from a text file and as a value the number of times that word occurs in the text file. Have the program fill the first symbol table with these counts, keeping track of how long that takes using a Stopwatch object. It then does the same thing with the second symbol table....
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. // A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. // At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use the file in.txt as sample input for your program. v import java.io.*; import java.util.*; public class Pretty { public static final int LINE_SIZE = 50; public static void main(String[] parms) { String inputLine; int position = 1; Scanner fileIn = new Scanner(System.in); while (fileIn.hasNextLine()) { inputLine = fileIn.nextLine(); if (inputLine.equals("")) { if (position > 1) { System.out.println(); } System.out.println(); position = 1; } else...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT