What am i missing in....Add an item: Ask the user to enter all the information f
ID: 3568772 • Letter: W
Question
What am i missing in....Add an item: Ask the user to enter all the information for the item, if there is room, add it to the arrays and output a message that the item has been added. If the arrays are already full, just display an appropriate message. If the item was added, be sure to update the variable that is tracking the number of items in your arrays.
public static int addBall(String[] hookPotentialArray, String[] nameBallArray, int[] ballWeightArray, int count) {
if (count < hookPotentialArray.length){
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the name of the ball: ");
String ballName = keyboard.nextLine();
System.out.println("Please enter the weight of the ball: ");
int ballWeight = keyboard.nextInt();
System.out.println("Please enter the hook potential of the ball: ");
String hookPotential = keyboard.next();
nameBallArray[count] = ballName;
ballWeightArray[count] = ballWeight;
hookPotentialArray[count] = hookPotential;
System.out.println("The ball you have added has been added. ");
System.out.println("");
count++;
}
return count;
}
Explanation / Answer
public static int addBall(String[] hookPotentialArray, String[] nameBallArray, int[] ballWeightArray, int count) {
if (count < hookPotentialArray.length){
System.out.println("You are about to add an entry to the array ");
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the name of the ball: ");
String ballName = keyboard.nextLine();
System.out.println("Please enter the weight of the ball: ");
int ballWeight = keyboard.nextInt();
System.out.println("Please enter the hook potential of the ball: ");
String hookPotential = keyboard.next();
nameBallArray[count] = ballName;
ballWeightArray[count] = ballWeight;
hookPotentialArray[count] = hookPotential;
System.out.println("The ball you have added has been added. ");
System.out.println("");
count++;
}
else
{
System.out.println("Array is already full !!");
}
return count;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.