Java Question: Consider the following array of numbers : Plaver ID Points Assist
ID: 3860991 • Letter: J
Question
Java Question:
Consider the following array of numbers :
Plaver ID Points Assists Rebounds 23 12 15 10 12 23 12 10 20 10 A triple double occurs when a particular player (represented by player ID), has double digit numbers (>=10 in 3 categories (represented by the columns entitled: Points, Assists, Rebounds). In the above example, Players 1 and 3 achieved triple doubles, however, Player 2 did not. Write a program that continually allows a user to input a player ID, determine whether that player achieved a triple double, and print out if they did indeed achieve a triple double. * If the user enters a -1, the program will print "Thanks for playing" and exit If the user enters a valid Player ID, print their Player ID and triple double statu:s Bonus (3 marks): If the user enters a Player ID that is not within the provided 2D Array, print out "This Player ID is NOT VALID, please try again" » Example Console Output: Program >> Enter a Player ID User>>12 Program >> Player ID 1 did not achieve a triple double Program >> Enter a Player ID User >> 23 Program >> Player ID 23 achieved a triple double Program >> Enter a Player ID User>>1 Program >> Player ID 1 is NOT VALID, please try again Program >> Enter a Player ID User >>-1 Program >> Thanks for playing. EXIT DEMO the above output to your TA. The bolded part is necessary to obtain full marks. You can use the below array to test your code: int [][ ] playerData - 123,23,15,12),(12,9,10,10),(8,10,12,20));Explanation / Answer
FindPlayerId.java
import java.util.Scanner;
public class FindPlayerId {
public static void main(String[] args) {
//Declaring variables
int id, index;
boolean bool1;
//Declaring a 2-D Array
int[][] playerData = {{ 23, 23,15, 12 }, {12, 9, 10,10 }, { 8, 10,12, 20 } };
//Scanner object is used to get the inputs entered by the user
Scanner sc = new Scanner(System.in);
/* This while loop continues to execute
* until the user enters a '-1' as input
*/
while (true) {
//Getting the id entered by the user
System.out.print("Enter a player id :");
id = sc.nextInt();
if (id == -1) {
System.out.println("Thanks for playing.");
break;
} else {
/* Calling the method to check whether
* the user entered ID is valid or not
*/
index = isValid(playerData, id);
if (index == -1) {
System.out.println("player ID " + id + " is NOT VALID, please try again");
} else if (index != -1) {
bool1 = isTripleDouble(playerData, id, index);
if (bool1) {
System.out.println("Player ID " + id + " achieved a triple double");
} else {
System.out.println("Player ID " + id + " did not achieved a triple double");
}
}
}
}
while (id != -1);
}
/* Calling the method to check whether
* the Id achieved Double Triple or not
*/
private static boolean isTripleDouble(int[][] playerData, int id, int index) {
for (int i = 0; i < playerData.length; i++) {
if (playerData[index][i] < 10)
return false;
}
return true;
}
/* Calling the method to check whether
* the Id is valid or not
*/
private static int isValid(int[][] playerData, int id) {
int index;
for (int i = 0; i < playerData.length; i++) {
if (playerData[i][0] == id)
return i;
}
return -1;
}
}
_______________________
Output:
Enter a player id :12
Player ID 12 did not achieved a triple double
Enter a player id :23
Player ID 23 achieved a triple double
Enter a player id :1
player ID 1 is NOT VALID, please try again
Enter a player id :-1
Thanks for playing.
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.