You are on page 1of 3

CS 111T - Lab

Programming Language 2
Computer Science Department
2022

Lab Objectives:
In this lab, a student will practice

• In this lab, the student will practice: • Declaring accessors and mutators
• Creating a class declaration. methods.
• Declaring instance variables. • Writing a test application to
• Declaring a constructor. demonstrate the capabilities of another
• Overloading constructor. class.
• Reading part of a UML class
diagram/access modifier.
Lab Exercise 1:

Based on the UML class diagram below, create the needed instance variables, set and get
method and constructors; then write a test application to demonstrate the classes
capabilities.

Exam
- ExamName: String
- ExamNo: int
- Difficulty: boolean
- ??????????????
+ << all setter>>
+ <<all getter>>
+ <<Constructor>> Exam( )
+ <<Constructor>> Exam (int ExamNo ,String ExamName )
+ checkDifficulty ( Difficulty: String) : void
+ ????????????????

Consider the following points:


• Add any appropriate attribute to the class Exam. NOTE: use different data types
than string and int.
• checkDifficulty Method: this method takes Difficulty as parameter and it should
display "The test was hard" if it is true otherwise display “The test was super easy”.
• Write a method that print out all the attributes.
In your main class:
o Create 2 different Exam objects.
o Call one setter and one getter.
o Call checkDifficulty method for the object created.
o Print all information of the object crated.
Assignment

Write a Java program that models the properties and behaviours of any object from your
choice. Note: Animal, Person, Student, and Customer are not accepted as answer.

Write maximum 4 properties, and at least 1 behaviour. All fields must be private. Provide
getter and any necessary setter methods and one constructor.

You’ll also need a test class that contains a main method to create objects of the class.

You might also like