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
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...
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...
***Programming language is Java. After looking at this scenario please look over the requirements at the...
***Programming language is Java. After looking at this scenario please look over the requirements at the bottom (in bold) THIS IS ALL THAT WAS PROVIDED. PLEASE SPECIFY ANY QUESTIONS IF THIS IS NOT CLEAR (don't just say more info, be specific)*** GMU in partnership with a local sports camp is offering a swimming camp for ages 10-18. GMU plans to make it a regular event, possibly once a quarter. You have been tasked to create an object-oriented solution to register,...
As you saw from the lab PowerPoint slides last week, you will be doing a research...
As you saw from the lab PowerPoint slides last week, you will be doing a research study looking at ‘Aggression Priming” for your first paper. For this week’s discussion, I want you to discuss with your group what you think this study is about. What is the hypothesis? What theory does it come from? What do you predict will happen (do you expect something different than the hypothesis in the researcher instructions? If so, what and why?)? Do you think...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML As a review, Here are some links to some explanations of UML diagrams if you need them. • https://courses.cs.washington.edu/courses/cse403/11sp/lectures/lecture08-uml1.pdf (Links to an external site.) • http://creately.com/blog/diagrams/class-diagram-relationships/ (Links to an external site.) • http://www.cs.bsu.edu/homepages/pvg/misc/uml/ (Links to an external site.) However you ended up creating the UML from HW4, your class diagram probably had some or all of these features: • Class variables: names, types, and...
(Use the case of “Global Treps”) You have been selected as the project manager for the...
(Use the case of “Global Treps”) You have been selected as the project manager for the Global Treps project. You helped to run a local shark tank like event at your college last year as part of a class project, so you have a general idea of what is involved. The schedule goal is six months, and the budget is $120,000. Your favorite professor, Dr. K., and a few of her associates have agreed to fund the project. Your strengths...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT