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

Tutorial 1 - Class With Data Members

The document describes how to create a Student class based on a UML class diagram. It includes declaring private string data members for surname, studentNumber, and an int age. It then provides another example of creating a Competition class with private data members for name and competitors, and a constant double BASIC_REG_FEE of R125.58. The steps are to open NetBeans, create a new project called StudentApp, add a new Java class, and populate it with the private data members from the UML diagram.

Uploaded by

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

Tutorial 1 - Class With Data Members

The document describes how to create a Student class based on a UML class diagram. It includes declaring private string data members for surname, studentNumber, and an int age. It then provides another example of creating a Competition class with private data members for name and competitors, and a constant double BASIC_REG_FEE of R125.58. The steps are to open NetBeans, create a new project called StudentApp, add a new Java class, and populate it with the private data members from the UML diagram.

Uploaded by

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

T1

 
Tutorial 1 – Creating a class with data members 
 
 
 
 
Purpose: 
The purpose of this tutorial is to illustrate the creation of a concrete class with its data 
members. You will be provided with the UML class diagram from which you need to 
create the class. 
 
 
You are provided with the following UML class diagram, that represents a Student class. 
A student must have a surname, student number, and an age.  
 
Student 
‐ surname: String 
‐ studentNumber: String 
‐ age: int 
 
Student UML Class Diagram 
 
1. Open NetBeans and create a new project called StudentApp. 
2. Under the new project create a new “Java Class” as shown in the figure 1. 
 

 
Figure 1 (New Java Class) 
 


Page 1 

3. You will have a new class as shown in figure 2 in the source window. 
 

 
Figure 2 (Student class) 
4. From the UML class diagram, we can now populate the data members of the class, 
starting with the “surname” data member. Note that the “‐ “sign means the access 
modifier is private and the data type is “String”. Following the syntax to declare a data 
member, as indicated in the comments of figure 3, the surname data member will be 
declared as shown in figure 3. 
 

 
Figure 3 
 
5. Note that we only declare data members. We do not initialize them, except if it is a 
constant data member. Will be illustrated in a later example. 
6. Now declare the rest of the data members as shown in figure 4. 
 

 
Figure 4 
 
7. You have successfully created a basic concrete class with its data members. 
 
 
 


Page 2 

Follow these steps and complete the class declaration with its data members for the 
Competition class as shown in the UML class diagram. A Competition must have a name, 
a basic registration fee and number of competitors. 
 
Competition 
‐ BASIC_REG_FEE: double 
‐ name: String 
‐ competitors: int 
 
Competition UML Class Diagram 
 
Note that the BASIC_REG_FEE data member is a constant data member with a fix price of 
R125.58 and should be declared using the following syntax: 
 
<access modifier> <final keyword> <data type> dataMemberName; 


Page 3 

You might also like