Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

I need help fixing my Java code to have an output that is displayed on the given image:

Java Code:

 

import java.util.Random;
import java.util.Scanner;
class Pattern_of_six_FallProject_3

    public static void main(String[] args) { 

        
        
        while(true){    
            String pattern = getInputPattern();  
            int count = getCountToGetPattern(pattern);  
            System.out.println("it took " + count + " throws to get the pattern" + pattern); 
            if (repeatAgain()==false) 

            break;      
        }   
    }     

    private static String getInputPattern() 
    {    
        Scanner input=new Scanner(System.in);       

        System.out.println("Please enter the six number pattern you would like the computer to throw seperated by spaces");    

        String pattern=input.nextLine();       

        return pattern+" ";   
    }    

    private static int getCountToGetPattern(String pattern) {    

        Random rand=new Random();     
        String outputPattern="";      

            for(int i=0;i<6;i++)          
            outputPattern += ""+1+rand.nextInt(6) ;   

            int count=1;       

            while(! outputPattern.equals(pattern))    
            {         

                outputPattern="";     

                for(int i=0;i<6;i++)     
                outputPattern += 1+rand.nextInt(6) +" ";    

                count++;       
            }       
            return count;
            }     
            private static boolean repeatAgain()   
            {        
                Scanner input=new Scanner(System.in);     
                System.out.println("Would you like to play the game again? Please enter (yes/no)"); 
                if(input.next().equals("yes"))          
                return true;       
                else          
                return false; 
            }
     } 

This game requests six dice numbers from the player.
The game then throws the dice until that pattern appears.
The game then tells the player how many throws it took.
Please enter the six-number pattern you would
like the computer to throw separated by spaces.
123456
yes
it took 33,012 throws to get the pattern 123456
Would you like to play the game again?
Please enter (yes/no)
Please enter the six-number pattern you would
like the computer to throw separated by spaces.
666666
it took 338,136 throws to get the pattern 6 6 6 6 6 6
expand button
Transcribed Image Text:This game requests six dice numbers from the player. The game then throws the dice until that pattern appears. The game then tells the player how many throws it took. Please enter the six-number pattern you would like the computer to throw separated by spaces. 123456 yes it took 33,012 throws to get the pattern 123456 Would you like to play the game again? Please enter (yes/no) Please enter the six-number pattern you would like the computer to throw separated by spaces. 666666 it took 338,136 throws to get the pattern 6 6 6 6 6 6
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education