Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen

This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program.

Converting from Binary to Decimal Enter a binary value (empty line to quit): 111011 The binary value 111011 is 59 in decimal (base 10). Enter a binary value (empty line to quit): 1101 The binary value 1101 is 13 in decimal (base 10). Enter a binary value (empty line to quit): 1011 The binary value 1011 is 11 in decimal (base 10). Enter a binary value (empty line to quit): 1d231 ERROR - invalid binary value Enter a binary value (empty line to quit): 10 The binary value 10 is 2 in decimal (base 10). Enter a binary value (empty line to quit): Goodbye

Note that your output depends on the choices made by the user. You are required to check that the user has input a valid binary value (i.e. a string consisting only of 1s and 0s) or an empty line. See the project skeleton for more details. NOTE: For this assignment you will need to use the Character.getNumericValue() method. This method takes a character value such as '2' and converts it to the appropriate integer value (in this case the number 2). char input='2'; int inputInt = Character.getNumericValue(input); // inputInt now has a value of 2

This is the format:

/** * Project09.java * * A program that converts binary numbers into decimal numbers. * Used to practice breaking code up into methods. * * @author YOUR NAME HERE */ package osu.cse1223; import java.util.Scanner; public class Project09 { public static void main(String[] args) { //TODO: Fill in body } /** * Given a Scanner as input, prompt the user to enter a binary value. Use * the function checkForBinaryValue below to make sure that the value * entered is actually a binary value and not junk. Then return the value * entered by the user as an String to the calling method. * * @param input * A scanner to take user input from * @return a String representing a binary value read from the user */ public static String promptForBinary(Scanner input) { // TODO: Fill in body } /** * Given a String as input, return true if the String represents a valid * binary value (i.e. contains only the digits 1 and 0). Returns false if * the String does not represent a binary value. * * @param value * A String value that may contain a binary value * @return true if the String value contains a binary value, false otherwise */ public static boolean checkForBinaryValue(String value) { // TODO: Fill in body } /** * Given a binary value, return an int value that is the base 10 * representation of that value. Your implementation must use the algorithm * described in the Project 9 write-up. Other algorithms will receive no * credit. * * @param value * A String containing a binary value to convert to integer * @return The base 10 integer value of that binary in the String */ public static int binaryToDecimal(String value) { // TODO: Fill in body } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

Describe contextual influences on direct financial compensation.

Answered: 1 week ago

Question

=+ How well do you think you could do your job?

Answered: 1 week ago