Concept explainers
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;
}
}
Step by stepSolved in 4 steps with 3 images
- import java.util.Scanner; public class CircleAndSphereWhileLoop{ public static final double MAX_RADIUS = 500.0; public static void main(String[] args) { Scanner in = new Scanner(System.in); // Step 2: Read a double value as radius using prompt // "Enter the radius (between 0.0 and 500.0, exclusive): " // Step 3: While the input radius is not in the ragne (0.0, 500.0) // Display a message on one line (ssuming input value -1) // "The input number -1.00 is out of range." // Read a double value as radius using the same promt double circumference = 2 * Math.PI * radius; double area = Math.PI * radius * radius; double surfaceArea = 4 * Math.PI * Math.pow(radius, 2); double volume = (4 / 3.0) * Math.PI * Math.pow(radius, 3); // Step 4: Display the radius, circle circumference, circle area, // sphere surface area, and…arrow_forwardHow do I code: public static void rotateElements(int[] arr, int rotationCount) public static void reverseArray(int[] arr) In Java?arrow_forwardPRACTICE CODE import java.util.TimerTask;import org.firmata4j.ssd1306.MonochromeCanvas;import org.firmata4j.ssd1306.SSD1306;public class CountTask extends TimerTask {private int countValue = 10;private final SSD1306 theOledObject;public CountTask(SSD1306 aDisplayObject) {theOledObject = aDisplayObject;}@Overridepublic void run() {for (int j = 0; j <= 3; j++) {theOledObject.getCanvas().clear();theOledObject.getCanvas().setTextsize(1);theOledObject.getCanvas().drawString(0, 0, "Hello");theOledObject.display();try {Thread.sleep(2000);} catch (InterruptedException e) {throw new RuntimeException(e);}theOledObject.clear();theOledObject.getCanvas().setTextsize(1);theOledObject.getCanvas().drawString(0, 0, "My name is ");theOledObject.display();try {Thread.sleep(2000);} catch (InterruptedException e) {throw new RuntimeException(e);}while (true) {for (int i = 10; i >= 0; i--)…arrow_forward
- I need help with this java problem described below: import java.util.Scanner; import java.util.InputMismatchException; public class ExpirationMonth { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int expirationMonth; boolean valueFound = false; while (!valueFound) { try { expirationMonth = scnr.nextInt(); valueFound = true; System.out.println("Expiration month: " + expirationMonth); System.out.println("Processed one valid input value"); } /* Your code goes here */ } } }arrow_forwardimport java.util.Scanner; public class LabProgram { /* Define your method here */ public static void main(String[] args) { Scanner scnr = new Scanner(System.in); /* Type your code here. */ }}arrow_forwardneed help finishing/fixing this java code so it prints out all the movie names that start with the first 2 characters the user inputs the code is as follows: Movie.java: import java.io.File;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Scanner;public class Movie{public String name;public int year;public String genre;public static ArrayList<Movie> loadDatabase() throws FileNotFoundException {ArrayList<Movie> result=new ArrayList<>();File f=new File("db.txt");Scanner inputFile=new Scanner(f);while(inputFile.hasNext()){String name= inputFile.nextLine();int year=inputFile.nextInt();inputFile.nextLine();String genre= inputFile.nextLine();Movie m=new Movie(name, year, genre);//System.out.println(m);result.add(m);}return result;}public Movie(String name, int year, String genre){this.name=name;this.year=year;this.genre=genre;}public boolean equals(int year, String genre){return this.year==year&&this.genre.equals(genre);}public String…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education