Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Programming Languages A Place for windows applications programs and programmers .

Programming Languages Thread, Java programing help in Programming , WebDesign & Development; Hi am new to java and i have a program my teacher wants us to practice and write. Here is ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=31137


Reply
LinkBack Thread Tools Display Modes
Java programing help
 
 
Senior Member

Reply With Quote
 
Join Date: Dec 2008
Posts: 18,122
20-02-2009, 04:20 AM
 
Hi am new to java and i have a program my teacher wants us to practice and write. Here is the program instructions: Using the PairOfDice class from programming project 5.10, design and implement a class to play a game called Pig. In this game,...

Hi am new to java and i have a program my teacher wants us to practice and write.
Here is the program instructions:
Using the PairOfDice class from programming project 5.10, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a 1, all points accumulated for that round are forfeited and control of the dice moves to the other player. If the player rolls two 1’s in one turn, the player loses all points accumulated thus far in the game and loses control of the dice. The player may voluntarily turn over the dice after each roll. There for the player must decide to either roll again (be a Pig) and risk losing points or relinquish control of the dice, possibly allowing the other player to win. Implement the computer player such that it always relinquishes the dice after accumulating 20 or more points in any given round.


Here are the 5 classes required
Die:


public class Die {
private final int MAX = 6;

private int faceValue;

public Die() {
faceValue = 1;
}

public int roll() {
faceValue = (int) (Math.random() * MAX) + 1;

return faceValue;
}

public void setFaceValue(int value) {
if (value > 0 && value =goal)
rollAgain=false;

else
if (limit==ASK){
System.out.println("Take another turn (Y/N)?");
Scanner sc =new Scanner(System.in);
String again=sc.nextLine();
rollAgain=again.equalsIgnoreCase("Y");
}
else
if(round>=limit)
rollAgain=false;
if(rollAgain){
total+=round;
round=0;
}

return rollAgain;
}
public int getPoints(){
return total;

}

}











PlayPig


import java.util.*;
class PlayPig
{
public static void main(String[]args)
{
Pig game = new Pig(100);
game.play();
}
}








Pig

(I have no idea what to do for this class. I know that PlayPig class want to run game from this Pig class but I have no idea what im suppose to be doing. I have email my teacher and he said to ask the tutors but they are closed today and he wants us to turn it in by 11:59 pm tonight which is in 3.5 hours for me. i have go this far and have no idea what to do now. The pig class is suppose to manage the players but i have now idea how to set it up and link the game.play method.(teacher gave us the playpig class)



Thanks for your time and help!
 
 
 
Reply

Programming Languages Thread, Java programing help in Programming , WebDesign & Development; Hi am new to java and i have a program my teacher wants us to practice and write. Here is ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=31137


Bookmarks

Tags
java, programing


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump