The Student Room Group

Case Study help involving input data

Hi guys, i got a few question involving my case study

My Program should record dice throws in a bucket array until target dice is matched.

Add a code to allow storage of values entered in a bucket array - recording how many of each number was thrown

Write a method which prints the number of attempts taken to match the target dice
and then a table showing each number and how many times it was thrown.Send the frequency data to a file.

so far I have this

import javax.swing.JOptionPane;
class CaseStudy2
{
static int anArray[] = new int[6]; // declares the array
static String[] thisRoll = { "One", "Two", "Three", "Four", "Five", "Six"};

public static void main (String[] args)
{
anArray[0] = 0; // initialize first element
anArray[1] = 0; // initialize second element
anArray[2] = 0; // etc.
anArray[3] = 0;
anArray[4] = 0;
anArray[5] = 0;


inputdata();
displayData(anArray);
System.exit(0);

}



public static void inputdata (String[] args)
{

int thisRoll = 0;

final int TARGET = 6; // variable stating the target number being 6

while (thisRoll != TARGET )


String str;

str = JOptionPane.showInputDialog(null, "Roll the dice and enter the number: ");// ask the user to enter a number that was thrown on the dice

thisRoll = Integer.parseInt(dicenumber_string); // convert string to int

for ( int i = 0; i < anArray.length; i++ )
{
if (thisRoll == TARGET )// if statement if the target number (6) is met
{
anArray = anArray + dicenumber;
}
}
String[] yesno = {"No", "Yes"};
String again = (String) JOptionPane.showInputDialog(null, "Enter more values ?", "Again", JOptionPane.QUESTION_MESSAGE, null, yesno, yesno[0]);

if(again == "Yes")
{
inputdata();
}
}

public static void displayData(int[] anArray)
{

System.out.println("Number one was thrown " + anArray[0]);// this prints out the number of attempts the user got on the dice throw
System.out.println("Number two was thrown " + anArray[1]);
System.out.println("Number three was thrown " + anArray[2]);
System.out.println("Number four was thrown " + anArray[3]);
System.out.println("Number five was thrown " + anArray[4]);
System.out.println("Number six was thrown " + anArray[5]);



}
System.out.println("The number of attempts to match the target dice was " + ); //this is incompleted
}
}

my question is, how do i send the frequency data to a file and can someone recommend a way to print out the results showing the number of times the number was thrown (i have not completed it yet)

thanks
what is that?
Reply 2
TheNightmareSSJ3Broly
what is that?

A mess lol.
Gimmie 5 mins to look through.
You didnt reply to the other topic you made btw? If you understood and why it was a black screen that appeared...the black screen was where you input your values.

Anyways, i see a few improvements in your coding =).

EDIT:
Ok, just a few points and questions...
1. What java editor are you using?
2. Im sorry, your code is too incomplete for me to fix, well, i could but it'd take me more time then i'm willing to spend. Your calling methods with no arguments, you have additional brackets in places there should not be and you're using variables when you have not even declared them.

If you want us to help you need to at least give compilable code and then comment where you need help....i have no idea what you even want help with!

Latest

Trending

Trending