# Java Qs 2....

• 03-14-2010, 06:03 AM
ruchira_sandanayaka
Java Qs 2....
Question 01
In Mathematics, different number systems are in use. The most commonly used number system is the
decimal number system, which has a base of 10. Other number systems in use are the binary number
system (base 2), octal number system (base 8) and the hexadecimal number system (base 16). They are
all positional number systems, where the decimal value of the number can be obtained by summing the
multiplication of each digit by its corresponding place value. For example, in binary system the
decimal equivalent of the number 1010 can be obtained by the sum: 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20 =
1 x 8 + 0 x 4 + 1 x 2 + 0 x 1 = 12
Design a program that would read a number and the base of the number system and print the equivalent
decimal value.
Assume that the base of the number system is always 10 or less. That is, all the digits of the number
system are a subset of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Examples of such number systems are
those with base 2 (binary), base 8 (octal), base 4, base 5 etc.
Your submission should include two documents.
(i) The design of the program in Pseudocode.
(ii) Implementation of the solution in Java
This will consist of a single file that contains a single class called
ITE1101Ass1Mar10XXXXXXXXX and the program should be saved in a file called
ITE1101Ass1Mar10XXXXXXXXX.java
where XXXXXXXXX is your index no
for e.g. the class of the answer submitted by the student with registration number e08420064 would be
ITE1101Ass1Mar10e08420064 and this would be saved in a file called
ITE1101Ass1Mar10e08420064.java
Bonus points: You may earn bonus marks if your program is able to
handle the Hexadecimal number system (base 16) as well.