I am a adult returning student in Java and would really benefit from having someone work with me on exercises to further my understanding of the material. Anyone interested in helping would be greatly appreciated.

## All 7 Replies

Everyone would be glad to help if you show some individual effort. If you have a question, feel free to ask it, that's the whole point of this forum after all.

I appreciate the comment. I did all my work last semester but I don't know anyone outside the class and this is new to me so when I stumble it takes me far longer to resolve issues than it should. Like now, I am having problems with a problem. It was originally assigned and skipped over because of MLK but I wanted to work it anyhow. It is as follows:
In this lab you are going to extend the code you wrote in you first lab. You are going to add to the class Coin a variable value that represents the value of the coin in cents (e.g. can be 1, 5, 10, or 25). This value, together with the bias, should be specified as the constructor to the class Coin.

You are also going to create a new class Change that stores an array of Coin objects. The array of coins, which can be of arbitrary size, should be given as input parameter to the constructor of the class Change. Add to the class Change a toString() method that prints the coins in the change. An example return value of the method is “dime nickel tails quarter tails”, which means that the 3rd and 5th coin are tails and their values cannot be seen. Add a method flip(int i) to the class Change that flips the ith coin. Test the class Change by creating a third class called Game. In the main method of this class, create a random change of size 10 coins.

Show the change to the user and print the sum of the coins that are heads. Then allow the user to flip all the coin if they want to do so. If the user decides to flip the coins, show the new values for the coins and the new sum for the head coins. The goal of the game is to the get the highest possible sum for the value of the coins that are heads.
I completed the first assignment but I am not getting the array of objects part because the first exercise asked me to solicit from the user the bias so how do I incorporate this into the constructor. Would a copy of my first assignment help?

This is my 1st project from which the 2nd is supposed to build

import javax.swing.JOptionPane; //Import class for use of JOptionPane windows

``````public class Coin
{
private static double face;
private static double bias = .5;
final static int HEAD = 1;
final int TAILS =2;

public static void main(String[] args)	//Main method
{
int counter = 0;	//Local variable to control for loop
boolean data;		//Local variable to evaluate outcome of flip method
//
int input;			//Local variable to store JOP input
//					Solicits user to run the program
input = JOptionPane.showConfirmDialog(null, "Would you like to change the bias and run " +
"the program?", "Coin", JOptionPane.YES_NO_OPTION);
//
if (input == 1)	//Evaluates user choice as integer value
{				//JOP closes program based on choice of no option
JOptionPane.showMessageDialog(null, "The Coin Program Exits. Good Bye!",
"Program Terminates", JOptionPane.CANCEL_OPTION);
System.exit(0);	//Program terminates
}
//
while (input == 0)	//While loop begins based on yes
{
setBias();	//Calls method, passing no arguments
//
for (int i = 0; i <10; i++)	//For loop to toss the coin a set # of times
{
flip();	//Calls method, passing no arguments
data = isHead();	//Calls method, assigning to variable result of return
//
if (data == true)	//If statement to evaluate is toss is a HEAD
{
counter ++;		//If toss is HEAD, increment counter variable
}
}	//JOP tells user the result of the program at current bias
JOptionPane.showMessageDialog(null, "            You tossed HEADS " + counter + " times",
"Results", JOptionPane.PLAIN_MESSAGE);
//
counter = 0;	//Resets counter variable
//JOP prompts user to run the program again
input = JOptionPane.showConfirmDialog(null, "Would you like to change the bias and run " +
"the program?", "Coin", JOptionPane.YES_NO_OPTION);
}	//Given a choice of no by user, program terminates
JOptionPane.showMessageDialog(null, "The Coin Program Exits. Good Bye!",
"Program Terminates", JOptionPane.CANCEL_OPTION);
System.exit(0);	//Program terminates
}//End of Main
//

public static void flip()	//Method to control tossing of coin
{
double calc = 0;	//Local variable to create toss value
//
calc = 2 * (Math.random()) * (1 - bias);	//Assigns to calc variable the result of math
//											//formula to generate a random value of toss
if (calc <= .5)	//If statement evaluates generated number
{
face = 1;	//Assigns to face data field an integer value for comparison
}
else face = 2;	//Assigns to face data field an integer value for comparison
}//End of Method
//
public static boolean isHead()	//Method for comparing generated number to constant for HEAD
{
if (face == HEAD)	//If statement compares generated number to constant for HEAD
{
return true;	//Returns true to main method if values are equal
}
else return false;	//Returns false to main method if values are false
}//End of Method
//
public static void setBias()	//Method to allow user to change the bias value to HEAD
{
String biasInput;	//Local variable to accept user input from JOP
//Prompts user to change bias value
biasInput = JOptionPane.showInputDialog(null, "Input your desired bias value", "Bias Change",
JOptionPane.INFORMATION_MESSAGE);
bias = Double.parseDouble(biasInput);	//Parses bias value from string to double type
}//End of Method
}//End of Class``````

Post code in code tags. You'll notice the button that says 'code' right above the reply box, it makes it easier for us to help you. And welcome to the forums. :)

Thanks, is that better

``````import javax.swing.JOptionPane;	//Import class for use of JOptionPane windows

public class Coin
{
private static double face;
private static double bias = .5;
final static int HEAD = 1;
final int TAILS =2;

public static void main(String[] args)	//Main method
{
int counter = 0;	//Local variable to control for loop
boolean data;		//Local variable to evaluate outcome of flip method
//
int input;			//Local variable to store JOP input
//					Solicits user to run the program
input = JOptionPane.showConfirmDialog(null, "Would you like to change the bias and run " +
"the program?", "Coin", JOptionPane.YES_NO_OPTION);
//
if (input == 1)	//Evaluates user choice as integer value
{				//JOP closes program based on choice of no option
JOptionPane.showMessageDialog(null, "The Coin Program Exits. Good Bye!",
"Program Terminates", JOptionPane.CANCEL_OPTION);
System.exit(0);	//Program terminates
}
//
while (input == 0)	//While loop begins based on yes
{
setBias();	//Calls method, passing no arguments
//
for (int i = 0; i <10; i++)	//For loop to toss the coin a set # of times
{
flip();	//Calls method, passing no arguments
data = isHead();	//Calls method, assigning to variable result of return
//
if (data == true)	//If statement to evaluate is toss is a HEAD
{
counter ++;		//If toss is HEAD, increment counter variable
}
}	//JOP tells user the result of the program at current bias
JOptionPane.showMessageDialog(null, "            You tossed HEADS " + counter + " times",
"Results", JOptionPane.PLAIN_MESSAGE);
//
counter = 0;	//Resets counter variable
//JOP prompts user to run the program again
input = JOptionPane.showConfirmDialog(null, "Would you like to change the bias and run " +
"the program?", "Coin", JOptionPane.YES_NO_OPTION);
}	//Given a choice of no by user, program terminates
JOptionPane.showMessageDialog(null, "The Coin Program Exits. Good Bye!",
"Program Terminates", JOptionPane.CANCEL_OPTION);
System.exit(0);	//Program terminates
}//End of Main
//

public static void flip()	//Method to control tossing of coin
{
double calc = 0;	//Local variable to create toss value
//
calc = 2 * (Math.random()) * (1 - bias);	//Assigns to calc variable the result of math
//											//formula to generate a random value of toss
if (calc <= .5)	//If statement evaluates generated number
{
face = 1;	//Assigns to face data field an integer value for comparison
}
else face = 2;	//Assigns to face data field an integer value for comparison
}//End of Method
//
public static boolean isHead()	//Method for comparing generated number to constant for HEAD
{
if (face == HEAD)	//If statement compares generated number to constant for HEAD
{
return true;	//Returns true to main method if values are equal
}
else return false;	//Returns false to main method if values are false
}//End of Method
//
public static void setBias()	//Method to allow user to change the bias value to HEAD
{
String biasInput;	//Local variable to accept user input from JOP
//Prompts user to change bias value
biasInput = JOptionPane.showInputDialog(null, "Input your desired bias value", "Bias Change",
JOptionPane.INFORMATION_MESSAGE);
bias = Double.parseDouble(biasInput);	//Parses bias value from string to double type
}//End of Method
}//End of Class``````

Much better. Unfortunately I'm currently busy forcing MSN hotmail's crappy "locally saved emails" to be re-saved in ".eml" format, but otherwise, I would help you out immediately. But at least now when someone else comes by to help they won't be turned off by a lack of code tags.

Thanks, it is no emergency because this is not a due assignment. I just want to understand the concept before getting slowed down in the class or creating migranes for myself. :) If and when you get a chance to give it some time I appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.