• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Random phone number generator

 
derek smythe
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 21424
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I believe it's covered in grade 1000.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49823
69
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
derek smythe
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3090
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I had heard it at least once before. He's before my time, mostly, but well worth a listen.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21424
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I would be in trouble. LOL!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic