NEED 3 SOLUTIONS , AS THERE ARE 3 DIFFERENT PEOPLES ASSIGNMENTS JAVA LANGUAGE, WE NEED BY TOMORROW AFTERNOON 11;30PM, THE SUBMISSION WAS AT 12;30 . PLEASE SEND SOLUTIONS ASAP BEFORE DUE TIME, WE HAVE...

NEED 3 SOLUTIONS , AS THERE ARE 3 DIFFERENT PEOPLES ASSIGNMENTS JAVA LANGUAGE, WE NEED BY TOMORROW AFTERNOON 11;30PM, THE SUBMISSION WAS AT 12;30 . PLEASE SEND SOLUTIONS ASAP BEFORE DUE TIME, WE HAVE TO CHECK THE FILES

Qus 1: a.         Why is it important to consider refactoring when modifying existing class/classes?


b.         After completely refactoring a class, some of the unit testsmay fail.  Briefly discuss why maintaining a bank of unit tests and running these regularly is important for the refactoring process.



Qus 2 : Consider the following “Add” class:









 public class Add {


            private int array[];


            public Add(){


            }


             public Add(int a[]){


            this.setData(a);


            }


            public int Calculate(int P, int Q){


              int sum=0;



               for(int i=P;i


                       sum=sum+array[i];


              }


            return sum;


            }


            public void setData(int a[]){


            this.array=a;


            }



publicstaticvoid main(String args[]) {


int result, input []= {1,2,3,4,5,6,7,8,9,10};


            Add s =new Add(input);



            result = s.Calculate(0,4);


            System.
out
.println(result);



              }


    }
































The class has two constructor methods, and two other helping methods, and a private member variable (an array ofpositive numbers). The heart of the class is “Calculate” method which adds all the numbers between two indices (P and Q) and returns the sum.


The main method declares an object of the “Add” class, initializes the array with some integer numbers, passes two indices to calculate the sum, and prints the sum. Note that, the starting index of the array is 0.


Write 5 (five)Unit Tests for the above class to test Calculate method. Note that all the Unit tests should address distinct scenarios.




Qus 3: The code snippets below provide some of the contents of two classes: Fruit and Passion.














 public class Fruit {



 …



    public String toString() {



       return “From Fruit Class”;



    }



 }





 public class Passion extends Fruit {



 …



    public String toString() {



       return “From Passion Fruit Class”;



    }



 }



In this scenario, consider the following four pairs of statements (Object Declaration + Print), where one of the pairs isincorrect. Find out that one and discuss the reason. For the other three pairs, write down the answers and briefly discuss the reason.



















// pair-1



Fruit f1 = new Fruit();



System.out.println(f1.toString());




// pair-2



Fruit f2 = new Passion();



System.out.println(f2.toString());




// pair-3



Passion f3 = new Passion();



System.out.println(f3.toString());




// pair-4



Passion f4 = new Fruit();



System.out.println(f4.toString());




Qus 4 : a)     What are the characteristics of Unified Process? Describe the four phases of Unified Process.


b)    Design reusability is handled differently in Extreme Programming than in other conventional approaches.  Explain how this occurs.



Qus 5 : The following Employee class has some public data members: a String data member (Name), getter (getName) and setter (setName) methods, which implement some checks to ensure


o    Name cannot be set to a null value and


o    Name can be accessed only when its value is not null


Identify the coupling behavior for the following program and justify your answer. If you think that the following program is an example of a bad application design, write down the modified code that satisfies the properties of a good design.



publicclass Employee {


public String Name;


public String getName(){


if(Name==null)


return "Not initialized";


else


return Name;


            }


publicvoid setName(String Nm){


if(Nm!=null)


this.Name=Nm;


else


                        System.
out
.println("Name cannot be initialized to a null");


            }


}


publicclass Manager {


publicstaticvoid main(String[] args) {


             Employee emp=new Employee();


            emp.Name=null;


            System.
out
.println("Name is "+ emp.Name);


            }


 }



Qus 6 : Consider a car rental company from where you can rent a car of your choice. Once the customer selects a car to rent, a one-time checkout session is created to issue the invoice. Now consider the following class diagram with important entities of the system. Based on the properties of the system, the relationship between the classes can be aggregation, multiplicity, composition, association, generalization, etc.





Based on the above description, find out the appropriate values for:


A (relation between Customer and Rental Invoice)


B (relation between Rental Item and Rental Invoice)


C (relation between Checkout Session and Rental invoice)


D (relation between actual Vehicles and Rental Item class)


In addition, you have to write down the reason in brief for selecting that property.




Qus 7: What should be the goal while designing a subsystem in terms of Cohesion and Coupling? Discuss briefly.



Qus 8: a.    Identify the cohesive behavior for the following program and justify your answer.


b.     If you think that the program is an example of bad application design, write down the modified code that satisfies the properties of a good design.



publicclass Purchase {


publicvoid ConnectToSite(){


                        System.
out
.println("Inside ConnectToSite");


            }



publicvoid  SelectItems(){


                        System.
out
.println("Inside SelectItems");


            }


publicvoid ProceedToPayment(){


                       System.
out
.println("Inside ProceedToPayment");


            }


publicvoid CloseConnection(){


                        System.
out
.println("Inside CloseConnection");


            }



publicstaticvoid main(String[] args) {


            Purchase myPurchase =new Purchase();


            myPurchase.ConnectToSite();


            myPurchase.SelectItems();


            myPurchase.ProceedToPayment();


            myPurchase.CloseConnection();


            }


 }



Qus 9: The following questions relate to theStudent class provided below:


(a         Identify one (1) bad smell in the Student class and explain why this is an issue.  How can this bad smell be removed?


(b)        Rewrite the Student class to demonstrate the removal of the bad smell identified in part (a). You only need to rewrite the section that requires modification.




publicclass  Student{


private String name;


private String phone;


privateint id;


public Student() {


this.name=null;


this.phone=null;


this.id = 0;


               }


public Student(String name, String phone,int id) {


this.name= name;


this.phone=phone;


this.id = id;


               }


publicvoid setData(String name, String phone,int id) {


this.name = name;


this.phone = phone;


this.id = id;


               }


publicvoid showEmployeeDetail() {


if((this.name)==null || (this.phone)==null || (this.id)


                                       System.
out
.println("Missing Data from this object");


                           }


else{


                                    System.
out
.println("Name = " + name + ", Phone = " + phone + ", Age = " + id);


                           }


               }


publicstaticvoid main(String args[]) {


                  Student s1 =new Student();


                  s1.showEmployeeDetail();



                  Student s2 =new Student("James","0431794657", 41849012);


                  s2.showEmployeeDetail();



                  Student s3 =new Student();


                  s3.setData("Moly", "0496970808", 402020202);


                  s3.showEmployeeDetail();


                 }


            }


May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here