need help dont know whats wrong

This is what i have so far

import java.util.Scanner;

import java.util.*;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.Reader;

public class Test

{

public static void main(String[] args) throws IOException

{

int total = 0;

int totala = 0;

int number = 0;

int numbera = 0;

while (total < 12)

{

for (int i = 1; i < 2; i++)

{

number = 1 + (int) (Math.random() * 6);

numbera = 1 + (int) (Math.random() * 6);

}

System.out.println("You want to roll again, y or n");

Reader r = new InputStreamReader(System.in);

char c = (char) r.read();

String s = new Character(c).toString();

total += number;

if (s.equalsIgnoreCase("y")){

System.out.println ("The total number of spots are " + total);

}

if(total > 10){

System.out.println("YOU LOSE!!!");

}

totala += numbera;{

if (s.equalsIgnoreCase("n"))

System.out.println("The total the computer has generated are " + totala);

}

if (total > totala){

System.out.println("Well done you Win ");

}

if (totala > total){

System.out.println("You have lost Better luck next time");

}

if(total==totala){

System.out.println("Game Is Drawn");

}

}

}

}

when i press 'y' it shows me a random number then a message for example ("You have lost Better luck next time"); or ("Well done you Win ");

and this is what is to happen if i keep pressing 'y' it should add the numbers togheter until its over 11 or i press 'n'

after i press "n" it should automatically be the computers turn.

this is are rules of the computer.

1. should generate a random number between 1 and 6 if it generates anything that =>8 it should stop and compare with my score.

can someone tell me what im doing wrong.

2. if it generates anything > 11 it losses (if i dont generate anything >11)

3. compares who wins at the end (player or computer).

i really dont know what ive done wrong can someone

[2185 byte] By [999128a] at [2007-10-3 3:01:32]
# 1
What you can improve:- post formatted code http://forum.java.sun.com/help.jspa?sec=formatting- use more methods
CeciNEstPasUnProgrammeura at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 2
can someone tell me where ive gone wrong ive tried lots of things and i still cant get to work.ty
999128a at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 3
I would tell you if I could read your code!
CeciNEstPasUnProgrammeura at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 4
I can't read your code b/c you didn't put it in [code] tags, but how the hell do you get and 8 or 11 if you're generating a number b/w 1 and 6?
Norweeda at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 5
im not sure how to format my code cause ive never learned any of that before can u show me in one part in what ive to do and ill try the rest myself.ty
999128a at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 6
There is a link on this page...1st reply....read it
Norweeda at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 7
Cause im new to java im not sure what to do.
999128a at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 8

Honestly...even if I wanted to just DO this project for you I couldn't. I can't even understand what this thing is trying to do...based on your code or your description.

If you take the time to carefully write out the full specifications for this game maybe I'll take some time and look at your code.

Norweeda at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 9
post your code within code tag.
asif_need_javaa at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 10
post your code within code tag ?
999128a at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 11

This is what ive tried to improve in. but its nothing to do with the formatting.

import java.util.Scanner;

import java.util.*;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.Reader;

public class Test

{

public static void main(String[] args) throws IOException

{

int total = 0;

int totala = 0;

int number = 0;

int numbera = 0;

while (total < 12)

{

for (int i = 1; i < 2; i++)

{

number = 1 + (int) (Math.random() * 6);

numbera = 1 + (int) (Math.random() * 6);

}

System.out.println("You want to roll again, y or n");

Reader r = new InputStreamReader(System.in);

char c = (char) r.read();

String s = new Character(c).toString();

total += number;

if (s.equalsIgnoreCase("y")){

System.out.println ("The total number of spots are " + total);

}

else if(total > 10){

System.out.println("YOU LOSE!!!");

}

totala += numbera;

if (s.equalsIgnoreCase("n")){

System.out.println("The total the computer has generated are " + totala);

}

else if(totala > 10){

System.out.println("THE COMPUTER HAS LOST!!!");

}

else if ( totala >=8 && total > totala){

System.out.println("Well done you Win ");

}

else if (totala>=8 && totala > total){

System.out.println("You have lost Better luck next time");

}

else if(totala>=8 && total==totala){

System.out.println("Game Is Drawn");

}

}

}

}

The same rules apply can someone help.

999128a at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 12
Wow.This is just...wow.
CeciNEstPasUnProgrammeura at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 13

WHAT IS WRONG WITH YOU.

When you post cose use the [code] tag.

as in when you post stuff HERE (nothing at all to do with java)

[code]

code

code

code

code

[ / code] (no spaces)

then it'll look all nice.

And again...what are your rules....spend 5 minutes and type them out so other people can understand them.

Norweeda at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 14

why do you ahve scanner in there?

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.Reader;

public class Dice

{

public static void main(String[] args) throws IOException

{

int total = 0;

int totala = 0;

int number = 0;

int numbera = 0;

while ( total < 12 )

{

for ( int i = 1; i < 2; i++ )

{

number = 1 + (int) (Math.random() * 6);

numbera = 1 + (int) (Math.random() * 6);

}

System.out.println( "You want to roll again, y or n" );

Reader r = new InputStreamReader( System.in );

char c = (char) r.read();

String s = new Character( c ).toString();

total += number;

if ( s.equalsIgnoreCase( "y" ) )

{

System.out.println( "The total number of spots are " + total );

}

else if ( total > 10 )

{

System.out.println( "YOU LOSE!!!" );

}

totala += numbera;

if ( s.equalsIgnoreCase( "n" ) )

{

System.out.println( "The total the computer has generated are "

+ totala );

}

else if ( totala > 10 )

{

System.out.println( "THE COMPUTER HAS LOST!!!" );

}

else if ( totala >= 8 && total > totala )

{

System.out.println( "Well done you Win " );

}

else if ( totala >= 8 && totala > total )

{

System.out.println( "You have lost Better luck next time" );

}

else if ( totala >= 8 && total == totala )

{

System.out.println( "Game Is Drawn" );

}

}

}

}

Norweeda at 2007-7-14 20:51:14 > top of Java-index,Java Essentials,Java Programming...
# 15

dear 999128,-

please try to debug your code and come back with a specific compiler/run time error. that way you will receive faster help.

i would suggest to use random number generator class instead of Reader r = new InputStreamReader(System.in);.

Kindly read and understand the following web site: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html

i dont know why you need according to your description:

for (int i = 1; i < 2; i++)

{

number = 1 + (int) (Math.random() * 6);

numbera = 1 + (int) (Math.random() * 6);

}

try to use debugger or you can put

System.out.println("your expected output")

commands in your program to output your expected outputs.

i have been watching your posts and i am sure nobody is gonna try fix your code without your rigorous analysis. If you do, then it is your good luck.

hope these help

geomana at 2007-7-21 10:04:58 > top of Java-index,Java Essentials,Java Programming...