0% found this document useful (0 votes)
10 views

electrical engineering

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

electrical engineering

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EE4011 Computer Software 1 Challenge #4

Challenge: #4
Marks: 0% of module marks
There will be a 5% Quiz later where marks will only be awarded if this
assignment is submitted in Brightspace.

Title: Exploring Java Classes and Objects

Objectives: • Work with a partner


• Develop skills in working with classes, objects, instance variables and methods.
• Design and code a class (Module) and a test class (ModuleTest)
• Use Javadoc to document each method.
Submission: Submit to Brightspace Assignments Challenge #4 by Wed 9 Oct, 16:00
(Late submission accepted until 12 Oct, 18:00)
Directly submit the java files Module.java and ModuleTest.java.
Ensure that an appropriate file header comment is included in each java source file
with author name(s), id number(s), last date of modification and a short description
of the java class.

Notes: All module handouts and laboratory/challenge work completed must be maintained
in an accessible file storage device. I’d suggest a top level folder per module.
Consider using a separate subfolder for this work, e.g. named Coursework4 or CW4.
Reminder: Maintain regular backups of all your work.

Two Challenge Exercises


::
Two different exercises are presented below. The reason to do both is to reinforce the concepts of:

1. class creation including instance variables and methods

2. class execution by creating objects and calling methods.

The first exercise class Module is very prescribed where the requirements are specified in a lot of
detail. The verbosity is to guide you step by step towards completion.

The optional second exercise requirements are deliberately sparse, to encourage you to reflect and
create, and thereby deepen your knowledge.

AY25a 1/3
EE4011 Computer Software 1 Challenge #4
Challenge Exercise 1: Extend the Module Class
Steps: 1. Start by reading the entire Module class requirements below.
2. Complete a UML Class Diagram using the attributes given, and the operations:
i.e. set/get methods, constructors, toString methods.
3. Code the class Module to represent the object selected.
4. Code the class ModuleTest to test all methods in the class Module.
5. When coding, pay attention to naming and code style and layout.
6. Ensure appropriate file header comments are in each Java file.

The Module class


Complete a class called Module to maintain information on a module taken in a course and test it by
writing code in a class called ModuleTest. You can extend the Module class completed in the
Coursework or start this from scratch in a new IDE project.
In the Module class, you should:
a) Create six attributes (pieces of information) as instance variables.
1. the module code (name it code of type String as it may contain characters e.g. "EE4011"),
2. the module title (name it title of type String),
3. the lecturer’s name (name it lecturer of type String),
4. the number of students (name it numberStudents of type int)
5. the number of contact hours per week (name it contact of type int)
6. the number of credits (name it credits of type double).
b) Provide three constructors to initialise the instance variables, each with a Javadoc comment.
• The first constructor with no parameters will explicitly initialize the six instance variables to their
default values (numeric variables: int/double to 0, object reference variables: String to null).
• The second constructor will accept three parameters for code, title and lecturer.
• The third constructor will accept six parameters corresponding to the six instance variables.
c) Provide a set and get method for each instance variable, each with a Javadoc comment.
• In the setContact method, if the method's contact parameter value is not positive then set it to 0, if
greater than 15, set to 15).
• In the setCredits method, only the credit values 2.5, 3, 5, 6, 7.5, 9 are allowed, otherwise set to 0.0.
d) Provide an appropriate toString method that returns a String representation of all the module details.

The ModuleTest class


Write a test application in a class named ModuleTest to demonstrate the class Module’s capabilities.
In your test application, you must call all the Module constructors and methods .
Create and handle three Module objects as follows:
e) For the first module, construct the object module1 using the six parameter constructor to set all the
attributes, then display it using the toString method.
f) For the second module, construct the object module2 using the three parameter constructor, then display it
using the toString method.
g) For the third module, construct the object module3 using the no parameter constructor. Use the set
methods to set each of the attributes to appropriate values. Then display the module details using
System.out.printf/println and get methods.

AY25a 2/3
EE4011 Computer Software 1 Challenge #4
Optional
Challenge Exercise 2: Design, code and test a class from scratch

Steps: Choose a real world object and create class to represent it. See examples below.
1. Select and name a class and identify the attributes you want to store.
2. Complete a UML Class Diagram defining the attributes, and the operations:
i.e. set/get methods, constructors, toString and any other methods.
3. Code the class ClassName to represent the object selected.
4. Code the class TestClassName to test all methods in the selected Class.
5. When coding, pay attention to naming, code style and layout.
6. Ensure appropriate file header comments are in each Java file.

1. Member of a Sports Club e.g. UL Sports & Social Club


2. Bank Card e.g. information maintained on your Debit/Credit card.
3. UL Room e.g. building, room number, capacity etc
4. Details for COVID-19 contact tracing: name, phone number, place, when etc.
5. Animal e.g. basic details for an animal at the Wild Ireland sanctuary
6. Target Heart-Rate Calculator, see Making a Difference: JavaHTP8e ex 3.11 p104 (9e ex 3.16 p101).
7. etc.

For the class selected:


a) Maintain at least 4 attributes and if there are potentially many select maximum 8.
b) Implement the corresponding set/get methods.
c) Perform appropriate checking in the set methods (simple checks will suffice e.g. positive numbers).
d) Implement at least two constructors (one which should be the no parameter constructor)
e) Implement the toString method.
f) Identify and code some appropriate test cases to execute all your methods.

AY25a 3/3

You might also like