6 Replies - 1444 Views - Last Post: 23 February 2009 - 08:28 AM Rate Topic: -----

#1 Live_Flow11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
			
			System.out.println("Enter your first choice ");
			human_choice1 + scan_next[];
			System.out.println("Enter your second choice ");
			human_choice2 + scan_next[];
			
			if human_choice1 
		 


Thats what I have so far...

Posted Image

This is the assignment.

Is This A Good Question/Topic? 0
  • +

Replies To: Guess The Day of the Week

#2 tanah.melayu  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • 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? ;)

it'll make us much easy to help you. :D
Was This Post Helpful? 0
  • +
  • -

#3 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#4 Live_Flow11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.

Posted Image

Thats the sample output
Was This Post Helpful? 0
  • +
  • -

#5 Live_Flow11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
			
			System.out.println("Enter your first choice ");
			human_choice1 = scan_next[];
			System.out.println("Enter your second choice ");
			human_choice2 = scan_next[];
			
			if human_choice1 
		 


I'm getting an error around "int generator.nextInt ((7) + 1);" where the period is.
Was This Post Helpful? 0
  • +
  • -

#6 Live_Flow11  Icon User is offline

  • New D.I.C Head

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

Re: Guess The Day of the Week

Posted 23 February 2009 - 07:20 AM

Bump...
Was This Post Helpful? 0
  • +
  • -

#7 gurdog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.");
			}
		 }
	  }
   }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1