Academic Year 2023-2024 Semester 1 / 420371 - Programming with Java EE / Assignment A
Academic Year 2023-2024 Semester 1 420371 - Programming with Java EE
Assignment A
When we are analyzing the source code of a Java project for certain purposes (e.g. locating the related scope of bugs), we commonly focus on the following two issues:
-
a) The invocation relationships among methods. For example, given a method, which method(s) invokes it, and which method(s) is invoked by it?
-
b) The original source of method parameters. For instance, given the sayHello method in the class below, its parameter name may be directly assigned by a literal in the main method when it invokes sayHello (i.e. "Jon"); and it may also be indirectly assigned in the introduction method, while this further contains two sub cases: (1) assigned by name2 (i.e. "Garfield") within the introduction method; and (2) indirectly assigned by name3 (i.e. "Odie") in the main method.
package main;
class Test {
void sayHello(String name) {
System.out.println("Hello, " + name + "!"); }
void introduction(String name1) {
sayHello(name1);
String name2 = "Garfield";
sayHello(name2);
}
public static void main(String[] args) { sayHello("Jon");
String name3 = "Odie";
introduction(name3);
}
}
General Requirements
Each team of candidates is required to design and implement a Java program for analyzing and displaying the above method invocation information in a specified Java project. All functionalities should be implemented in Java. Please focus on the design of system architecture and components, the implementation of functionalities and features, and the efficiency of program, as well as the readability of source code. There is no specific requirement on the user interface, while a simple command-line based program is well accepted.
Important tip: AST (abstract syntax tree) is a tree-like representation of the source code structure, which could be useful in analyzing the relationships among source code elements. You may consider
Page 1 of 5
Academic Year 2023-2024 Semester 1 / 420371 - Programming with Java EE / Assignment A
(but not necessarily) using the Java Parser library (please kindly refer to the reference for details).
The assessment will be based on both the presentation and submission. All teams will be randomly divided into three groups (namely Group A, Group B, and Group C), while each group is subject to different requirements as below:
Group
Group A Group B Group C
Functional Requirements
F0
F0 + F1
F0 + F2
Submission Due
11.59pm, 25 October 2023 11.59pm, 1 November 2023 11.59pm, 8 November 2023
Presentation Date
26 October 2023 2 November 2023 9 November 2023
F0: Basic Functional Requirements (For All Groups)
Design and implement a Java program that analyzes the source code of a specified Java project, and prints out the method invocation relationships, with the following features:
a) The end-user can use the program to load a specific Java project and specify any method of any class within this project, and consequently, the program prints out its callers and callees. This service should be supported in an on-demand manner, which implies that given a specified Java project, the program should firstly scan and analyze all method invocation relationships, properly store necessary data and information, and then quickly respond to the end-user’s queries. A set of input and output samples is presented below. Please note that the samples are for illustrative purpose only, but not compulsory requirements. Concrete formats of input and output can be designed in any way as long as all information can be clearly understood.
Input:
introduction, main.Test, depth=2
========
Output:
It is invoked by the following:
[main, main.Test (depth:1)] It invokes the following:
// Method name, class name, and depth of search
[sayHello, main.Test (depth:1)]
Input:
sayHello, main.Test, depth=2
========
Output:
It is invoked by the following:
[introduction, main.Test (depth:1)]
[main, main.Test (depth:2)] It invokes the following:
[NONE]
b) The program can completely print out all possible original sources of every parameter in each method from all classes, into a plain text file. The following output serves as a sample, while you may design any output format as long as it can be easily understood.
Page 2 of 5
Academic Year 2023-2024 Semester 1 / 420371 - Programming with Java EE / Assignment A
main.Test:
sayHello(String name):
String name:
["Jon": Line 15 of Test.java]
[name2: Line 11 of Test.java <-- "Garfield": Line 10 of Test.java]
[name1: Line 9 of Test.java <-- name1: Line 8 of Test.java
<-- name3: Line 17 of Test.java <-- "Odie": Line 16 of Test.java]
F1: Extended Feature 1 (For Group B Only)
When parsing the source code, a source code block may not be successfully identified by the parsing facilities if there exist code elements that are not completed yet, such as the following example. Please improve your program and try to implement additional mechanism for identifying such source code block as much as possible.
public class IncompleteClass {
private int a, b;
public int getSum()
this.a = 5;
// The left brace is missing
// Not finished yet
} }
this.b = 10;
int result = this.a +
F2: Extended Feature 2 (For Group C Only)
In object-oriented programming, a method may override another method in the parent class. Under such scenario, the method invocation depends on the type of object at runtime. For example, given the following source code, when the a.speak() statement is executed, it actually invokes the speak method in the Dog class rather than that in the Animal class. Please consider and support such situation with additional mechanism.
class Animal {
void speak() { System.out.println("Animal speaks"); }
}
class Dog extends Animal {
@Override
void speak() { System.out.println("Dog barks"); } }
class Main {
public void speak() {
} }
Animal a = new Dog();
a.speak(); // It actually invokes the speak method of the Dog class
Page 3 of 5
Academic Year 2023-2024 Semester 1 / 420371 - Programming with Java EE / Assignment A
References
-
Abstract Syntax Tree (AST): https://en.wikipedia.org/wiki/Abstract_syntax_tree
-
Java Parser: https://javaparser.org
Submission
Each team is required to submit a package consisting of the following materials:
-
a) The complete set of source code;
-
b) One project report that covers the following contents in the given order:
-
1) Full names and matriculation numbers of all team members, contact number, email address, and other particulars if any;
-
2) The complete list of system functionalities and features implemented;
-
3) A simple user manual (including UI samples and descriptions);
-
4) System architecture and components, general workflow, major data structures, efficiency considerations, and key techniques;
-
5) Other technical details and/or information, if any.
Note: The report should be written in English; file format for submission: PDF.
-
-
c) The presentation slides, with the first slide presenting the full names and matriculation numbers of all team members.
Note: The slides should be composed in English; file format for submission: PDF.
Please place the source code (a) and the documents (b and c) into different folders, compress them into one ZIP file, and submit it via Canvas.
Presentation
Each team is required to present the project within 20 minutes, followed by a Q&A session. The presentation should be delivered in English. Candidates are required to:
-
a) Explicitly demonstrate all implemented functionalities and features;
-
b) Present the design of system architecture and components, general workflow, major data structures, efficiency considerations, and key techniques, as well as other issues that are worth discussing;
-
c) Present the mechanisms, methods and skills of collaboration among team members;
-
d) Discuss important issues involved during the design and implementation, as well as the corresponding solutions.
Page 4 of 5
Academic Year 2023-2024 Semester 1 / 420371 - Programming with Java EE / Assignment A
Grading Criteria
Grading Criterion
Weight
Part A: Presentation
System functionalities and features 40% Technical design 30% Presentation quality 10%
Part B: Submission
Source code quality 10% Documentation quality 10%
THE END
Page 5 of 5