SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 2 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 12 Jan 2018 My Price 10.00

displays back to the user the decimal value and exits

program 1 description: 

Write a program takes in a binary value, protected by a try/catch block, from the console and displays back to the user the decimal value and exits. You can use Integer.parseInt(bin, 2). 
If input is not base 2, parseInt will throw an error, which the try block will catch and add display a meaningful message to user, then prompt for a binary number again.

Program 2 description:

Starting with the code hangeman.java and hangeman.txt which is located in the contents section, modify the code to read in the file hangeman.txt which will contain the words used for guessing. In addition improve the code to meet the courses rubric for full credit ( code comments ect ). The hangeman.txt should be in the root of the project, e.g. the parent of the src folder and you would open it with new File("./hangman.txt").

  • import java.util.Scanner;


    public class hangman {
      public static void main(String[] args) {
        String[] words = { "write", "program", "that", "receive", "positive" };
        char anotherGame;

        Scanner input = new Scanner(System.in);

        do {
          int index = (int) (Math.random() * words.length);

          String hiddenWord = words[index];
          StringBuilder guessedWord = new StringBuilder();

          for (int i = 0; i < hiddenWord.length(); i++)
            guessedWord.append('*');

          int numberOfCorrectLettersGuessed = 0, numberOfMisses = 0;

          while (numberOfCorrectLettersGuessed < hiddenWord.length()) {
            System.out.print("(Guess) Enter a letter in word " + guessedWord
                + " > ");
            String s = input.nextLine();
            char letter = s.charAt(0);

            if (guessedWord.indexOf(letter + "") >= 0) {
              System.out.println("\t" + letter + " is already in the word");
            } else if (hiddenWord.indexOf(letter) < 0) {
              System.out.println("\t" + letter + " is not in the word");
              numberOfMisses++;
            } else {
              int k = hiddenWord.indexOf(letter);
              while (k >= 0) {
                guessedWord.setCharAt(k, letter);
                numberOfCorrectLettersGuessed++;
                k = hiddenWord.indexOf(letter, k + 1);
              }
            }
          }

          System.out.println("The word is " + hiddenWord + ". You missed "
              + numberOfMisses + ((numberOfMisses <= 1) ? " time" : " times"));

          System.out.print("Do you want to guess for another word? Enter y or n> ");
          anotherGame = input.nextLine().charAt(0);
        } while (anotherGame == 'y');
      }
    }

Attachments:

Answers

(5)
Status NEW Posted 12 Jan 2018 02:01 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)