Page 651 - Computer science 868 Class 12
P. 651

SAMPLE PROJECTS

                                                                                           #Experiential Learning
                                                                                           #Computational Thinking




                   Project  1    Write a menu driven program to perform
                                 1.  Binary addition          3. Binary multiplication
                                 2.  Binary subtraction       4. Binary division

                   1       import java.util.*;
                   2       class binopt{

                   3           Scanner sc= new Scanner(System.in);
                   4           void accept(){

                   5               Scanner sc= new Scanner(System.in);
                   6               int n,m,nn,mm;

                   7               do{
                   8                   System.out.println("Enter 2 decimal numbers: ");
                   9                   n=sc.nextInt();

                   10                  m=sc.nextInt();

                   11              }while(n<0||m<0);
                   12              nn=tobinary(n);
                   13              mm=tobinary(m);

                   14              System.out.println("the binary numbers are:"+ nn+"  "+ mm);
                   15              operation(nn,mm);

                   16          }
                   17          int tobinary(int x){

                   18              String s="";int n=x;
                   19              while(n>0){

                   20                 s= Integer.toString(n%2)+s;
                   21                 n=n/2;

                   22              }
                   23              return Integer.parseInt(s);

                   24          }
                   25          void operation(int nb, int mb){

                   26               System.out.println("enter the choice: 1. addition 2.substraction
                                     3.multiplication 4.division");
                   27              int ch = sc.nextInt();



                                                                                                                       649
                                                                                                       Sample Projects  649
   646   647   648   649   650   651   652   653   654   655   656