Question

In: Computer Science

Question 1) Identify the type of bad smells and refactor the given code. 1. Code 1:...

Question 1) Identify the type of bad smells and refactor the given code.

1. Code 1:

public double sumSquaresArea ( L1, L2 )

{

area1 = smallSquareArea(L1);

area2 = bigSquareArea(L2);

return area1+area2

}

public double smallSquareArea ( L1)

{

area = L1 * L1;

return area;

}

public double bigSquareArea ( L2 )

{

area = L2 * L2;

return area;

}

2. Code 2:

class Student

{

private string name;

public void getStudentMarks ( );

}

class Course_Marks

{

private int course_id;

private string semester;

public void getStudentMarks ( );

}

3. Code 3:

public void accountInfo(string account_title, string account_number, string account_type)

{

// Generate Monthly Statement

if(account_type == “Current”)

{

// do something

}

else if (account_type == “Saving”)

{

// do something

}

else

{

//do something

}

  

//Account information

System.out.println(“***** Account Information *****”);

System.out.println(“Account_Title : ” , account_title);

System.out.println(“Account Number : ” , account_number);

System.out.println(“Account_Type : ” , account_type);

System.out.println(“Monthly Statement : ”, monthly_statement );

}

Solutions

Expert Solution

Question 1 :-

Explanation :-

Return type and data type of the arguements are not present and semi color during return was not written due to which error raised. Corrected code

Program :-

public double sumSquaresArea (double L1,double L2 )
{
double area1 = smallSquareArea(L1);
double area2 = bigSquareArea(L2);
return area1+area2;
}
  
public double smallSquareArea (double L1)
{
double area = L1 * L1;
return area;
}
  
public double bigSquareArea (double L2 )
{
double area = L2 * L2;
return area;
}

Question 2:-

Explanation :-

There were two issues. One was string data type. It should be "String". And, second as there is no function definition we need to set class and methods as abstract.

Program :-

abstract class Student

{

private String name;

public abstract void getStudentMarks ( );

}

abstract class Course_Marks

{

private int course_id;

private String semester;

public abstract void getStudentMarks ( );

}

Code 3 :-

Explanation :-

Many errors :-

1) monthly_statement variable is not defined but used for printing the value. So, I have commented it

2) string variables should be declared by String

3) In printing statement, two elements are merged through "+" symbol not with "," symbol

Code :-

public void accountInfo(String account_title, String account_number, String account_type)
{
// Generate Monthly Statement   
if(account_type == "Current")
{
// do something
}
else if (account_type == "Saving")
{
// do something
}
else
{
//do something
}

//Account information
System.out.println("***** Account Information *****");
System.out.println("Account_Title : " + account_title);
System.out.println("Account Number : " + account_number);
System.out.println("Account_Type : " + account_type);
//System.out.println("Monthly Statement : "+ monthly_statement );
}


Related Solutions

Module 2 Programming Assignment – Battleship Refactor Refactor your Battleship drawing code from Module 1. Download...
Module 2 Programming Assignment – Battleship Refactor Refactor your Battleship drawing code from Module 1. Download the OO template for the basic battleship game, BattleshipRefactor.zip (refer below) The template has the outline of a battleship game using OO constructs. You need to add the Grid class and complete the code so that it runs correctly. At a minimum, you need to complete the Draw and DropBomb methods with code similar to the previous assignment. There will be changes due to...
1. Identify what they are given and what they need to find; 2. Identify the type...
1. Identify what they are given and what they need to find; 2. Identify the type of problem they have been given and the tools necessary to solve the problem; 3. Correctly apply the tools to the information given to set up the problem; 4. Perform mathematically correct calculations to determine a solution; 5. Interpret their results in terms of the original problem. Use the internet and find the Medicare expenditures in the year 2000 and the Medicare expenditures in...
Fill in the blanks with suitable code and identify the type of inheritance in the following...
Fill in the blanks with suitable code and identify the type of inheritance in the following code snippet.(CO5) [Write all the three constructors completely in the answer sheet. Don’t write any other parts of the program] class Xyz { int one, two; public: Xyz(--------) {one=i; --------; } }; class Abc { int dc; public: Abc(int k) {-----------;} }; class Ijk: public Abc, public Xyz { int f; public: Ijk(int l, int m, int z, int n):-------,--------- { f=n;} }; int...
----- Please solve the questions with the code below. Thank you. ----- Exercise Overview Refactor your...
----- Please solve the questions with the code below. Thank you. ----- Exercise Overview Refactor your code to enhance the user experience and to use objects and classes. All functional requirements in Project 1 remain, except where enhancing the system replaces specific functions. Functional Requirements The console entry point for the user inputs is on the same line as the prompt. (new) User enters name at the beginning of a session. System covers four math operations – addition, subtraction, multiplication,...
Question 1) Identify the type of data that would be used to describe a response. Time...
Question 1) Identify the type of data that would be used to describe a response. Time in Line to Buy Groceries A. Qualitative (Categorical) B. Quantitative - Continuous C. Quantitative - Discrete Question 2) Identify the type of data that would be used to describe a response. Most Watched Television Show A. Quantitative - Discrete B. Quantitative - Continuous C. Qualitative (Categorical) Question 3. lege administrator wants to survey 250 students that attend her college to see if students are...
Question 4. The probability that an individual will suffer from a bad reaction of a given...
Question 4. The probability that an individual will suffer from a bad reaction of a given serum is .003. Out of 10000 individuals, compute the following probabilities using both the Binomial and Poisson models. Part 1. P (X = 0) where X is Binomial and then Poisson. Part 2. P (X > 10) where X is Binomial and then Poisson.
Question 1 (a) Identify the type of information that can beat the market under each form...
Question 1 (a) Identify the type of information that can beat the market under each form of market efficiency. (b) Janet, a junior analyst of an investment bank, kept an eye on the share price of Temcent Company, a fintech company with abundant analysts’ coverage. She noticed that the share price was increased by 10% immediately after the release of annual result announcement. She said to her senior colleague, Ricky, “The share price of Temcent is over-reacted to the result...
Language for this question is Java write the code for the given assignment Given an n...
Language for this question is Java write the code for the given assignment Given an n x n matrix, where every row and column is sorted in non-decreasing order. Print all elements of matrix in sorted order.Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the matrix. Then the next line contains the n x n elements...
// (A) Implement the code below. For a given graph, return a Set of type T...
// (A) Implement the code below. For a given graph, return a Set of type T of all of the strongly connected nodes of the given key. public Set<T> stronglyConnectedComponent(T key) { return null; } // (B) Implement the code below. Optimally find the shortest path between the given start and end node. public List<T> shortestPath(T startLabel, T endLabel) {        return null; }
Examine each of the following code fragments to identify the type of polymorphism it represents (overloading,...
Examine each of the following code fragments to identify the type of polymorphism it represents (overloading, coercion, parametric, or subtype) double x, y;    x = 5;    y = 4;      print("result= " + x / y);   b. int sum(int a, int b) {    std::cout << "Sum of ints\n";      return a + b;      }      double sum(double a, double b) {     std::cout << "Sum of doubles\n";     return a + b;      }      int main() {  ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT