Question

in java PART ONE ================================================== Write a program that will read employee earnings data from an...

in java

PART ONE ==================================================

Write a program that will read employee earnings data from an external file and then sort and display that data. Copy and paste the input file data below into an external file, which your program will then read.

You will want to use parallel arrays for this program.

Modify the select sort algorithm to receive both arrays as parameters as well as the size of the arrays. Use the algorithm to sort your earnings array. When your select sort algorithm swaps elements in the earnings array, it must also swap elements in the parallel names array. That's why you have to send both arrays to the select sort function, along with the count of lines.

Your output should be:

          Jerry    156.75
           Jack    192.50
            Jay    199.90
         Joshua    311.15
        Jessica    320.35
          Julia    325.50
       Jeremiah    338.50
          Jaden    344.50
       Jennifer    354.75
           Joel    355.50
           Josh    360.60
           Jean    364.25
          Jacob    365.50
          Jamal    366.50
          Janet    460.75
      Josephine    500.00
         Justin    540.00
         Jeremy    540.25
        Jackson    555.50
          James    590.00
          Jason    590.90
         Jayden    600.00
       Jonathan    610.10
         Joseph    650.50
         Joanne    655.25
          Jamie    659.90
     Jacqueline    750.90
         Jasmin    765.50
        Justine    870.25
         Jessie    875.50
       Jeanette    881.75
        Jasmine    901.10
           John    990.90

The input file:

Jean 364.25
Janet 460.75
Jerry 156.75
Jamal 366.50
Joanne 655.25
Justin 540.00
Justine 870.25
Jackson 555.50
Jennifer 354.75
Jeanette 881.75
Jeremy 540.25
Jeremiah 338.50
Jack 192.50
Jacob 365.50
Jessica 320.35
James 590.00
Joshua 311.15
Jamie 659.90
Jayden 600.00
Julia 325.50
Jasmine 901.10
John 990.90
Josh 360.60
Joseph 650.50
Joel 355.50
Jay 199.90
Jaden 344.50
Jasmin 765.50
Jason 590.90
Jessie 875.50
Josephine 500.00
Jonathan 610.10
Jacqueline 750.90

PART TWO =======================================================

Write a program which will populate an integer ArrayList with user input, and then provide a menu of various operations to perform on that ArrayList.

The first step is to have the user push a bunch of integers into a ArrayList. The second step is to perform various operations on that ArrayList. Your input must be in the format below. The user can enter either a positive integer or -99 to quit. The menu to present is:

  1. Sum the ArrayList elements
  2. Sum the square of each element
  3. Display the smallest element
  4. Display the largest element
  5. Create a new ArrayList and start over
  6. Quit the program

Your output should resemble the example below:

Let's populate the ArrayList. Enter a number: 50
Enter your next number or -99 to quit: 42
Enter your next number or -99 to quit: 63
Enter your next number or -99 to quit: 126
Enter your next number or -99 to quit: 81
Enter your next number or -99 to quit: 86
Enter your next number or -99 to quit: 9
Enter your next number or -99 to quit: 39
Enter your next number or -99 to quit: 116
Enter your next number or -99 to quit: -99

Your ArrayList is: 50 42 63 126 81 86 9 39 116 
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 1
Your ArrayList: 50 42 63 126 81 86 9 39 116 
Sum of the ArrayList: 612

Your ArrayList is: 50 42 63 126 81 86 9 39 116 
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 2
Your ArrayList: 50 42 63 126 81 86 9 39 116 
Sum of the square of each ArrayList element: 53124

Your ArrayList is: 50 42 63 126 81 86 9 39 116 
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 3
Your ArrayList: 50 42 63 126 81 86 9 39 116 
Smallest ArrayList element: 9

Your ArrayList is: 50 42 63 126 81 86 9 39 116 
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 4
Your ArrayList: 50 42 63 126 81 86 9 39 116 
Largest ArrayList element: 126

Your ArrayList is: 50 42 63 126 81 86 9 39 116 
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 5

Let's populate the ArrayList. Enter a number: 50
Enter your next number or -99 to quit: 50
Enter your next number or -99 to quit: -99

Your ArrayList is: 50 50 
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 6
Program ending.

PART THREE==================================================

Write a program that will populate an ArrayList with positive integers that the user enters. When the user is done entering integers, they enter -99 to quit. Your program then prints out that original ArrayList in a simple format.

Then present the user with a menu choice: select 1 for evens and 2 for odds. Your program then will add numbers from the original ArrayList into a second ArrayList, but in reverse order, and only the evens/odds that the user picked.

This program will ask you to enter numbers into an ArrayList until
you quit; it will then push only those even/odd numbers (you pick)
in reverse into a separate ArrayList.

Enter a positive integer or -99 to quit: 50
Enter your next positive integer or -99 to quit: 53
Enter your next positive integer or -99 to quit: 56
Enter your next positive integer or -99 to quit: 59
Enter your next positive integer or -99 to quit: 62
Enter your next positive integer or -99 to quit: 65
Enter your next positive integer or -99 to quit: 68
Enter your next positive integer or -99 to quit: 71
Enter your next positive integer or -99 to quit: 74
Enter your next positive integer or -99 to quit: q
Original ArrayList:
50 53 56 59 62 65 68 71 74 
Select: (1) Evens
        (2) Odds --> 1
Reversed ArrayList with only evens:
74 68 62 56 50

PART FOUR ====================================================

Design a set of classes that work together to simulate a police office issuing a parking ticket. Design the following classes:

  • ParkedCar Class: simulates a parked car. This class needs to know the car's make, model, color, license plate number, and the number of minutes that the car has been parked.
  • ParkingMeter Class: simulates a parking meter. Needs to know the number of minutes that has been purchased for parking time.
  • ParkingTicket Class: simulates the actual parking ticket. Needs:
    • to report the make, model, color, and license plate number of the illegally parked car.
    • to report the amount of the fine, which is $25 for the first hour or part of an hour that the car is illegally parked, plus $10 for every additional hour or part of an hour.
    • to report the name and badge number of the police officer issuing the ticket
  • PoliceOfficer Class: simulates the police officer. Needs to know the officer's name and badge number. The police officer examines a ParkedCar object and a ParkingMeter object and determine if the car's meter has expired. The police officer then issues a parking ticket (i.e. generates a ParkingTicket object) if the car's time has expired.

Write a demo program to show how these classes collaborate.

UML's:

/*
-----------------------------------------
Parked Car Class
-----------------------------------------
- make : String
- model : String
- color : String
- plate: String
- minutesParked : int
-----------------------------------------
+ ParkedCar(mk: String, mod: String,
     col: String, lic: String, min: int)
+ ParkedCar(car2 : ParkedCar)
+ (setters and getters as needed)
+ toString() : String
-----------------------------------------
*/

/*
-----------------------------------------
ParkingMeter Class
-----------------------------------------
- minutesPurchased : int
-----------------------------------------
+ ParkingMeter(m : int)
+ setMinutesPurchased(m : int) : void
+ getMinutesPurchased() : int
-----------------------------------------
*/

/*
-----------------------------------------
PoliceOfficer Class
-----------------------------------------
- name : String
- badge : String
-----------------------------------------
+ PoliceOfficer(n: String, bn: string)
+ PoliceOfficer(officer2 : PoliceOfficer)
+ patrol(car: ParkedCar, meter: ParkingMeter):
      ParkingTicket
+ (setters and getters as needed)
+ toString() : String
*/

/*
-----------------------------------------
ParkingTicket Class
-----------------------------------------
- car: ParkedCar
- officer: PoliceOfficer
- fine: double
- minutes: int
+ BASE_FINE: double = 25.0
+ HOURLY_FINE: double = 10.0
-----------------------------------------
+ ParkingTicket(aCar: ParkedCar, 
     anOfficer: PoliceOfficer, min: int)
+ ParkingTicket(ticket2 : ParkingTicket)
+ calculateFine() : void
+ (setters and getters as needed)
+ toString() : String
*/
0 0
Add a comment Improve this question Transcribed image text
Answer #1

There are four parts given in the question, which are not inter connected. Infact these are four questions posted as one.

Please find the solution for the First question. In the below Java code I Have implemented the selection sort algorithm for the given question. Have not answered the other parts/quesions.

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Scanner;

public class SelectionSort
{
    void sort(float earnings[],String names[])
    {
        int n = earnings.length;

        // One by one move boundary of unsorted subarray
        for (int i = 0; i < n-1; i++)
        {
            // Find the minimum element in unsorted array
            int min_idx = i;
            for (int j = i+1; j < n; j++)
                if (earnings[j] < earnings[min_idx])
                    min_idx = j;

            // Swap the found minimum element with the first
            // element
            float temp = earnings[min_idx];
            earnings[min_idx] = earnings[i];
            earnings[i] = temp;
          
            String tempName = names[min_idx];
            names[min_idx]=names[i];
            names[i]=tempName;
        }
    }

    // Prints the array
    void printArray(String names[],float earnings[])
    {
        int n = earnings.length;
        for (int i=0; i<n; ++i)
            System.out.print(names[i]+" "+earnings[i]+"\n");
        System.out.println();
    }

    // Driver code to test above
    public static void main(String args[]) throws IOException
    {
      
       Path path = Paths.get("C:\\Users\\msounda6\\Projects\\Cg\\earnings.txt");

       //Using scanner to read the input from File
       Scanner scanner = new Scanner(path);
       String [] arr1 = new String[2];
       String [] names=new String[33];
       float [] earnings=new float[33];
      
       System.out.println("Read text file using Scanner");
       //read line by line
       int count=0;
       while(scanner.hasNextLine()){
            //process each line
           String line = scanner.nextLine();
            arr1=line.split(" ");
          
            names[count]=arr1[0];
            earnings[count]=Float.parseFloat(arr1[1]);
          
            count++;
           // System.out.println(line);
       }
       scanner.close();
      
//       for (int i=0;i<names.length;i++)
//       {
//           System.out.println(names[i]);
//           System.out.println(earnings[i]);
//       }
      
        SelectionSort ob = new SelectionSort();

        ob.sort(earnings,names);
        System.out.println("Sorted array");
      
        ob.printArray(names,earnings);
    }
}

Add a comment
Know the answer?
Add Answer to:
in java PART ONE ================================================== Write a program that will read employee earnings data from an...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

  • I need it in JAVA Write a program that randomly populates an array of size 100,...

    I need it in JAVA Write a program that randomly populates an array of size 100, sorts it, and then finds the median. The random numbers must be from 0-99 and all integer values. Also since there is an even set of numbers the median is found by taking the mean of the two middle numbers (In other words the 50th and 51st). You have to code your own sorting method. You may not use a built in java sorter....

  • JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts...

    JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. "Out of Bounds") and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle...

  • write a java program Accept a positive integer n from keyboard and then create an array...

    write a java program Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...

  • In Java, using only recursion. Ask the user for a list of integers. Display the greatest...

    In Java, using only recursion. Ask the user for a list of integers. Display the greatest number in the sequence. Allow any non-integer to end the input. DO NOT USE LOOPS. We are currently learning recursion and can only use recursion. Please provide notes so to better understand. Please describe how inputting a string will end the input section and then go on to execute what number is greater within the entire user input. -------------------------------------------------------------------------------- Standard Input                 5 20...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT