Question

Develop the Guessing game last semester based on Object Oriented principles. Specifically, you should not have...

Develop the Guessing game last semester based on Object Oriented principles. Specifically, you should not have static methods or static variables except for the main method

Homework Answers

Answer #1

copyable code:

import java.util.Scanner;

class game

{

    //constructor

    game()

    {

       System.out.println("Initilaizing constuctor....");

    }

    //method definition to guess the number

    void guess()

    {

            int secretkey;

            //generates the random number

            secretkey = (int) (Math.random() * 9 + 1);

            //gets input from the user

            Scanner keyboard = new Scanner(System.in);

            int key;

            //gives tips based on the user input in finding the correct guess

            do {

                  System.out.print("Enter a guess (1-10): ");

                  key = keyboard.nextInt();

                  if (key == secretkey)

                        System.out.println("Congratulations!,Guessed the correct key");

                  else if (key < secretkey)

                        System.out

                                   .println(" Secret key is larger.");

                  else if (key > secretkey)

                        System.out

                                   .println(" Secret key is lesser.");

            } while (key != secretkey);

    }  

}

//main method

public class guessgame {

      public static void main(String[] args) {

          //generating object for the class

           game g=new game();

           System.out.println("\nStart guessing");

           //calls the method of the class using objects

           g.guess();           

      }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use object-oriented programming to write an application for a company that uses a subscription-based business model...
Use object-oriented programming to write an application for a company that uses a subscription-based business model to loan out clothes such as office and party wear to female clients. A subscription costs $69 per 4 weeks. A client can make unlimited loan requests during her subscription, as long as she has no previous loan that has not been returned. There can be only one piece of clothes in each loan request. The chosen piece of clothes takes a day to...
We encourage you to work in pairs for this challenge to create a Student class with...
We encourage you to work in pairs for this challenge to create a Student class with constructors. First, brainstorm in pairs to do the Object-Oriented Design for a Student class. What data should we store about Students? Come up with at least 4 different instance variables. What are the data types for the instance variables? Write a Student class below that has your 4 instance variables and write at least 3 different constructors: one that has no parameters and initializes...
In JAVA write the following program: Objective: Practice object-oriented principles by making two Peanut Butter and...
In JAVA write the following program: Objective: Practice object-oriented principles by making two Peanut Butter and Jelly Sandwiches. The program must create two sandwiches based on user input. The sandwich information for both must then print out their details and determine if the two sandwiches are equal. Requirements: Write a class called Bread with the following Instance Variables Name: The name brand of the bread. o   Calories: The number of calories per slice assumed to be between 50 and 250 inclusively....
1.If you have defined a class,  SavingsAccount, with a public  static method,  getNumberOfAccounts, and created a  SavingsAccount object referenced by...
1.If you have defined a class,  SavingsAccount, with a public  static method,  getNumberOfAccounts, and created a  SavingsAccount object referenced by the variable  account20, which of the following will call the  getNumberOfAccounts method? a. account20.getNumberOfAccounts(); b. SavingsAccount.account20.getNumberOfAccounts(); c. SavingsAccount.getNumberOfAccounts(); d. getNumberOfAccounts(); e. a & c f. a & b 2.In the following class, which variables can the method printStats use? (Mark all that apply.) public class Item { public static int amount = 0; private int quantity; private String name; public Item(String inName, int inQty) { name...
Create in JAVA Suppose you are designing a game called King of the Stacks. The rules...
Create in JAVA Suppose you are designing a game called King of the Stacks. The rules of the game are as follows:  The game is played with two (2) players.  There are three (3) different Stacks in the game.  Each turn, a player pushes a disk on top of exactly one of the three Stacks. Players alternate turns throughout the game. Each disk will include some marker to denote to whom it belongs.  At the end...
You have been hired as Risk Consultant at a U.S.-based bank.  The bank is currently reporting...
You have been hired as Risk Consultant at a U.S.-based bank.  The bank is currently reporting its financials using the book value accounting method. The bank is considering an international move in which it can switch to the market value accounting method. You have been asked to write a 3-page report for the bank`s management. The report should discuss the following: What is the difference between book value accounting and market value accounting?  How do interest rate changes affect the...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of...
For Java For this assignment you will develop two classes called ATM and Customer that simulate...
For Java For this assignment you will develop two classes called ATM and Customer that simulate an imaginary automated teller machine (ATM). In the assignment, you should also develop a UML class diagram for the ATM class and a jUnit test case. In the program, we assume that an ATM initially keeps $100.00 cash for customer transactions. Additionally, we assume that there are a total of ten customers combined for the Union Bank and BOA banks. This is a list...
C++ Programming   You are to develop a program to read Baseball player statistics from an input...
C++ Programming   You are to develop a program to read Baseball player statistics from an input file. Each player should bestored in a Player object. Therefore, you need to define the Player class. Each player will have a firstname, last name, a position (strings) and a batting average (floating point number). Your class needs to provide all the methods needed to read, write, initialize the object. Your data needs to be stored in an array of player objects. The maximum...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • How can you use Bayes’ theorem in light of new information? In Bayes’ theorem, how does...
    asked 3 minutes ago
  • Which of the following is not one of the four states of a working file? Unchanged,...
    asked 6 minutes ago
  • Assume we have CPU instructions that look like this: load register, address save register, address Where...
    asked 19 minutes ago
  • What is the difference between the following two declarations? char array[] = “Hello World”; char *array...
    asked 34 minutes ago
  • Discuss knowledge and understanding gleaned from The Least Dangerous Assumption and Strategies for Presuming Competence. How...
    asked 35 minutes ago
  • Exercise 13-20 (LO13-3) The owner of Maumee Ford-Volvo wants to study the relationship between the age...
    asked 37 minutes ago
  • Scenario The Department of Administrative Services (DAS) provides a number of services to other departments in...
    asked 45 minutes ago
  • Linear Regressions The number of newly reported crime cases in a county in New York State...
    asked 49 minutes ago
  • Specialty courts have been developed for various categories of crimes and offenders (e.g., mental health, substance...
    asked 54 minutes ago
  • An air-track cart with mass m=0.40kg and speed v0=1.2m/s approaches two other carts that are at...
    asked 54 minutes ago
  • Write a program in C# that reverses a collection and removes elements that are divisible by...
    asked 57 minutes ago
  • A gas pipeline with the thickness of 4mm is to be joint together by using welding...
    asked 1 hour ago