taller número 1 de informática ll

14
Taller número 1 de informática ll Make a computer program that allows the conversion of numbers to different bases as well: 1. Binary to Decimal 2. Decimal to Octal 3. Binary to Hex 4. Exit The delivery of the program will include some issues: 1. Source code in Java (It must be fully functional). 2. Must submit documentation of the program, is the user manual (PDF Format). Deadline: september 16th, 2015, 7:00am Delivery mode: in .zip format, all the files in only one piece. 1) Below is the determined exercise: public static double lea(Object msj){ int x=0; double r=0; do{ try{ x=1; r=Double.parseDouble(JOptionPane.showInputDialog(msj)); }catch(Exception exc){

Upload: ramivides

Post on 18-Feb-2017

63 views

Category:

Investor Relations


0 download

TRANSCRIPT

Page 1: Taller número 1 de informática ll

Taller número 1 de informática ll

Make a computer program that allows the conversion of numbers to different bases as well:

1. Binary to Decimal

2. Decimal to Octal

3. Binary to Hex

4. Exit

The delivery of the program will include some issues:

1. Source code in Java (It must be fully functional).

2. Must submit documentation of the program, is the user manual (PDF Format).

Deadline: september 16th, 2015, 7:00am

Delivery mode: in .zip format, all the files in only one piece.

1) Below is the determined exercise:

public static double lea(Object msj){ int x=0; double r=0; do{ try{ x=1; r=Double.parseDouble(JOptionPane.showInputDialog(msj)); }catch(Exception exc){ x=0; } }while(x==0); return r; }

Page 2: Taller número 1 de informática ll

public static void write(Object msj){ JOptionPane.showMessageDialog(null,msj); } public static void main(String[] args) { char op; do{ op=JOptionPane.showInputDialog("B. Binary to decimal\n"+"D. Decimal to octal\n"+"H. Binary to hexadecimal\n"+"X. Exit").charAt(0); switch(op) { case 'B': write("You have chosen Binary to Decimal"); int bin,dec; bin=(int)lea("Enter Binary number"); dec=Binariodeci(bin); write(bin+"(2) = "+dec+"(10)"); break; case 'D': Decimaloctal(); break; case 'H': int binario,decimal; binario=(int)lea("Enter Binary number: "); decimal=binariohexa(binario); break; case 'X': break; default: write("Option is not valid, Please select other option"); }

Page 3: Taller número 1 de informática ll

}while(op!='X'); } public static int Binariodeci(int x){ int r=0,d; int i,c=0; while(x>0){ d=x%10; r=r+d*(int)Math.pow(2,c); c=c+1; x=x/10; } return r; } public static void Decimaloctal() { write("You have chosen Decimal to Octal"); int deci;String octal=""; deci=(int)lea("Enter decimal number: "); while(deci>0) { octal=deci%8+octal; deci=deci/8; } write(octal); } public static int binariohexa(int x) { write("You have chosen Binary to Hexadecimal"); String hexadecimal=""; int r=0,d,C; int i,c=0; while(x>0){ d=x%10; r=r+d*(int)Math.pow(2,c); c=c+1; x=x/10; } while (r>0){

Page 4: Taller número 1 de informática ll

hexadecimal=r%16+hexadecimal; r=r/16; } C=Integer.parseInt(hexadecimal); if (C<10) { write(" The number hexadecimal is: "+C); } if(C==10) { write("The number hexadecimal is: "+C+ " A"); } if(C==11) { write("The number hexadecimal is: "+C+ " B"); } if(C==12) { write("The number hexadecimal is: "+C+ " C"); } if(C==13) { write("The number hexadecimal is: "+C+ " D"); } if(C==14) { write("The number hexadecimal is: "+C+ " E"); } if(C==15) { write("The number hexadecimal is:"+C+ " F"); } return r; }}

2) Now you can see how the program works step by step

Page 5: Taller número 1 de informática ll

A. We started the program and the first thing we show is the following menu options:

B) Here are four options that we must choose, each one is named by a letter that is what you are going to write

Por ejemplo:

C) Here we click OK and we continue to the next step or the option chosen.3) In this step once chosen any of the options program will show us the following

message.

Page 6: Taller número 1 de informática ll

A) Shown here is that we have chosen the option to convert a binary number to a decimal number, we accept and continue to the next option.

Now we must enter the binary number that we want to convert to a decimal number in the white box of the low part.

Example: add the number binary 1100 Then we click  OK then continue to the next step which would result from the conversion.

A. after that we give clic Ok will show the result of the conversion .

In the following images we can observe the function of this system and that

means every number in the hexadecimal system

Page 7: Taller número 1 de informática ll

After having shown the result of the conversion the program again will return to the start menu

4) After returning to the menu of the options we can choose again anyone in this case we will choose the option D.

A. here as we know is OK to continue to the next option..

Page 8: Taller número 1 de informática ll

B. we have chosen the option to convert a decimal number to an octal number.

In this option we must enter the decimal number that we want to convert to the system octal.

C. Then displays the result on the following image also in the other picture shows the function.

Page 9: Taller número 1 de informática ll

D. After seeing the result ,the program will take us again to the options menu.

Page 10: Taller número 1 de informática ll

5) In this point of the program two options are missing, one is another conversion system that would be of binary to hexadecimal and the option to go out of the program.

A. In the first image we can see that we have chosen the third , we see in the second image we chose the system binary to hexadecimal.

B. In the previous image we write the binary number that we will convert to the system hexadecimal.

Page 11: Taller número 1 de informática ll

C. In the previous picture we see the result and a letter, the letter C is equal to 12 in the hexadecimal system

D. In the following images we can observe the function of this system and that means every number in the hexadecimal system.

Page 12: Taller número 1 de informática ll

6) After the program was finishing the last system, it was sending us again to the menu of main options

A. only missing the last option, is to exit the program.

B. Once we accept the program will be completed with total success.