## 15-200 Fall 2006 Homework Assignment 1 Number Systems

Program Due: Thursday Sep. 14, 2006 at 11:59pm

### Overview:

The best known number system in this world is the decimal number system. We all know what the number 185 represents

```
2         1         0
185 = 1 * 10  + 8 * 10  + 5 * 10
```
In this representation 10 is called base or radix. The number system used in microprocessors is the binary number system. The main difference between this number system and the decimal number system is that instead of 10 digits, the binary number system only contains 2 digits called '0' or '1':
```
2        1        0
101 = 1 * 2  + 0 * 2  + 1 * 2
```
Here are a few others numeric systems:
• Octal - base is 8
• Duodecimal - base is 12 (used for some purposes by the Romans)
• Hexadecimal - base is 16
• Vigesimal - base is 20 (used by the Mayans)
• Sexagesimal - base is 60 (used by the Babylonians)

The lab will require you to use the control flow statements, perform simple logical operations, and comminicate with the user via the dialog box.

### Objectives:

• To review of basic Java concepts
• To gain experience of working with the JOptionPane and ArrayList classes

### Instructions:

#### Part I:

Write a method that converts any positive decimal integer to any other number system between 2 and 36. This convertion is not complicated, but it requires a lot of divisions. Here is an example of converting 176 to base 7:

```176 / 7 = 25 remainder 1
25  / 7 =  3 remainder 4
3   / 7 =  0 remainder 3
```
We write all remainders backwards 341, that is all. We have
```176    =  341
10         7
```
Another example
```12345    =  343340
10            5
```

Now let us convert decimal 10 to base 16. What would be a result? 10. Unfortunately we cannot write 10 since it contains two digits 1 and 0. We have to use other characters for representation. We shall use the alphabet. For bases larger than 10, we will take additional digits from the letters a-z:

```10  = a        11  = b      ...   15   = f
10   16        10   16            10    10
```
More example,
```23332   =  a80a
10         13
```
You will use the ```JOptionPane ``` class to read input from the user's keyboard and write messages (output) to the user's screen. Also you will use the `ArrayList` class that provides methods to manipulate the size of the array that is used internally to store the list.

#### Part II:

In this part of the assignment you are to write a method that finds all decimal integers in the range [1, 10000] for which multiplication by 3 in a given (prompt for it!) base has the same effect as reversing its digits in that base. For example, in base 7 number 12 poseses such property
```12  = 15        12*3 = 36   = 51
10    7                10     7
```
The other numbers in base 7 that satisfy that criteria are 96, 600, 684, 4128, 4800.

You shall use the ```JOptionPane ``` class to prompt a user for a base and then write output to the user's screen.

#### Notes:

The base is between 2 and 36. You do not need to do an input valiadation.
For bases larger than 10, additional digits are chosen from the letters "a-z".
Review the implementation of calculation of Pi at Pi.java. This should help you to deal with JOptionPane and conversion from a string to an integer.