Question

Note: Write the pseudocode separately and the source code separately in java using the loops method according to the question

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
* 1) call addShutdownHook in java Runtime
* 2) create new thread object
* 3) implement run method
* 4) while input is not cookie
* 5)    catch any keyboard interruptions
* 6)    if caught create clear input buffer
* 7)    else
* 8)       ask user input
* 9) after valid input, finally print msg to user
*/
//Game.java
import java.lang.System;
import java.lang.Runtime;
import java.util.Scanner;
public class Game
{
   public static void main(String args[])
   {
       //using addShutdownHook() method we can create a thread
       // that detects any keyboard interruptions in program
       //
       Runtime.getRuntime().addShutdownHook(new Thread()
       {
           public void run()
           {
               //Scanner object for asking input
               Scanner in = new Scanner(System.in);
               String inp = "";
               //until user enters cookie
               while(true)
               {
                   //ask input to user
                   try
                   {
                       System.out.print("Gimme a cookie: ");
                       inp = in.nextLine();
                       //if cookie is the input break.
                       if(inp.equalsIgnoreCase("cookie"))
                       {
                           //finally print msg to user
                           System.out.println("Don't leave your terminal open, fool!");
                           return;
                       }
                   }
                   //catch exceptions
                   catch(Exception e)
a                   {
                       System.out.println();
                       //create new Scanner object, previous object cotains
                       //invalid buffer.
                       in = new Scanner(System.in);
                   }
               }
              
           }
       });

   }
}

C\Windows\SYSTEM32\cmd.exe Gimme Gimme a cookie: I dont Understand Gimme a cookie: Who is this? Gimme a cookie: help? Gimme

Add a comment
Know the answer?
Add Answer to:
Note: Write the pseudocode separately and the source code separately in java using the loops method...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write pseudocode and the write the source code in C++, thanks! Program 0: Insulted yet? Most...

    Write pseudocode and the write the source code in C++, thanks! Program 0: Insulted yet? Most people get harassed by telemarketers, so for your warmup question, you're going to design (pseudocode) and write (source code) a program that generates (clean) insults at random. The program must have a function that takes in the name of a person and prints out an insult directed to them. Further, the program should ask if the person has had enough insults and continue until...

  • java pseudocode and source code help? Write a program that uses an array of high temperatures...

    java pseudocode and source code help? Write a program that uses an array of high temperatures for your hometown from last week (Sunday - Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array...

  • Note: According to the question, please write source code in java only using the class method....

    Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors. Exercise #2: Design and implement a program (name it compareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array...

  • Note: Please write the Pseudocode using Arrays method in Java language. Program 2 (40%); For this...

    Note: Please write the Pseudocode using Arrays method in Java language. Program 2 (40%); For this assignment, we're going to make a game. Imagine you initially start with a random "hand" of two cards (values 2-9). Your goal is to continue to add to your hand until the sum of the cards is between 21 25, at which point youu win. Further, if you hold 5 cards, you win. However, if you exceed a sum of 25, you lose. Admittedly,...

  • Note: According to the question, please write source code in java only using the class method....

    Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors.​ Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods Assume that the station and volume settings range from 1 to 10 1. A private variable of type int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT