Construct a bulls and cows program for my intro java class

Assignment Help JAVA Programming
Reference no: EM13163839

construct a Bulls and Cows program for my intro Java class. This program needs to perform the basic functions of the game (determining how many cows there are and how many bulls there are and tell the player when they win), but it also needs to offer the option to play again and record top score, low score, and average score over the games played in one session. I have the basic code down, but I'm having a hard time figuring out how to give the option to play again and print the high, low, and average scores. Can anyone help? My code is below.

 

public class Tester
{
public static void main (String[] args)
{
Game g = new Game();
g.play();
}
}

public class Game
{
int turns = 0;
Player p = new Player();
Oracle o = new Oracle();
public void play ()
{
String generated_number = o.generateNumber();
System.out.println(" generated_number is " + generated_number);
int[] a= {0,0};
while(a[0]<4)
{
String Guessed_number = p.makeGuess();
// a[0] represents bulls and a[1] represents cows.
// we need this information to be returned from compare function
// so used array here.
// array is the only way to return multiple values from function.
o.compare(generated_number,Guessed_number, a);
System.out.println(a[0] + " bull(s) and " + a[1] + " cow(s)");
turns++;
}
System.out.println("Correct! You took " + turns + " guesses.");
}
}

import java.util.Scanner;
public class Player
{
String yourGuess;
public Player(){}
public String makeGuess()
{
Scanner in = new Scanner(System.in);
System.out.println("Guess a four-digit number");
return in.next();
}
}

import java.util.Random;
public class Oracle
{
public Oracle() {}
public String generateNumber()
{
Random generator = new Random();
int a = 0;
int b = 0;
int c = 0;
int d = 0;
while(a==b||a==c||a==d||b==c||b==d||c==d)
{
a = generator.nextInt(10);
b = generator.nextInt(10);
c = generator.nextInt(10);
d = generator.nextInt(10);
}
String generatedNumber = "" +a+b+c+d;
return generatedNumber;
}
public static void compare(String generatedNumber, String yourGuess, int[] a)
{
a[0] = a[1]=0;
for (int i=0; i<4; i++)
{
for (int j=0; j<4; j++)
{
if (generatedNumber.charAt(i)==yourGuess.charAt(j))
{
if (i==j)
{
a[0]++;
}
else
{
a[1]++;
}
}
}
}
}
}

 

 

Reference no: EM13163839

Questions Cloud

Write a corresponding if else statement : The mathematical operation max(x,y,w,z) can be represented by using the conditional expression operator, as in:  max = (x > y && x > z && x > w) ? x : ((y > z && y > w) ? y : ((z > w) ? z : w))  Write a corresponding if else statement that is equival..
Multinational corporation with different suppliers : How can supply chain information integration be accomplished in a large multinational corporation with many different suppliers?
Write a machine-language program to input two one-digit num : Write a machine-language program to input two one-digit numbers, add them, and output the one-digit sum. Write it in a format suitable for the loader and execute it on the Pep/8 simulator.
Sexual dysfunction : Choose a sexual dysfunction: describe the symptoms, the theoretical perspective of the dysfunction, and treatment approaches for the dysfunction.
Construct a bulls and cows program for my intro java class : construct a Bulls and Cows program for my intro Java class. This program needs to perform the basic functions of the game (determining how many cows there are and how many bulls there are and tell the player when they win), but it also needs to offer..
Original categorization of knowledge or belief : After looking through the evidence, do you still maintain your original categorization of knowledge or belief? Why?
Empirical evidence for the knowledge or belief : Give 3 pieces of empirical evidence for the knowledge or belief, as well as 3 logical reasons.
What is server-side and client-side scripting? : 1. What is Server-side and Client-side scripting? Explain the differences between server-side and client - side scripting languages. Please provide 3 advantages and disadvantages of each. Please provide applicable references in APA style
Two mental disorders and illnesses-anorexia and bulimia : Examine at least two mental disorders and two mental illnesses from the perspective of psychology of eating disorders anorexia & bulimia.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd