NPTEL Programming In Java Assignment 9 Answers 2022:- All the Answers provided here to help the students as a reference, You must submit your assignment at your own knowledge
What is Programming In Java?
With the growth of Information and Communication Technology, there is a need to develop large and complex software. Further, that software should be platform-independent, Internet-enabled, easy to modify, secure, and robust. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment. Now, the Java programming language is being used for mobile programming, Internet programming, and many other applications compatible to distributed systems. This course aims to cover the essential topics of Java programming so that the participants can improve their skills to cope with the current demand of IT industries and solve many problems in their own filed of studies.
CRITERIA TO GET A CERTIFICATE
Average assignment score = 25% of the average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100
Final score = Average assignment score + Exam score
YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.
NPTEL Programming In Java Assignment 9 Answers 2022:-
Q1. Problem statement:
Complete the code to develop a BASIC CALCULATOR that can perform operations like Addition, Subtraction, Multiplication and Division.
Code:-
int i=0;
int j=0;
double ans=0;
char pattern[] = input.toCharArray();
for(int a=0; a<pattern.length; a++)
{
if(pattern[a]=='+')
{
i= Integer.parseInt(input.substring(0,a));
j= Integer.parseInt(input.substring(a+1,pattern.length));
ans = (double)i+j;
}else if(pattern[a]=='-')
{
i= Integer.parseInt(input.substring(0,a));
j= Integer.parseInt(input.substring(a+1,pattern.length));
ans = (double)i-j;
}else if(pattern[a]=='/')
{
i= Integer.parseInt(input.substring(0,a));
j= Integer.parseInt(input.substring(a+1,pattern.length));
ans = (double)i/j;
}else if(pattern[a]=='*')
{
i= Integer.parseInt(input.substring(0,a));
j= Integer.parseInt(input.substring(a+1,pattern.length));
ans = (double)i*j;
}
}
System.out.print(input+" = " + Math.round(ans));
Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW
Q2. Problem statement:
Complete the code to develop an ADVANCED CALCULATOR that emulates all the functions of the GUI Calculator as shown in the image.
Code:-
char pattern [] = input.toCharArray();
int f=0;
for(int i=0; i<pattern .length; i++){
pattern [i]=gui_map(pattern [i]);
}
double operand1=0.0;
String o1="";
double operand2=0.0;
String o2="";
double ans=0.0;
outerloop:
for(int i=0; i<pattern .length; i++){
int r=0;
if(pattern [i]=='+'||pattern [i]=='-'||pattern [i]=='/'||pattern [i]=='X'||pattern [i]=='='){
for(int j=0; j<i; j++){
o1+=Character.toString(pattern [j]);
}
operand1=Double.parseDouble(o1);
for(int k=i+1; k<pattern .length; k++){
if(pattern [k]=='='){
f=1;
operand2=Double.parseDouble(o2);
if(pattern [i]=='+'){
ans=operand1+operand2;
}else if(pattern [i]=='-'){
ans=operand1-operand2;
}else if(pattern [i]=='/'){
ans=operand1/operand2;
}else if(pattern [i]=='X'){
ans=operand1*operand2;
}
break outerloop;
}else{
o2+=Character.toString(pattern [k]);
}
}
}
}
if(f==1)
System.out.print(ans);
Q3. 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:
Code:-
char mat[][]= new char[5][5];
for(int L=0;L<5; L++)
{
String input = sc.nextLine();
char seq[] = input.toCharArray();
if(seq.length==5){
for(int i=0;i<5;i++)
{
mat[L][i]=seq[i];
}
}else
{
System.out.print("Wrong Input!");
System.exit(0);
}
}
char tran[][] = new char[5][5];
String outer[]={"00","10","20","30",
"40","41","42","43",
"44","34","24","14",
"04","03","02","01"};
String inner[]={"11","21","31","32",
"33","23","13","12"};
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
for(int k=0; k<outer.length; k++)
{
char indices[]=outer[k].toCharArray();
int a = Integer.parseInt(String.valueOf(indices[0]));
int b = Integer.parseInt(String.valueOf(indices[1]));
if(a==i && b==j)
{
if(k==15){k=1;}
else if(k==14){k=0;}
else {k+=2;}
indices=outer[k].toCharArray();
a = Integer.parseInt(String.valueOf(indices[0]));
b = Integer.parseInt(String.valueOf(indices[1]));
tran[a][b] = mat[i][j];
break;
}
}
for(int k=0; k<inner.length; k++)
{
char indices[]=inner[k].toCharArray();
int a = Integer.parseInt(String.valueOf(indices[0]));
int b = Integer.parseInt(String.valueOf(indices[1]));
if(a==i && b==j){
if(k==7){k=0;}
else {k+=1;}
indices=inner[k].toCharArray();
a = Integer.parseInt(String.valueOf(indices[0]));
b = Integer.parseInt(String.valueOf(indices[1]));
tran[a][b] = mat[i][j];
break;
}
}
tran[2][2] = mat[2][2];
}
}
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(tran[i][j]);
}
System.out.println();
}
Q4. 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:
Code:-
char act[][]= new char[5][5];
char ref[][]= new char[5][5];
for(int L=0;L<5; L++)
{
String input = sc.nextLine();
char seq[] = input.toCharArray();
if(seq.length==5)
{
for(int i=0;i<5;i++)
{
act[L][i]=seq[i];
}
}
}
for(int i=0; i<5;i++)
{
for(int j=0; j<5;j++)
{
ref[i][j]=act[i][4-j];
}
}
for(int i=0; i<5;i++)
{
for(int j=0; j<5;j++)
{
System.out.print(ref[i][j]);
}
System.out.println();
}
Q5. 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:
Code:-
char act[][]= new char[5][5];
for(int L=0;L<5; L++)
{
String input = sc.nextLine();
char pat[] = input.toCharArray();
if(pat.length==5){
for(int i=0;i<5;i++)
{
if(pat[i]=='0' || pat[i]=='1')
{
act[L][i]=pat[i];
if(L==4 && i==4)
flipflop(act);
}
else
{
System.out.print("Only 0 and 1 supported.");
break;
}
}
}else
{
System.out.print("Invalid length");
break;
}
}
}
static void flipflop(char[][] flip)
{
for(int i=0; i<5;i++)
{
for(int j=0; j<5;j++)
{
if(flip[i][j]=='1')
flip[i][j]='0';
else
flip[i][j]='1';
}
}
for(int i=0; i<5;i++)
{
for(int j=0; j<5;j++)
{
System.out.print(flip[i][j]);
}
System.out.println();
}
πFOR NEXT WEEK ASSIGNMENT ANSWERSπ
Disclaimer:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.
For More NPTEL Answers:- CLICK HERE
Join Our Telegram:- CLICK HERE
Programming In Java Assignment 9 Answers 2022:- All the Answers provided here to help the students as a reference, You must submit your assignment at your own knowledge
If you found this article Interesting and helpful, donβt forget to share it with your friends to get this information.