Draw a box for the program’s main() method at the top of the page
Write the text main within the box; this now represents the main method
Draw a box for each of the methods that main() calls. Position these below the box for main so that you can easily draw arrows from the bottom of main to the methods it calls
Write the name of each method within the box
Draw an arrow from main to the method’s box
Next to the line draw smaller arrows to indicate the data that will be passed to, or returned from, the method
import java.util.Scanner;
/*7.1pp arrarys of objects
* @author D
*
*/
public class CastingAgent {
// calculating the highest revenue actor
public static Actor mostValuableActor(Actor[] actors, int numActors) {
Actor highest = actors[0];//
for (int i = 1; i < numActors; i++) { if (actors[i].revenue() > highest.revenue()) {
highest = actors[i];
}
}
return highest;
}
// calculating the average revenue of a actor
public static double averageActorRevenue(Actor[] actors, int numActors) {
double average;// average num actor
int sum = 0;// store the sum of all actors
for (int i = 0; i < numActors; i++) { sum += actors[i].revenue(); } average = (double) sum / numActors;// the average length of the first num actor in the array return average; } // bulk add in actors public static int bulkAdd(Scanner in, Actor[] actors, int numActors) { for (int i = 0; i < numActors; i++) { actors[i] = readActor(in); } return numActors; } // add actor length public static int addActor(Scanner in, Actor[] actors, int numActors) { if (numActors < actors.length) {// condition actors[numActors] = readActor(in); numActors++; } else { System.out.println("No more room in the actors."); } return numActors; } // displays all the actors public static void displayAll(Actor[] actors, int numActors) { for (int i = 0; i < numActors; i++) { System.out.println(actors[i]); } } // read the value typed by the user public static Actor readActor(Scanner in) { String name;// display actor name int memberId;// display actor memberid int revenue;// record the revenue of actor // actor input menu System.out.print("Name: "); name = in.next(); System.out.print("Member ID: "); memberId = in.nextInt(); in.nextLine(); System.out.print("Revenue: "); revenue = in.nextInt(); while (revenue < 0) {// condition System.out.print("Revenue must be 0 or larger! Try again: "); revenue = in.nextInt(); } return new Actor(name, memberId, revenue);// return value } public static void main(String[] args) { // Create a constant for the maximum number of actors (i.e. 50) final int CAPACITY = 50; // Create an array to store the actors Actor[] actors = new Actor[CAPACITY]; // Create a variable to store the number of actors in the array int numActors = 0; // // ...show the user a menu. int choice = 0;// // Create a Scanner object Scanner in = new Scanner(System.in); System.out.println("Casting Agent"); // Read in the number of actors the user wants to enter in bulk initially (store // the number in numActors, then... System.out.print("Enter initial number of entries (< " + CAPACITY + "): "); numActors = in.nextInt(); in.nextLine(); // calling math.min method // prints the minimum of two numbers numActors = Math.min(numActors, CAPACITY); // call your bulkAdd method to handle that, and then... numActors = bulkAdd(in, actors, numActors); do { // Display a menu System.out.println("1. Add another actor"); System.out.println("2. Display all actors"); System.out.println("3. Display most valuable actor"); System.out.println("4. Display average actor revenue"); System.out.println("5. Quit"); System.out.print("Enter option: "); choice = in.nextInt(); in.nextLine(); System.out.println(); // Process the user's choice switch (choice) { case 1: // Add another actor numActors = addActor(in, actors, numActors); break; case 2: // Display all actors displayAll(actors, numActors); break; case 3: // Display most valuable actor System.out.println("Most valuable actor: " + mostValuableActor(actors, numActors)); break; case 4: // Display average actor revenue System.out.println("Average actor revenue: " + averageActorRevenue(actors, numActors)); break; case 5: // Quit break; default: System.out.println("Invalid choice"); } System.out.println(); } while (choice != 5); } }