Java Question help Base four

Apr 30th, 2015
Price: $5 USD

Question description

import java.util.Scanner;

public class BaseFour{
  public static void main(String[] args){
    Scanner scan = new Scanner(;
    String input = "";
    // So long as the String input is NOT 1-60 in length,
    //    Ask the user to enter a valid base-4 number up to 60 digits
    //    Save the next line of user input to the variable "input"
    // If the input string is NOT base-4, tell the user "Bad input!"
    // Otherwise, tell the user "You entered [numeric value of input]"
    // You can call the methods like so:
    //      isBaseFour(input)      This will give you a true or false value
    //      baseFourValue(input)   This will give you a long value
  private static boolean isBaseFour(String input){

    // Go over each character of input
    //      If that single character is NOT '0' or'1' or '2' or '3', return false immediately
    // If you finish going through the characters, return true
    return true;
  private static long baseFourValue(String input){
    long result;

    // To start, the exponent is 0 and the next position in 
    // in the input string is the string length minus one.  
    // You already have a long variable to hold your result.
    // While the exponent is smaller than the string length, 
    //     Get the character at the next position in the input string
    //        and store it in a char variable
    //     Subtract '0' (not 0) from that character and multiply 
    //         the result of that subtraction by (long) Math.pow(4, exponent)
    // When the loop is finished, assign the result to the variable "result"
    return result;
You will need to do the following things:
  1. Get a String of input from the user.
  2. Depending on whether the input is valid, announce the number's value; otherwise, let the user know it is bad input.
  3. Write a method to verify whether or not the user's input string is valid.
  4. Write a method to calculate the value of the user's input string.

Tutor Answer

(Top Tutor) Daniel C.
School: UIUC

Studypool has helped 1,244,100 students

Review from our student for this Answer

May 3rd, 2015
"The best tutor out there!!!!"
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1820 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors