Results 1 to 9 of 9
  1. #1
    Student101 is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default Why wont this compile?

    i am doing an assignment for a course where you are supposed to create a program where it takes an inputted number of an inputted base, and converts it into a decimal(base 10). i have gotten this far and i am stuck. it will not compile and i am wondering if this is the best way to go about it?

    Here is the code i have so far:

    Java Code:
    import java.util.Scanner;
    
    public class AA3Q1{
    
    
    	public static void main(String[] args) {
    
    		int base;
    		int binaryNumber;
    		getNumberInBase();
    
    		Scanner kbd = new Scanner(System.in);
    		System.out.print("Enter a base.");
    		base = kbd.nextInt();
    
    
    
    		System.out.print(base, binaryNumber);
    
    	}
    
    	public static int getNumberInBase( Scanner scanner, int binaryNumber) {
    
    	// get input from the user.
    	Scanner kbd = new Scanner(System.in);
    	System.out.print("Enter a binary number:");
    	binaryNumber = kbd.nextInt();
    	return binaryNumber;
    
    	}
    	public static int convertToDecimal(int number, int base, int binaryNumber, int copyOfBinNum, int currPower, int decimalNumber) {
    
    			// keep looping until -1 is encountered.
    			while (binaryNumber != -1) {
    
    				// reset values to 0, use copyOfBinNum for calculations.
    				decimalNumber = 0;
    				currPower = 0;
    				copyOfBinNum = binaryNumber;
    
    			}
    			// keep looping until all digits of copyOfBinNum are removed.
    			while (copyOfBinNum > 0) {
    
    				// get last digit and strip it off copyOfBinNum
    				currDigit = (int) copyOfBinNum % 10;
    				copyOfBinNum /= 10;
    
    				// add to the running total if the digit is one
    				if (currDigit < 10) {
    					decimalNumber += Math.pow(base,currPower);
    					return decimalNumber;
    				}
    
    				// increment the power of two for next loop.
    				currPower++;
    			}
    
    				return null;
    
    
    	}
    	public static void printResults(int number, int base, int result) {
    
    	convertToDecimal();
    
    	System.out.println("you input the number " + number + " in the base " + base + ". This number as a power of 10 is " + result + ".");
    
    	}
    }
    Here is the Error message:

    C:\Users\chelsea\Downloads\A3Q1.java:19: cannot find symbol
    symbol : variable nextInt
    location: class java.util.Scanner
    base=keyboard.nextInt;
    ^
    1 error

    Tool completed with exit code 1

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,039
    Rep Power
    20

    Default

    That code is not in the code you posted.
    Therefore that error has not come from compiling this code.

  3. #3
    Allspark is offline Member
    Join Date
    Sep 2010
    Posts
    21
    Rep Power
    0

    Default

    Correct code or not, that error arises when you forget the parenthesis after nextInt. So variable = kbd.nextInt();
    Also, the code that you inputted here does call the methods you have created but does not know where to assign the returned value. For example:

    Java Code:
    public static void main(String[] args) {
    
    		int base;
    		int binaryNumber;
    		[COLOR="Red"]binaryNumber = [/COLOR]getNumberInBase();
    
    		Scanner kbd = new Scanner(System.in);
    		System.out.print("Enter a base.");
    		base = kbd.nextInt();
    
                   
    
    		System.out.print(base, binaryNumber);
    
    	}
    then you're not calling the rest of your methods so that code never executes.
    Last edited by Allspark; 11-17-2010 at 06:52 PM.
    - Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -

  4. #4
    Student101 is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    thank-you both of you. but ok so how do i show it where to assign the value? and do i have to call all of the methods in the code for it to execute?

  5. #5
    Student101 is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default ok figured something out!!

    Ok so i got am little bit further. now there is only 1 error message. Any ideas how i would fix it?

    Here is the code:

    Java Code:
    import java.util.Scanner;
    
    public class DanielsonErikA3Q1{
    
    private static int currDigit;
    private static int base;
    
    
    	public static void main(String[] args) {
    
    		int base;
    		int binaryNumber;
    
    		Scanner kbd = new Scanner(System.in);
    		System.out.print("Enter a base.");
    		base = kbd.nextInt();
    
    
    
    		System.out.println(base, binaryNumber);
    
    	}
    
    	public static int getNumberInBase( Scanner scanner, int binaryNumber) {
    
    	// get input from the user.
    	Scanner kbd = new Scanner(System.in);
    	System.out.print("Enter a binary number:");
    	binaryNumber = kbd.nextInt();
    	return binaryNumber;
    
    	}
    	public static int convertToDecimal(int number, int base, int binaryNumber, int copyOfBinNum, int currPower, int decimalNumber) {
    
    			// keep looping until -1 is encountered.
    			while (binaryNumber != -1) {
    
    				// reset values to 0, use copyOfBinNum for calculations.
    				decimalNumber = 0;
    				currPower = 0;
    				copyOfBinNum = binaryNumber;
    
    			}
    			// keep looping until all digits of copyOfBinNum are removed.
    			while (copyOfBinNum > 0) {
    
    				// get last digit and strip it off copyOfBinNum
    				currDigit = (int) copyOfBinNum % 10;
    				copyOfBinNum /= 10;
    
    				// add to the running total if the digit is one
    				if (currDigit < 10) {
    					decimalNumber += Math.pow(base,currPower);
    					return decimalNumber;
    				}
    
    				// increment the power of two for next loop.
    				currPower++;
    			}
    
    				return decimalNumber;
    
    
    	}
    	public static void printResults(int number, int base, int result) {
    
    
    
    	System.out.println("you input the number " + number + " in the base " + base + ". This number as a power of 10 is " + result + ".");
    
    	}
    }
    Here is the error message:

    C:\Users\chelsea\Downloads\DanielsonErikA3Q1.java: 20: cannot find symbol
    symbol : method println(int,int)
    location: class java.io.PrintStream
    System.out.println(base, binaryNumber);
    ^
    1 error

    Tool completed with exit code 1

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The error message is telling you what's wrong. It can't find println(int, int) because this method simply doesn't exist. println takes a String parameter, not two ints.

  7. #7
    Student101 is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default Oops!

    Oops! sorry about that posted the wrong code. thanks though. here is what i am having a problem with.

    Here is the code:

    Java Code:
    import java.util.Scanner;
    
    public class DanielsonErikA3Q1{
    
    private static int currDigit;
    private static int base;
    private static int binaryNumber;
    private static int decimalNumber;
    
    
    	public static void main(String[] args) {
    
    
    		int base;
    		int binaryNumber;
    
    		Scanner kbd = new Scanner(System.in);
    		System.out.print("Enter a base.");
    		base = kbd.nextInt();
    
    		System.out.println(base + "" + binaryNumber);
    
    		printResults();
    
    
    	}
    
    	public static int getNumberInBase( Scanner scanner, int binaryNumber) {
    
    	// get input from the user.
    	Scanner kbd = new Scanner(System.in);
    	System.out.print("Enter a binary number:");
    	binaryNumber = kbd.nextInt();
    	return binaryNumber;
    
    	}
    	public static int convertToDecimal(int number, int base, int binaryNumber, int copyOfBinNum, int currPower, int decimalNumber) {
    
    			// keep looping until -1 is encountered.
    			while (binaryNumber != -1) {
    
    				// reset values to 0, use copyOfBinNum for calculations.
    				decimalNumber = 0;
    				currPower = 0;
    				copyOfBinNum = binaryNumber;
    
    			}
    			// keep looping until all digits of copyOfBinNum are removed.
    			while (copyOfBinNum > 0) {
    
    				// get last digit and strip it off copyOfBinNum
    				currDigit = (int) copyOfBinNum % 10;
    				copyOfBinNum /= 10;
    
    				// add to the running total if the digit is one
    				if (currDigit < 10) {
    					decimalNumber += Math.pow(base,currPower);
    					return decimalNumber;
    				}
    
    				// increment the power of two for next loop.
    				currPower++;
    			}
    
    				return decimalNumber;
    
    
    	}
    	public static void printResults(int binaryNumber, int base, int decimalNumber) {
    
    
    
    	System.out.println("you input the number " + binaryNumber + " in the base " + base + ". This number as a power of 10 is " + decimalNumber + ".");
    
    	}
    }
    Here is the Error:

    C:\Users\chelsea\Downloads\DanielsonErikA3Q1.java: 23: printResults(int,int,int) in DanielsonErikA3Q1 cannot be applied to ()
    printResults();
    ^
    1 error

    Tool completed with exit code 1

  8. #8
    lonegreyride is offline Member
    Join Date
    Nov 2010
    Posts
    12
    Rep Power
    0

    Default

    At the end of your main() method, you call printResults, but pass no arguments to it. It requres three int values.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,302
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    println takes a String parameter
    Um, one of the 10 overloads does.

    db

Similar Threads

  1. wont validate
    By karq in forum XML
    Replies: 1
    Last Post: 10-07-2010, 05:33 PM
  2. Triangles wont draw Help?
    By The_Sponzy_Paradox in forum Java 2D
    Replies: 9
    Last Post: 03-22-2010, 02:42 AM
  3. Why wont import jm.util.*; work??
    By cakepizza in forum New To Java
    Replies: 2
    Last Post: 01-01-2010, 11:19 PM
  4. why wont it compile
    By bje98f in forum Advanced Java
    Replies: 1
    Last Post: 04-23-2009, 10:55 PM
  5. simple problem - code wont compile
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •