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

So I have this assignment and I can\'t seem to make heads and tails of this. I a

ID: 3635278 • Letter: S

Question

So I have this assignment and I can't seem to make heads and tails of this. I am supposed to have 3 separate programs that are supposed to inherit from each other. There is one for the ball, one for the board, and a test class that puts it all together. I was able to get it started in one file and I can't seem to break it apart. Basically, I have to have the number of balls dropped, 2 - 20 slots (which it will tell you if you are outside of the 2 - 20). From there I have to say which way it bounces (left or right), and which slot it lands in . IE slot 1 : 0 slot 2 : 2 etc. Here is what I have so far. Any help is appreciated because I am totally deadlocked right now and its driving me nuts! Thanks and I will rate you as a lifesaver.

import java.util.Scanner;
import java.util.Random;

public class Ball
{

public static void main(String[] args)
{

Scanner input = new Scanner(System.in);

int slotNumber;

int ball = BallNumber();

int slot = Slot_Number();
int [] slots = new int[slot];

for(int i = 0;i < ball;i++)
{
slot_Number = direction(slot);

for(int n = 0;n < slots.length;n++)
{
if(slot_Number == n)
{
slots[n]++;
}
}
}

displayBalls(ball,slots);
}

public static int SlotNumber ()
{
Scanner input = new Scanner(System.in);

System.out.print("Please enter the number slots [2-20]:");

int slot = input.nextInt();
return slot;
}

public static int BallNumber ()
{
Scanner input = new Scanner(System.in);

System.out.print("Please enter the number balls to drop: ");

int slots = input.nextInt();

return slots;
}

public static int direction(int slots)
{
int direction;
int right = 0;

for(int i = 2; i <= slots; i++)
{
direction = (int)(Math.random() * 2);

if(direction==0){
System.out.print("L");
}
else
{
System.out.print("R");
right++;
}
}
System.out.println();

return right;
}
}

Explanation / Answer

Hi I'm not sure if you've done deeper OOP Java otherwise breaking your program up into classes would be a lot easier. Ok I can give you a brief description of what I think you should do according to what I understood. Make a Ball class you know where you have a: public class ball{ public ball(){ //constructor } } Anything to do with the ball, put in that class. Such as storing if the ball went left or right, put in a variable in your ball class. Because you set whether the ball went left or right only once and that too only when you first use the ball, you can have that as your constructor parameters. There is no need for a setter method for that variable as you only use it once. Make a getter method if you need to know the direction later on. Do this for each of the variables you think you need. From what I can see, you can add a variable for direction, and I guess a slot number variable. What I see in your code up there, is you make a function call "displayBalls(ball, slots)", I don't see that code anywhere. Whatever your intentions are with that function, I think it should be in your "board" class. So make a Board class, this should hold information such as the slots, or whatever, and should also include the methods that you have in your main class. If they relate to something the board does, stick them in the board class. Leave your main class to only run the program, so things like ask for input, display output and all that stuff. I hope this helps, I really would have liked to show you some code but I don't fully understand the requirements of the program, more so how to implement my understanding in a way that suffices what you may be required to do.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote