[Solved] CSE111 Lab 5
5.0
1 customer review
Digital download
Digital download
$25.00
Message us on WhatsApp for payment or download support.
Open WhatsApp
| class msgClass{ |
| public int content; |
| } |
| public class FinalT5A{ |
| private int sum = 2; |
| private int y = 1; |
| public int x = 1; |
| public void methodA(){ |
| int x=0, y =0, i = 0; |
| while (i < 2){ |
| msgClass myMsg = new msgClass(); |
| myMsg.content = this.x; |
| this.y = this.y + methodB(myMsg, myMsg.content); |
| System.out.println(x + + y+ + sum); |
| y = this.y / 2; |
| x = y + sum/2 i; |
| sum = x + y + myMsg.content; |
| i++; |
| } |
| System.out.println(x + + y+ + sum); |
| } |
| private int methodB(msgClass mg2, int mg1){ |
| int x = 0; |
| y = y + mg2.content; |
| mg2.content = y + mg1; |
| x = this.x + 3 + mg1; |
| sum = sum + x + y; |
| System.out.println(this.x + + this.y+ + sum); |
| mg2.content = sum mg1 ; |
| return sum; |
| } |
| } |
| FinalT5A fT5A = new FinalT5A(); fT5A.methodA(); | x | y | sum |
| public class FinalT6A{ |
| public static int temp = 3; |
| private int sum; |
| private int y = 2; |
| public FinalT6A(int x, int p){ |
| temp+=3; |
| y = temp p; |
| sum = temp + x; |
| System.out.println(x + + y+ + sum); |
| } |
| public void methodA(){ |
| int x=0, y =0; |
| y = y + this.y; |
| x = this.y + 2 + temp; |
| sum = x + y + methodB(temp, y); |
| System.out.println(x + + y+ + sum); |
| } |
| public int methodB(int temp, int n){ |
| int x = 0; |
| y = y + (++temp); |
| x = x + 2 + n; |
| sum = sum + x + y; |
| System.out.println(x + + y+ + sum); |
| return sum; |
| } |
| } |
| FinalT6A q1 = new FinalT6A(2,1); q1.methodA(); q1.methodA(); | x | y | sum |
| Quiz1 q1 = new Quiz1(); q1.methodA(); q1.methodA(); Quiz1.temp+= 2; Quiz1 q2 = new Quiz1(2); q2.methodA(); q2.methodA(); | x | y | sum |
| class A{ |
| public static int temp = 4; |
| public int sum; |
| public int y; |
| public A(){ |
| y = temp 2; |
| sum = temp + 1; |
| temp-=2; |
| } |
| public void methodA(int m, int n){ |
| int x = 0; |
| y = y + m + (temp++); |
| x = x + 1 + n; |
| sum = sum + x + y; |
| System.out.println(x + + y+ + sum); |
| } |
| } |
| class B{ |
| public static int x; |
| public int y = 5; |
| public int temp = -5; |
| public int sum = 2; |
| public B(){ |
| y = temp + 3 ; |
| sum = 3 + temp + 2; |
| temp-=2; |
| } |
| public B(B b){ |
| sum = b.sum; |
| x = b.x; |
| b.methodB(2,3); |
| } |
| public void methodA(int m, int n){ |
| int x = 2; |
| y = y + m + (temp++); |
| x = x + 5 + n; |
| sum = sum + x + y; |
| System.out.println(x + + y+ + sum); |
| } |
| public void methodB(int m, int n){ |
| int y = 0; |
| y = y + this.y; |
| x = this.y + 2 + temp; |
| methodA(x, y); |
| sum = x + y + sum; |
| System.out.println(x + + y+ + sum); |
| } |
| } |
| A a1 = new A(); B b1 = new B(); B b2 = new B(b1); b1.methodA(1, 2); b2.methodB(3, 2); | x | y | sum |
| class A{ |
| public static int temp = 3; |
| public int sum; |
| public int y; |
| public int x; |
| public A(){ |
| int temp = -3; |
| int sum = 7; |
| y = temp 5; |
| sum = temp + 2; |
| temp-=2; |
| this.x = sum + temp + y; |
| } |
| public A(int y, int temp){ |
| y = temp 1+ x; |
| sum = temp + 2 -x; |
| temp-=2; |
| } |
| public void methodA(int m, int [] n){ |
| int x = 0; |
| y = y + m + methodB(x,m)+(temp++)+y; |
| x = this.x + 2 + (++n[0]); |
| sum = sum + x + y; |
| n[0] = sum + 2; |
| System.out.println(n[0] + x + + y+ + sum + n[0]); |
| } |
| public int methodB(int m, int n){ |
| int [] y = {0}; |
| this.y = y[0] + this.y + m; |
| x = this.y + 2 + temp n; |
| sum = x + y[0] + this.sum; |
| System.out.println(y[0]+ x + this.temp + y[0]+ +sum+ y[0]); |
| return y[0]; |
| } |
| } |
| class B{ |
| public int y=1; |
| public int temp=-3; |
| public int x = 1; |
| public static int sum = 2; |
| public B(){ |
| y = temp + 1 ; |
| x = 3 + temp + x; |
| temp-=2; |
| } |
| public B(B b){ |
| sum = b.sum + this.sum; |
| x = b.x + x; |
| b.methodB(3,5); |
| } |
| public void methodA(int m, int [] n){ |
| int x = 0; |
| y = y + m + (temp++); |
| x = x + 2 + (++n[0]); |
| sum = sum + x + y; |
| n[0] = sum + 2; |
| System.out.println(temp + x + + y+ + sum + temp); |
| } |
| public void methodB(int m, int n){ |
| int [] y = {0}; |
| this.y = y[0] + this.y + m; |
| x = this.y + 2 + temp n; |
| methodA(x, y); |
| sum = x + y[0] + this.sum; |
| System.out.println(n + x + + y[0]+ + sum + n); |
| } |
| } |
| Consider the following code: |
| int x[] = {35}; |
| A a1 = new A(); |
| A a2 = new A(-5,-7); |
| B b1 = new B(); |
| B b2 = new B(b1); |
| a1.methodA(1, x); |
| b2.methodB(3, 2); |
| a2.methodA(1, x); |
| class msgClass{ |
| public int content; |
| } |
| public class Quiz3{ |
| private int sum; |
| private int y; |
| public static int x; |
| public Quiz3(){ |
| sum = 5; |
| x = 2; |
| y = 2; |
| } |
| public Quiz3(int k){ |
| sum = sum + k; |
| y = 3; |
| x += 2; |
| } |
| public void methodA(){ |
| int x=1, y=1; |
| msgClass [] msg = new msgClass[1]; |
| msgClass myMsg = new msgClass(); |
| myMsg.content = Quiz3.x; |
| msg[0] = myMsg; |
| msg[0].content = this.y + myMsg.content; |
| this.y = this.y + methodB(msg[0]); |
| y = methodB(msg[0]) + this.y; |
| x = y + methodB(msg, msg[0]); |
| sum = x + y + msg[0].content; |
| System.out.println(x + + y+ + sum); |
| } |
| private int methodB(msgClass [] mg2, msgClass mg1){ |
| int x = 2; |
| y = y + mg2[0].content; |
| mg2[0].content = y + mg1.content; |
| x = x + 2 + mg1.content; |
| sum = sum + x + y; |
| mg1.content = sum mg2[0].content ; |
| System.out.println(Quiz3.x + + this.y+ + sum); |
| return sum; |
| } |
| public int methodB(msgClass mg1){ |
| int x = 1, y = 2; |
| y = sum + mg1.content; |
| this.y = y + mg1.content; |
| x = Quiz3.x + 5 + mg1.content; |
| sum = sum + x + y; |
| Quiz3.x = mg1.content + x + 3; |
| System.out.println(x + + y+ + sum); |
| return y; |
| } |
| } |
| Quiz3 a1 = new Quiz3(); Quiz3 a2 = new Quiz3(5); msgClass msg = new msgClass(); a1.methodA(); a2.methodB(msg); | x | y | sum |
| Code | Output |
| public class StudentTest{ public static void main(String [] args){ Student s1 = new Student(); System.out.println(s1.getName()); Student s2 = new Student(Matin); System.out.println(s2.getName()); Student s3 = new Student(Saad); System.out.println(s3.getName()); System.out.println(Student.numberOfStudents); } } | default name Matin Saad 3 |