Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm in java one and i need help with this code. please follow the directions given and answer only if you know about the topic.

I'm in java one and i need help with this code. please follow the directions given and answer only if you know about the topic. I will appreciate your help. thank you

Program #7 had you convert decimal numbers like 123 to their octal equivalents, which is 173 for 123.

This program will work in reverse, converting octal numbers entered by the user to their equivalent decimal numbers. Your program will have one method in addition to main() that takes an integer number (that will be a proper octal number, containing only the digits 0 through 7) up to 8 digits in length and returns the equivalent integer number in decimal.

The main method of your program should prompt the user to enter a number of no greater than 8 digits. If they enter a number greater than 8 digits or a value less than 0, it should re-prompt the user to enter a number again. You do not need to check if the digits are valid octal numbers (0-7), as this is guaranteed. Display an error message each time the user enters an invalid value like this: Invalid Value Try Again

In addition to your main() method, your class will have a method called convert(), implemented like this:

public static int convert ( int octalNumber ) { }

The majority of your main() method should look like the following code. You will need to make some changes to do 8-digit data validation before calling the convert() method.

public static void main ( String args[] )

{

int oct;

Scanner sc = new Scanner ( System.in ); System.out.print ("Enter up to an 8-digit octal number and I'll convert it: "); oct = sc.nextInt(); System.out.printf ( "Your octal number %d is %d in decimal. ",oct, convert(oct));

The output of the program is illustrated in the code above. You must display your output as shown above and in the sample program executions shown on page 2 below.

Goals

- Write a simple method that accepts an int argument and returns an int value.

- Modify the logic of a program you've already written.

- Start to appreciate that main() doesn't have to be huge; in fact, the main() method typically will become a rather small "driver" method as you begin to modularize your code into other methods.

Points to Think About

- You must verify that the number entered is no more than 8 digits and not less than 0, continually prompting the user to enter a number until a valid number is entered.

- You may assume that the octal number entered by the user contains only valid octal digits, 0 through 7.

- Method documentation is required for all methods other than main().

- Follow the appropriate output format for your results (the octal number followed by a colon followed by the decimal number).

- The writing of a method called convert() as described is required for your program to be graded. Make sure that your method convert( ) behaves as described in this program description. In other words, method convert() should take an int value as an argument and return one int value.

- There will be no input or output performed in the method. Input or output performed in the method will result in point deductions.

- Your program must use the method you write to perform the conversion.

Sample Program Run (user input is underlined)

Enter up to an 8-digit octal number and I will convert it for you: 775002

Your octal number 775002 is 260610 in decimal.

Sample Program Run (user input is underlined)

Enter up to an 8-digit octal number and I will conver it for you: 0

Your octal number 0 is 0 in decimal.

Sample Program Run (user input is underlined)

Enter up to an 8-digit octal number and I will conver it for you: 45

Your octal number 55 is 45 in decimal.

Sample Program Run (user input is underlined)

Enter up to an 8-digit octal number and I will convert it for you: 777777777 Invalid Value Try Again Enter up to an 8-digit octal number and I will conver it for you: 80000000000 Invalid Value Try Again Invalid Value Try Again Enter up to an 8-digit octal number and I will convert it for you: 700000000

Invalid Value Try Again

Enter up to an 8-digit octal number and I will convert it for you: 77

Your octal number 77 is 63 in decimal.

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

Step: 3

blur-text-image

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago