[Solved] CSE111 Lab 8
5.0
1 customer review
Digital download
Digital download
$25.00
Message us on WhatsApp for payment or download support.
Open WhatsApp
| 1. | class A{ |
| 2. | public int temp = 4; |
| 3. | public int sum = 1; |
| 4. | public int y = 2; |
| 5. | public A(){ |
| 6. | y = temp 2; |
| 7. | sum = temp + 3; |
| 8. | temp-=2; |
| 9. | } |
| 10. | public void methodA(int m, int n){ |
| 11. | int x = 0; |
| 12. | y = y + m + (temp++); |
| 13. | x = x + 2 + n; |
| 14. | sum = sum + x + y; |
| 15. | System.out.println(x + + y+ + sum); |
| 16. | } |
| 17. | } |
| 18. | class B extends A { |
| 19. | public int x = 1; |
| 20. | public int sum = 2; |
| 21. | public B(){ |
| 22. | y = temp + 3 ; |
| 23. | sum = 3 + temp + 2; |
| 24. | temp-=1; |
| 25. | } |
| 26. | public B(B b){ |
| 27. | sum = b.sum; |
| 28. | x = b.x; |
| 29. | } |
| 30. | public void methodB(int m, int n){ |
| 31. | int y =0; |
| 32. | y = y + this.y; |
| 33. | x = this.y + 2 + temp; |
| 34. | methodA(x, y); |
| 35. | sum = x + y + super.sum; |
| 36. | System.out.println(x + + y+ + sum); |
| 37. | } |
| 38. | } |
| A a1 = new A(); B b1 = new B(); B b2 = new B(b1); a1.methodA(1, 1); b1.methodA(1, 2); b2.methodB(3, 2); | x | Y | Sum |
| public class Student{ |
| private String name = Just a Student; |
| private String department = nothing; |
| public void setDepartment(String dpt){ |
| this.department = dpt; |
| } |
| protected String getName(){ |
| return name; |
| } |
| protected void setName(String name){ |
| this.name = name; |
| } |
| public String toString(){ |
| return Name : + name + Department: + department; |
| } |
| } |
| public class TestStudent{ |
| public static void printName(Student s){ |
| System.out.println(s.toString()); |
| } |
| public static void main(String [] args){ |
| printName(new BBAStudent()); |
| printName(new BBAStudent(Humty Dumty)); |
| printName(new BBAStudent(Little Bo Peep)); |
| } |
| } |
| // see, output for following two lines are same because toString() is automatically called. So, you can omit toString when printing. System.out.println(car.toString());System.out.println(car);}} |
| Expected Output: (0, 0)(0, 1)(-1, 1)(-1, 0)(0, 0)(0, 0) |
| public class Vehicle2010User{ public static void main(String[] args){Vehicle2010 car = new Vehicle2010(); System.out.println(car); car.moveLowerLeft();System.out.println(car); Vehicle2010 car2 = new Vehicle2010(); car2.moveLeft();System.out.println(car.equals(car2)); car2.moveDown();System.out.println(car.equals(car2));}} |
| Expected Output: (0, 0) (-1, -1) false true |
| public class Tester { |
| public static void main(String[] args) { |
| RealNumber rn = new ComplexNumber(); |
| System.out.println(rn); |
| System.out.println(); |
| rn = new ComplexNumber(5, 7); |
| System.out.println(rn); |
| System.out.println(); |
| ComplexNumber cn = new ComplexNumber(); |
| cn.check(); |
| } |
| } |
| public class RealNumber { |
| private double realValue; |
| public double getRealValue() { |
| return realValue; |
| } |
| public void setRealValue(double r) { |
| realValue = r; |
| } |
| public RealNumber() { |
| this(0); |
| } |
| public RealNumber(double r) { |
| setRealValue(r); |
| } |
| public String toString() { |
| return RealPart: +getRealValue(); |
| } |
| public void ping() { |
| System.out.println(Im in RealNumber class); |
| } |
| } |
| public class Test{ |
| public static void testFruit(Fruit f){ |
| System.out.println(-Printing Detail); |
| if(f.hasFormalin()){ |
| System.out.println(Do not eat the +f.getName()+.); |
| System.out.println(f); |
| }else{ |
| System.out.println(Eat the +f.getName()+.); |
| System.out.println(f); |
| } |
| } |
| public static void main(String [] args){ |
| Mango m = new Mango(); |
| testFruit(m); |
| Jackfruit j = new Jackfruit(); |
| testFruit(j); |
| } |
| } |
| public class Fruit{ |
| private boolean formalin = false; |
| public String name = ; |
| public Fruit(boolean formalin, String name){ |
| this.formalin = formalin; |
| this.name = name; |
| } |
| public String getName(){ |
| return name; |
| } |
| public boolean hasFormalin(){ |
| return formalin; |
| } |
| } |
| public class Account{ |
| protected double balance = 0.0; |
| public Account(double balance){ |
| this.balance = balance; |
| } |
| public double getBalance(){ |
| return balance; |
| } |
| } |
| public class TestAccount{ |
| public static void printBalance(Account a){ |
| System.out.println(Account Balance: + a.getBalance()); |
| } |
| public static void main(String [] args) |
| { |
| System.out.println(Number of Checking Accounts: + CheckingAccount.numberOfAccount); |
| printBalance(new CheckingAccount()); |
| printBalance(new CheckingAccount(100.00)); |
| printBalance(new CheckingAccount(200.00)); |
| System.out.println(Number of Checking Accounts: + CheckingAccount.numberOfAccount); |
| } |
| } |
| public class Student{ |
| public String msg = I love BU; |
| public String shout(){ |
| return msg; |
| } |
| } |
| public class TestStudent{ |
| public static void printShout(Student s){ |
| System.out.println(); |
| System.out.println(s.msg); |
| System.out.println(s.shout()); |
| } |
| public static void main(String [] args){ |
| Student s = new Student(); |
| CSEStudent cs = new CSEStudent(); |
| CSE111Student cs111 = new CSE111Student(); |
| System.out.println(s.msg); |
| System.out.println(cs.msg); |
| System.out.println(cs111.msg); |
| printShout(s); |
| printShout(cs); |
| printShout(cs111); |
| } |
| } |
| Output |
| I love BUI want to transfer to CSE I love Java Programming I love BU I love BU |
| 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 extends A { |
| public static int x; |
| public int sum; |
| 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 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 int temp = 4; |
| public int sum; |
| public int y; |
| public A(){ |
| y = temp 2; |
| sum = temp + 3; |
| temp-=2; |
| } |
| public void methodA(int m, int n){ |
| int x = 0; |
| y = y + m + (temp++); |
| x = x + 2 + n; |
| sum = sum + x + y; |
| System.out.println(x + + y+ + sum); |
| } |
| } |
| class B extends A { |
| public int x; |
| public int sum; |
| public B(){ |
| y = temp + 3 ; |
| sum = 3 + temp + 2; |
| temp-=1; |
| } |
| public B(B b){ |
| sum = b.sum; |
| x = b.x; |
| } |
| 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); a1.methodA(1, 1); b1.methodA(1, 2); b2.methodB(3, 2); | x | y | sum |
| 1 | class A{ |
| 2 | public int temp = 4; |
| 3 | public int sum = 1; |
| 4 | public int y = 2; |
| 5 | public A(){ |
| 6 | y = temp 2; |
| 7 | sum = temp + 3; |
| 8 | temp-=2; |
| 9 | } |
| 10 | public void methodA(int m, int n){ |
| 11 | int x = 0; |
| 12 | y = y + m + (temp++); |
| 13 | x = x + 2 + n; |
| 14 | sum = sum + x + y; |
| 15 | System.out.println(x + + y+ + sum); |
| 16 | } |
| 17 | } |
| 18 | class B extends A { |
| 19 | public int x = 1; |
| 20 | public int sum = 2; |
| 21 | public B(){ |
| 22 | y = temp + 3 ; |
| 23 | sum = 3 + temp + 2; |
| 24 | temp-=1; |
| 25 | } |
| 26 | public B(B b){ |
| 27 | sum = b.sum; |
| 28 | x = b.x; |
| 29 | } |
| 30 | public void methodB(int m, int n){ |
| 31 | int y =0; |
| 32 | y = y + this.y; |
| 33 | x = this.y + 2 + temp; |
| 34 | methodA(x, y); |
| 35 | sum = x + y + super.sum; |
| 36 | System.out.println(x + + y+ + sum); |
| 37 | } |
| 38 | } |
| A a1 = new A(); B b1 = new B(); B b2 = new B(b1); a1.methodA(1, 1); 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 A(){ |
| y = temp 1; |
| sum = temp + 2; |
| temp-=2; |
| } |
| 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(x + + y+ + sum); |
| } |
| } |
| class B extends A { |
| public static int x = 1; |
| public int sum = 2; |
| public B(){ |
| y = temp + 1 ; |
| x = 3 + temp + x; |
| temp-=2; |
| } |
| public B(B b){ |
| sum = b.sum + super.sum; |
| x = b.x + x; |
| } |
| public void methodB(int m, int n){ |
| int [] y = {0}; |
| super.y = y[0] + this.y + m; |
| x = super.y + 2 + temp n; |
| methodA(x, y); |
| sum = x + y[0] + super.sum; |
| System.out.println(x + + y[0]+ + sum); |
| } |
| } |
| int x[] = {23}; A a1 = new A(); B b1 = new B(); B b2 = new B(b1); | |||
| a1.methodA(1, x); b2.methodB(3, 2); a1.methodA(1, x); | |||
| public class FinalT6A{ |
| public static int temp = 4; |
| private int sum; |
| private int y = 1; |
| public FinalT6A(int x, int p){ |
| temp+=1; |
| 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 + 3 + 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 |