Question: I need help with this programming assignment i am stuck on the if else staments can someone please input those in? and can you guys
I need help with this programming assignment i am stuck on the if else staments can someone please input those in? and can you guys do it in the same language not using abriviations please
import java.util.Scanner public class PlayerRoster { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); final int NUM_PLAYERS = 5; int[] jerseyNums = new int[NUM_PLAYERS]; int[] ratingNums = new int[NUM_PLAYERS]; int i = 0; int j = 0; int playerJersy = 0; int playerRating = 0; char menuOp = '-'; // Get user defined jersey numbers and ratings for (i = 0; i < NUM_PLAYERS; ++i) { System.out.println("Enter player " + (i + 1) + "'s jersey number:"); jerseyNums[i] = scnr.nextInt(); System.out.println("Enter player " + (i + 1) + "'s rating:"); ratingNums[i] = scnr.nextInt(); System.out.println(""); } // Print roster System.out.println("ROSTER"); for (i = 0; i < NUM_PLAYERS; ++i) { System.out.println("Player " + (i + 1) + " -- Jersey number: " + jerseyNums[i] + ", Rating: " + ratingNums[i]); } // Menu do { System.out.println(" MENU"); System.out.println("u - Update player rating"); System.out.println("a - Output players above a rating"); System.out.println("r - Replace player"); System.out.println("o - Output roster"); System.out.println("q - Quit"); System.out.println(" Choose an option:"); menuOp = scnr.next().charAt(0);
//Update if (/* complete the conditional expression */) { System.out.println("Enter a jersey number:"); playerJersy = scnr.nextInt(); System.out.println("Enter a new rating for player:"); playerRating = scnr.nextInt(); for (i = 0; i < NUM_PLAYERS; ++i) { if (jerseyNums[i] == playerJersy) { ratingNums[i] = playerRating; } } } // Output players above a user defined rating else if (/* complete the conditional expression */) { System.out.println("Enter a rating:"); playerRating = scnr.nextInt(); System.out.println(" ABOVE " + playerRating); for (i = 0; i < NUM_PLAYERS; ++i) { if (ratingNums[i] > playerRating) { System.out.println("Player " + (i + 1) + " -- Jersey number: " + jerseyNums[i] + ", Rating: " + ratingNums[i]); } } } // Replace else if (/* complete the conditional expression */) { System.out.println("Enter a jersey number:"); playerJersy = scnr.nextInt(); j = -1; // Default index for player replacement for (i = 0; i < NUM_PLAYERS; ++i) { if (playerJersy == jerseyNums[i]) { j = i; } }
// Replace player only if the player is in the roster if (j != -1) { System.out.println("Enter a new jersey number:"); playerJersy = scnr.nextInt(); System.out.println("Enter a rating for the new player:"); playerRating = scnr.nextInt(); jerseyNums[j] = playerJersy; ratingNums[j] = playerRating; } } // Output roster else if (/* complete the conditional expression */) { System.out.println("ROSTER"); for (i = 0; i < NUM_PLAYERS; ++i) { System.out.println("Player " + (i + 1) + " -- Jersey number: " + jerseyNums[i] + ", Rating: " + ratingNums[i]); } } } while(/* complete the conditional expression */); return; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
