Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in Java. i think you need just 2 classes so I\'ll provide them please. you don\'

ID: 3914158 • Letter: I

Question

in Java. i think you need just 2 classes so I'll provide them please. you don't have to test just show me how please. Its commented //TODO



import java.io.FileNotFoundException;

import java.io.File;

import java.util.Scanner;

import lib280.list.LinkedList280;

public class PerformanceByRank {

public static LinkedList280<Crew> readCrewData(String path) {

Scanner infile = null;

try {

infile = new Scanner(new File(path));

}

catch (FileNotFoundException e) {

System.out.println("Error: File not found!");

}

// Initialize output list.

LinkedList280<Crew> pirateCrew = new LinkedList280<Crew>();

// While there is more stuff to read...

while(infile.hasNext()) {

// Read the three values for a Crew record

int rank = infile.nextInt();

double pay = infile.nextDouble();

int sacks = infile.nextInt();

// Create a crew object from the data

Crew c = new Crew(rank, pay, sacks);

// Place the new Crew instnace in the linked list.

pirateCrew.insertFirst(c);

}

// Close the input file like a good citizen. :)

infile.close();

// Return the list of Crew objects.

return pirateCrew;

}

public static void main( String args[] ) {

// Read the data for Jack's pirate crew.

// If you are getting a "File Not Found" error here, you may adjust the

// path to piratecrew.txt as needed.

LinkedList280<Crew> pirateCrew = readCrewData("A1-PirateCrew/piratecrew.txt");

        // TODO Write your solution here.

}

}

other class



/**

* This class stores information about one of Tractor Jack's pirate crew.

*/

public class Crew {

/**

* The crew member's rank

*/

protected int rank;

/**

* The crew member's guaranteed annual pay (number golden guineas)

*/

protected double pay;

/**

* The number of sacks of grain plundered by this crew member this year.

*/

protected int grainSacks;

public Crew(int rank, double pay, int grainSacks) {

this.rank = rank;

this.pay = pay;

this.grainSacks = grainSacks;

}

public int getRank() {

return rank;

}

public void setRank(int rank) {

this.rank = rank;

}

public double getPay() {

return pay;

}

public void setPay(double pay) {

this.pay = pay;

}

public int getGrainSacks() {

return grainSacks;

}

public void setGrainSacks(int grainSacks) {

this.grainSacks = grainSacks;

}

public String toString() {

return "Rank: " + new Integer(this.rank) + ", Pay: " + new Double(this.pay) + ", Plunder: " + new Integer(this.grainSacks);

}

}

My Drive Drive are equitable in the sense that he'd like his crew members at each rank to be paid about the same per sack of grain that they plunder. You will write a program to determine the total amount Jack paid his crew per sack of grain for each crew rank separately. If the amount paid per sack of grain plundered varies a lot over the different ranks, Jack may want to re-think his pay scale and his negotiation tactics In the provided file PerformanceByRank. java you are given code that reads a data file piratecrew.txt (provided) containing the pay data for all of Jack's crew. The data will be returned as a linked list of Crew objects of type LinkedList280. A Crew object contains the rank, annual pay (in golden guineas), and the number of sacks of grain plundered in the last year by a crew member. It has getters and setters for each of these three pieces of data. Cres. java defining this class is provided. In the main ) function of PerformanceByRank. java, write a program that does the following 1. Create an array piratesByRank of ten LinkedList280cCrew objects, one for each rank (you saw how to do this in Tutorial 1) 2. Initialize the elements of the array of linked lists piratesByRank. 3. Iterate through the list of Crew objects returned by readCrevData0 and add each Crew object to the list at offset r of piratesByRank, where r is the crew member's rank. 4. For each list, determine the amount paid to all of the crew members of that rank per sack of grain plundered by all of the crew members of that rank and print it to the console (see the sample output section, below). If a list is empty, instead print to the console a message that Jack has no pirates employed at that rank. You are not permitted to modify any of the provided code. Exception: you are allowed to modify the pathnam e to the input file piratecrew.txt in the event that you get a "file not found" error. Sample Output

Explanation / Answer

public static void main( String args[] ) {
// Read the data for Jack's pirate crew.
// If you are getting a "File Not Found" error here, you may adjust the
// path to piratecrew.txt as needed.
LinkedList280<Crew> pirateCrew = readCrewData("A1-PirateCrew/piratecrew.txt");
    LinkedList280<Crew>[] piratesByRank = new LinkedList280<Crew>[10];

    for (int i = 0; i<piratesByRank.length; i++){
        piratesByRank[i] = new LinkedList280<Crew>();
    }   

    for (int i = 0; i<pirateCrew.size(); i++){
        int j = pirateCrew.get(i).getRank();
        piratesByRank[j].add(pirateCrew.get(i))
    }

    for (int i = 0; i<10; i++){
        double sumSacks = 0;
        double amt = 0;
        for (int j = 0; j < piratesByRank[i].size(); j++){
            sumSacks = sumSacks + piratesByRank[i].get(j).getGrainSacks();
            amt = amt + piratesByRank[i].get(j).getPay();
        }
        double avg = sumSacks/amt;
        System.out.println("Jack's rank " + i + " crew member were paid of " + avg + " guineas per sack of graing plundered");
    }
}
}