Programming In Java Week 9: Programming Assignments Jan-Jun 2022

 NPTEL PROGRAMMING ASSIGNMENTS

Week 9 : Programming Assignment 1

Due Date of Submission 2022-03-31, 23:59 IST

Problem statement:

Complete the code to develop a BASIC CALCULATOR that can perform operations like AdditionSubtractionMultiplication and Division.

Note the following points carefully
:
1. Use only double datatype to store calculated numeric values.
2. Assume input to be of 
integer datatype.
3. The output should be rounded using 
Math.round() method.
4. Take care of the spaces during formatting output (e.g., single space each before and after =).
5. The calculator should be able to perform required operations on a minimum of two operands as shown in the below example:


Input:


5+6 

Output:

5+6 = 11




import java.util.Scanner;

public class Question91{

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

String input = sc.nextLine(); 


 

 





Week 9 : Programming Assignment 2

Due Date of Submission 2022-03-31, 23:59 IST

Problem statement:

Complete the code to develop an ADVANCED CALCULATOR that emulates all the functions of the GUI Calculator as shown in the image.


Complete the code to develop an ADVANCED CALCULATOR that emulates all the functions of the GUI Calculator as shown in the image.




Note the following points carefully:
1. Use only double datatype to store all numeric values.
2. Each button on the calculator should be operated by typing the characters from 'a' to 'p'.
3. To calculate 25-6, User should input fjhkc (where, f for 2, j for 5, h for '-', k for 6 and c for '=' ).
3. You may use the already defined function 
gui_map(char).
4. Without '=', operations won't give output as shown in Input_2 and Output_2 example below.
5. The calculator should be able to perform required operations on two operands as shown in the below example:


Input:

klgc

Output:
18.0


import java.util.Scanner;

public class Question92{

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

String input = sc.nextLine();


 

 


static char gui_map(char in){
char out = 'N';
char gm[][]={{'a','.'}
,{'b','0'}
,{'c','='}
,{'d','+'}
,{'e','1'}
,{'f','2'}
,{'g','3'}
,{'h','-'}
,{'i','4'}
,{'j','5'}
,{'k','6'}
,{'l','X'}
,{'m','7'}
,{'n','8'}
,{'o','9'}
,{'p','/'}};
for(int i=0; i<gm.length; i++){
if(gm[i][0]==in){
out=gm[i][1];
break;
}
}
return out;
}
}


Week 9 : Programming Assignment 3

Due Date of Submission 2022-03-31, 23:59 IST

Problem statement:

Complete the code to perform a 45 degree anti clock wise rotation with respect to the center of a 5 × 5 2D Array as shown below:

INPUT:
       00100

       00100

       11111

       00100

       00100


OUTPUT:
       10001

       01010

       00100

       01010

       10001


Note the following points carefully
:
1. Here, instead of 0 and 1 any character may be given.

2. The input and output array size must be of dimension 5 × 5 and nothing else.



import java.util.Scanner;

public class Question93{

public static void main(String args[]){

Scanner sc = new Scanner(System.in);


 

 




Week 9 : Programming Assignment 4

Due Date of Submission 2022-03-31, 23:59 IST

A program needs to be developed which can mirror reflect any 5 × 5 2D character array into its side-by-side reflection. Write suitable code to achieve this transformation as shown below:

 INPUT:                                                                                            OUTPUT:
      OOXOO                                        OOXOO
      OOXOO                                        OOXOO
      XXXOO                                        OOXXX
      OOOOO                                        OOOOO
      XOABC                                        CBAOX


Note the following points carefully
:
1. Here, instead of X and O any character may be present.

2. The input and output array size must be of dimension 5 × 5 and nothing else.
3. Only side-by-side reflection should be performed i.e. ABC || CBA.


import java.util.Scanner;

public class Question94{

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

 

 




Week 9 : Programming Assignment 5

Due Date of Submission 2022-03-31, 23:59 IST

Write suitable code to develop a 2D Flip-Flop Array with dimension 5 × 5, which replaces all input elements with values 0 by 1 and 1 by 0. An example is shown below:

INPUT:
       00001
       00001
       00001
       00001
       00001


OUTPUT:

       11110
       11110
       11110
       11110
       11110


Note the following points carefully
:
1. Here, the input must contain only 0 and 1.

2. The input and output array size must be of dimension 5 × 5.
3. Flip-Flop: If 0 then 1 and vice-versa.


import java.util.Scanner;

public class Question95{

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

 

 

 


Post a Comment (0)
Previous Post Next Post