# Guess The Day of the Week

Page 1 of 1

## 6 Replies - 3105 Views - Last Post: 23 February 2009 - 08:28 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=88363&amp;s=dbe69dad472e877a60e8a06cd07aa6c7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Live_Flow11

Reputation: 0
• Posts: 35
• Joined: 25-January 09

# Guess The Day of the Week

Posted 22 February 2009 - 01:43 PM

Help with the math part and also what to do next please.
```   import java.util.Random;
import java.util.Scanner;

public class Project5A {

public static void main(String args[])
{

Random generator = new Random();
int x;
String pc_choice, human_choice;
String guess1;
String guess2;
int daynumber;
pc_choice + "";
Scanner scan =  new Scanner (System.in);

switch (x + Math.abs(generator.nextInt()\ 7 + 1)

int temp = scan.nextInt();

case 1;
pc_choice + "Monday";
break;

case 2;
pc_choice + "Tuesday";
break

case 3;
pc_choice + "Wednesday";
break

case 4;
pc_choice + "Thursday";
break

case 5;
pc_choice + "Friday";
break

case 6;
pc_choice + "Saturday";
break

case 7;
pc_choice + "Sunday";
break

human_choice1 + scan_next[];
human_choice2 + scan_next[];

if human_choice1

```

Thats what I have so far...

This is the assignment.

Is This A Good Question/Topic? 0

## Replies To: Guess The Day of the Week

### #2 tanah.melayu

Reputation: 5
• Posts: 45
• Joined: 21-February 09

## Re: Guess The Day of the Week

Posted 22 February 2009 - 02:03 PM

Hello Live_Flow11,

Can you explain more on what is actually your system about and what is actually you want us to do? and, why the source code given looks like hanging somewhere?

### #3 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

## Re: Guess The Day of the Week

Posted 22 February 2009 - 02:19 PM

you dont need to find the absolute when generating random ints
```int n = generator.nextInt(7) + 1;

```

also your switch statement is a mess, there's no semicolon after the cases, only colons so it should be
```case 1:
case 2:
etc

```

you switch should look liek this
```int n = generator.nextInt(7) + 1;
switch (n)
{
case 1:
pc_choice = "Monday";
break;

case 2:
pc_choice = "Tuesday";
break

case 3:
pc_choice = "Wednesday";
break

case 4:
pc_choice = "Thursday";
break

case 5:
pc_choice = "Friday";
break

case 6:
pc_choice = "Saturday";
break

case 7:
pc_choice = "Sunday";
break
}

```

then compare the string with the user input

This post has been edited by mostyfriedman: 22 February 2009 - 02:21 PM

### #4 Live_Flow11

Reputation: 0
• Posts: 35
• Joined: 25-January 09

## Re: Guess The Day of the Week

Posted 22 February 2009 - 02:37 PM

The program is supposed to generate two random days and if the human input matches the days you'll receive a "correct" response.

Thats the sample output

### #5 Live_Flow11

Reputation: 0
• Posts: 35
• Joined: 25-January 09

## Re: Guess The Day of the Week

Posted 22 February 2009 - 03:12 PM

``` //Rondel Temple
//2-23-08
//Comp 1210-001

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

public class Project5A {

public static void main(String args[])
{

Random generator = new Random();
int x;
String pc_choice, human_choice;
String guess1;
String guess2;
int daynumber;
pc_choice = "";
Scanner scan =  new Scanner (System.in);

int temp = scan.nextInt();

int generator.nextInt ((7) + 1);

switch (n)

{

case 1:
pc_choice = "Monday";
break;

case 2:
pc_choice = "Tuesday";
break

case 3:
pc_choice = "Wednesday";
break

case 4:
pc_choice = "Thursday";
break

case 5:
pc_choice = "Friday";
break

case 6:
pc_choice = "Saturday";
break

case 7:
pc_choice = "Sunday";
break

human_choice1 = scan_next[];
human_choice2 = scan_next[];

if human_choice1

```

I'm getting an error around "int generator.nextInt ((7) + 1);" where the period is.

### #6 Live_Flow11

Reputation: 0
• Posts: 35
• Joined: 25-January 09

## Re: Guess The Day of the Week

Posted 23 February 2009 - 07:20 AM

Bump...

### #7 gurdog

Reputation: 0
• Posts: 7
• Joined: 11-February 09

## Re: Guess The Day of the Week

Posted 23 February 2009 - 08:28 AM

Ok this has proven to be quite a challenge for a newbie. I have some of what I think is right here, but I know I am way off on a few things. Any help on this is very appreciated.

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

public class Project5A
{

//***********************************************************************
// Initialize variables
//***********************************************************************

public static void main(String[] args)
{
String Compchoice = "";
String (guess1) = "";
String (guess2) = "";
int randomNum = 0;
// Generates random numbers
Random generator = new randomNum();
randomNum = generator.nextInt(7) + 1;

//***********************************************************************
// Set switch statement
//***********************************************************************
Switch() = Switch(randomNum);
randomNum = Compchoice;

case 1 : Compchoice = "Sunday";
break;

case 2 : Compchoice = "Monday";
break;

case 3 : Compchoice = "Tuesday";
break;

case 4 : Compchoice = "Wednesday";
break;

case 5 : Compchoice = "Thursday";
break;

case 6 : Compchoice = "Friday";
break;

case 7 : Compchoice = "Saturday";
break;
}

//***********************************************************************
// User guessing the day of the week
//***********************************************************************
Scanner scan = new Scanner (System.in)
guess1;
guess2;

System.out.println("Can you guess the weekday picked by the computer?");
System.out.print("\n Enter your first guess: ");
guess1 = scan.nextInt();
System.out.print("\n Enter your second guess: ");
guess2 = scan.nextInt();

System.out.println("You guessed " + guess1 + "and" + guess2);

//***********************************************************************
// Use switch statement to set computer's choice of weekday
//***********************************************************************
if (<guess1>equalsIgnorecase<Compchoice>);
boolean System.out.println("Your first guess is right, the computer chose" + Compchoice);
else
{
boolean System.out.println("Your first guess is wrong, the computer did not choose" + guess1);

if (<guess2>equalsIgnorecase<Compchoice>);
boolean System.out.println("Your second guess is right, the computer chose" + Compchoice);
else
{
boolean System.out.println("Your second guess is also wrong, the computer did not choose" + guess2);
System.out.println("The computer chose" + Compchoice + ", better luck next time.");
}
}
}
}

```