Wayne Lam

Greenhorn
+ Follow
since Feb 25, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Wayne Lam

Hi all, thanks for the replies.Left with the last function which is decimal to octal. Thinking for doing a do while statement but mind blocked in thinking of the algorithm. If need to capture the decimal output-> use modulus function get remainder -> store in array -> quotient continously dividing til 0 while remainder store in array . Then we combine the output in reverse order using String + ?
Correct me if wrg. Quite noob in programming



12 years ago
Hi i have an assignment of completing a simple program as above(subject). There is a need of defining 2 exception.BlankInputException and InvalidOctalException
Had problem in doing the blankinputexception. This is use to catch a blank input on the 2 textfield. txtDeciaml and txtOctal. If blank, will throw new BlankInputException and return a message.Any idea on how to do this?
12 years ago

Ernie Mcracken wrote:So you need to read your string using your Scanner then call the validateString() method



If you are going to have this in the same class as your Main then you'll need to make the validateString() method static.



Thanks Ernie again almost there,but now the problem is when i try to type "exit",the program doesn't exit.I need to display a message stating that "Please enter a proper binary number" when the validation returns false and allows the user to type another input.Appreciate the help as i quite new in programming.





13 years ago

Ernie Mcracken wrote:for your validateInput method you could method something like this,



Your current method will return every time you hit a 0 or 1 so it will only return false if the first character is not 1 or 0.



Hi Ernie,after this,where should i call the method?
13 years ago
13 years ago
Hi guys.got some problem in this program.Was suppose to write a program to get a binary string and display its value. Need to have 3 methods.

binaryToDecimal()
-Receive string which represents the value
-Converts the binary value to decimal
-Return results

validateInput()
-Receive string as parameter
-Return true if string contains 0s and 1s,false otherwise

main()
-Read input using scanner class
-Call validateInput() method to check whether inputted value is binary value,display error message and repeat input process
-call binaryToDecimal() method to get its converted decimal value and display it


had some problem in the validateInput() part. not sure is it correct
13 years ago