wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Random phone number generator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Random phone number generator" Watch "Random phone number generator" New topic
Author

Random phone number generator

derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
I have had help with my code from another forum, the app is almost done, but no one is answering there now. I am trying to make a phone number generator. I get the following error though when trying to compile.

I posted this on another forum but no answer anymore,.


my post

C:\JAVA_PROGRAMMING_CODE\code1\RandomPhoneNum>javac RandomPhoneNum.java
RandomPhoneNum.java:23: cannot find symbol
symbol : method toOctalString(int)
location: class RandomPhoneNum
strippedNum = toOctalString(num1);
^
1 error



here is the code so far



Also, how did you people know about octal base numbers? I would never have known that. Do you know what I can do to improve my math ability please? I desperately need it. like any books you know? please. thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41045
    
  43
Right: you're calling a method called toOctalString, but your code has no such method. There is a class in the Java libraries that does have such a method, though. Do you know how you can find out which class of the standard Java class libraries has a particular method? (Hint: it involves perusing the javadocs.)


Ping & DNS - my free Android networking tools app
jishnu dasgupta
Ranch Hand

Joined: Mar 11, 2011
Posts: 103

Hey Derek,


It should be Integer.toOctalString(num1), which converts the given number to octal format and stores in a String.

For more clarification you can go this forum

http://www.coderanch.com/t/513799/java-programmer-SCJP/certification/toHexString-toOctalString


If debugging is the process of removing bugs, then programming must be the process of putting them in. -- Edsger Dijkstra

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18499
    
  40

derek smythe wrote:
Also, how did you people know about octal base numbers? I would never have known that. Do you know what I can do to improve my math ability please? I desperately need it. like any books you know? please. thanks.


Don't know about other countries, but in the U.S., converting a number from one base to another, is probably first encountered in the eighth grade. Some of my friends claim it was earlier. In my case, eighth grade sounds about right.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2982
    
    9
Yes, I believe it's covered in grade 1000.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37890
    
  22
What's a grade? I remember doing octal numbers when in a fresher's course when I was doing my MSc > 30 years after getting my first degree. But not before.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

I haven't learned about octal numbers or numbers with a different base system in highschool at all. I remember my uncle explaining me binary when I was about 14 or so. But systems like binary and hexadecimal are fairly common in computer programming, especially with lower-level programming languages (C++, C, assembly language).

Mathematics is a huge world. If you want to improve your math skills, you'd have to know in which area of mathematics you'd want to start. One field that programmers often have to know something about is discrete mathematics. A famous and classic book about algorithms and datastructures is Introduction to Algorithms.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Thank you. also, my code outputs this now for the first 3 digits sometimes, it goes over 1000 and is supposed to only have 3 digits for the octal group. Any more help appreciated. thanks.


C:\JAVA_PROGRAMMING_CODE\code1\RandomPhoneNum>java Rando
This app prints out a random phone number.
The first set of 3 digits can't have 8 or 9 in them.
The second set of 3 digits can't be greater than 742.
Here is a random generated phone number: 1145-736-2547



Also, since I don't remember anything from school except basic math and averages and percents, should I just buy beginner math books and go from beginner, to algebra, to calculus? Please. Thank you.
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
nevermind. I just bought a ridiculous amount of math books. I should be good now. But I still need help with the problem above please.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Mike Simmons wrote:Yes, I believe it's covered in grade 1000.


Mike, I'm sure you must be familiar with Tom Lehrer's song "New Math".
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2982
    
    9
Well, I had heard it at least once before. He's before my time, mostly, but well worth a listen.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41045
    
  43
You're generating decimal numbers up to 699, but those can have 4 digits in octal. You need to restrict the decimal numbers to those that have a 3-digit octal representation.
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Thank you. Here is the answer, someone helped me, but here it is if anyone is curious, you have to put in the following code.

num1= generator.nextInt(0700)+0100;// note the octal notation
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18499
    
  40

It is an interesting solution to a requirement -- but it doesn't seem to be very flexible. For example, what if the phone company changes it to allow the 9 as the third digit?

Henry
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Then I would be in trouble. LOL!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Random phone number generator
 
Similar Threads
Erroneous sym type What does this mean?
eek, help!
math problems as jnlp
Problem with Sort Method
Random-Format Number? Pls advise