CSE 566 Assignment 5
CSE 566 Assignment 5
CSE 566 Assignment 5
I have chosen an android project written in JAVA for the Resource Standard Metrics. This is a
project I have done in another course this semester. This project has 4 activities divided into 4
classes (files), MainActivity.java, PlaceActivity.java, MapsActivity.java, and
SettingsActivity.java respectively.
The metrics I have chosen are as follows:
Default Metrics:
RSM Report: M2 - Functional Metrics and Analysis
• -c Metrics for the cyclomatic, interface, and total complexity.
• -fa Functional context for metrics and analysis.
• -fp Function point metrics derived from lines of code and Fp factors.
• -k1 Sort by entity names such as file, class, and function.
• -o Object class and struct context for metrics and analysis reporting.
Additional Metrics:
• -n Source code quality analysis notices and recommendations.
Cyclomatic complexity is a measurement developed by Thomas McCabe to gauge a program’s
stability and level of trust. It counts how many linearly independent pathways a software module
has. Lower Cyclomatic complexity programs are easier to comprehend and alter with less risk.
Interface complexity describes the degree of complexity that a user encounters when engaged
with a digital medium like a website. When the rising complexity of a web page’s interface, for
example, the user is forced to devote more cognitive resources to studying the interface’s subtleties
rather than the website’s content.
From the above definitions, we can conclude that the low -c leads to better performance and
maintenance of the project. For the project, I have chosen the average cyclomatic complexity is
1.82 and the average interface complexity is 1.55. From these values, we can conclude that the
project is very easily readable, maintainable, and testable.
The function-wise complexity, eLOC, lLOC, and comments supplied to identify and understand
the variables impacting each function within a project provide the functional context for metrics
and analysis. This makes it easy for the programmers to maintain the code and find issue areas that
make the project perform poorly and fix them based on the metric value. LOC has a functional
point of 4.9, eLOC of 3.7, and ILOC of 3.1. These are exceptionally low numbers, suggesting that
the function is effective at its job and is simple to maintain.
The amount of complexity of a function inside the project is determined by the Functional
Cyclomatic Complexity thorough study.
File summary for the class MainActivity.java
In the above screenshot, we can see the file summary of the file MainActivity.java. This shows us
multiple details of the file like Total function LOC, eLOC, lLOC, Max function parameters, and
many more. We can see that the LOC has a functional point of 2.6, eLOC of 2.1, ILOC of 1.7,
average cyclomatic complexity is 1.50 and the average interface complexity is 1.75. These are
exceptionally low numbers, suggesting that the function is effective at its job and is simple to read,
maintain and test.
File summary for the class MapsActivity.java
In the above screenshot, we can see the file summary of the file MainActivity.java. This shows us
multiple details of the file like Total function LOC, eLOC, lLOC, Max function parameters, and
many more. We can see that the LOC has a functional point of 3.2, eLOC of 2.5, ILOC of 1.9,
average cyclomatic complexity is 2.56 and the average interface complexity is 1.33. This class has
the highest values among all other files but they are still within an acceptable range and are low
numbers, suggesting that the function is effective at its job and is simple to read, maintain and test.
File summary for the class MapsActivity.java
In the above screenshot, we can see the file summary of the file MainActivity.java. This shows us
multiple details of the file like Total function LOC, eLOC, lLOC, Max function parameters, and
many more. We can see that the LOC has a functional point of 0.6, eLOC of 0.5, ILOC of 0.4,
average cyclomatic complexity is 1.00 and the average interface complexity is 2.00. These are
exceptionally low numbers, suggesting that the function is effective at its job and is simple to read,
maintain and test.
File summary for the class SettingsActivity.java
In the above screenshot, we can see the file summary of the file MainActivity.java. This shows us
multiple details of the file like Total function LOC, eLOC, lLOC, Max function parameters, and
many more. We can see that the LOC has a functional point of 0.7, eLOC of 0.5, ILOC of 0.4,
average cyclomatic complexity is 1.00 and the average interface complexity is 1.33. These are
exceptionally low numbers, suggesting that the function is effective at its job and is simple to read,
maintain and test.
Project Summary:
Additional Metric:
The additional metric I have used for this project is the following:
• -n Source code quality analysis notices and recommendations.
Code Quality distinguishes between good (high quality) and bad (low quality) code. Quality, good
and terrible is all subjective terms. Depending on the situation, various teams may employ different
meanings. For a desktop application developer, high-quality code might imply several things. For
a web application developer, it may imply something quite different.
There are five key traits to measure for high quality. They are:
1. Reliability
2. Maintainability
3. Testability
4. Portability
5. Reusability
There are several metrics we can test to quantify the quality of our code.
Defect Metrics: The number of defects and the severity of those defects are important factors in
the overall quality of the code.
Complexity Metrics: Complexity metrics can help in measuring the quality of our code. Mainly
the cyclomatic complexity measures the number of linearly independent paths through a program’s
source code.
The additional metric I have selected for this project lists out all the quality analysis notices and
recommendations in the form of “Notice”. These notices are given for each function in every
individual file in the entire project.
These help us a lot in improving the quality of our code. These are very easy to fix and also help
us improve the quality of our code considerably.
Let us take an example of notice and see how to fix that.
Notice #51: Line 109: A function has been identified which does not
have a preceding comment. Comments that detail the purpose,
algorithms, and parameter/return definitions are suggested.
This is a notice from the syncDatabase() function of the MainActivity.java. This notice tells us
that, this function does not have a preceding comment. To fix this we have to go to that particular
function in the specified file and add a comment detailing the purpose, algorithms, and
parameter/return definitions are suggested. This will resolve the notice.
MainActivity.java
I’m providing a file from the project I’ve used.
package edu.asu.msse.catkuri.placemng;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import edu.asu.msse.catkuri.placemng.database.PlaceManagerDbHelper;
import edu.asu.msse.catkuri.placemng.models.PlaceDescription;
/**
* Copyright 2022 Chandra Atkuri
* This code is free to use for educational purposes.
*
* @author Chandra Atkuri
* mailto: [email protected]
* @version April 4, 2022
* <p>
* Lists the places in the database. Acts as the main activity of the app.
*/
public class MainActivity extends AppCompatActivity
{
private PlaceManagerDbHelper dbHelper;
private ListView listView;
public ArrayAdapter<String> adapter;
public String[] names;
@Override
protected void onCreate(Bundle savedInstanceState)
{
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
* Creates an intent with the given bundle. Starts the PlaceListActivity.
*
* @param bundle Bundle to encapsulate in the new activity's intent
*/
private void goToListView(Bundle bundle)
{
Intent intent = new Intent(this, PlaceActivity.class);
intent.putExtras(bundle);
startActivity(intent);
}
while (cursor.moveToNext())
{
String name =
cursor.getString(cursor.getColumnIndexOrThrow("Name"));
dbNames.add(name);
}
cursor.close();
adapter.clear();
adapter.addAll(dbNames);
}
@SuppressLint("SetTextI18n")
private void syncDatabase()
{
Button syncBtn = findViewById(R.id.sync);
syncBtn.setText("Syncing");
dbHelper = new PlaceManagerDbHelper(this);
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM PlaceDescription where
PlaceId > ?", new String[]{"0"});
List<PlaceDescription> localPlaces = new ArrayList<>();
while (cursor.moveToNext())
{
PlaceDescription place = new PlaceDescription();
place.setName(cursor.getString(cursor.getColumnIndexOrThrow("Name")));
place.setCategory(cursor.getString(cursor.getColumnIndexOrThrow("Category")))
;
place.setDescription(cursor.getString(cursor.getColumnIndexOrThrow("Descripti
on")));
place.setAddressTitle(cursor.getString(cursor.getColumnIndexOrThrow("AddressT
itle")));
place.setAddressPostal(cursor.getString(cursor.getColumnIndexOrThrow("Address
")));
place.setElevation(Float.parseFloat(cursor.getString(cursor.getColumnIndexOrT
hrow("Elevation"))));
place.setLongitude(Float.parseFloat(cursor.getString(cursor.getColumnIndexOrT
hrow("Longitude"))));
place.setLatitude(Float.parseFloat(cursor.getString(cursor.getColumnIndexOrTh
row("Latitude"))));
localPlaces.add(place);
}
cursor.close();
syncBtn.setText(getResources().getString(R.string.syncBtn));
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == R.id.action_favorite) {// User chose the
"Settings" item, show the app settings UI...
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
int id = 0;
//for (String name: )
// get the local names
Cursor cursor = db.rawQuery("SELECT * FROM PlaceDescription where
Name = ?", new String[]{name});
while (cursor.moveToNext())
{
id = cursor.getInt(cursor.getColumnIndexOrThrow("PlaceId"));
}
cursor.close();
return id;
}
The use of this formula gives a value from 171 to an unbounded negative number. As difference
between the code at 0 and the negative values is not that useful. So the formula is modified as
follows:
Maintainability Index = MAX(0,(171 - 5.2 * ln(Halstead Volume) - 0.23 * (Cyclomatic
Complexity) - 16.2 * ln(Lines of Code))*100 / 171)
Cyclomatic Complexity: This metric assesses the code’s structural complexity. It’s made by
counting the number of various code routes in the program’s flow. Complex control flow programs
necessitate more tests to obtain acceptable code coverage and are less maintainable.
The cyclomatic complexity of a structured program is calculated using the program’s control flow
graph, a directed graph comprising the program’s basic blocks with an edge connecting two basic
blocks if control can transfer from one to the other. The complexity M is then defined as:
M = E – N + 2P
where,
E = Number of edges of the graph.
N = Number of nodes of the graph.
P = Number of connected components.