0% found this document useful (0 votes)
62 views1 page

CSCI300L Sample Exam 1

Uploaded by

Hussein Shoeib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views1 page

CSCI300L Sample Exam 1

Uploaded by

Hussein Shoeib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

CSCI300L Sample Exam 1 Spring 2022-2023

Department of Computer Science and Information Technology


Name Id
Course CSCI300L Intermediate Programming with Objects
Date Time Duration 60 minutes

Part 1. (65 pts) Implement the class Student as presented in the following UML diagram:

Student
-name: String //could be formed of more than two words
-id: int
-gender: char
-gpa: double
+Student(n: String, i: int, g: char, gp: double) (10 pts)
+getFirstName(): String (10 pts) //returns the first word in name
+countWordsInName(): int (5 pts) //returns the number of words in name
+setGpa(gp: double): void (5 pts)
+setId(i: int): void (5 pts)
+isHonor(): boolean (5 pts)
+formatName(): void (10 pts) //capitalizes the first letter of every word in name
+getName(): String (5 pts) //returns the name after formatting it
+printDesrciption(): void (10 pts)

Note the following:


1. The id cannot be a negative value and the gpa should be between 0.0 and 4.0 inclusive. These
restrictions must be properly implemented within your code (setters and constructor). The data field
is to be set to -1 if the corresponding parameter’s value is invalid.
2. isHonor(): This method returns true if the student’s gpa is greater than 3.5 and false otherwise.
3. printDescription(): This method prints the information of the student as per the following example:

Mr. Karim Hassan Assaf, ID : 11232 is an Honor student with GPA 3.9
Note that the name is preceded by Mr. for male students and Ms. for females.
Part 2. (35 pts) Write a driver class to test the Student class as follows:
a. Create a student object using any data of your choice (Not from the user and different from the above
example) (5 pts)
b. Change its id with any other id. (5 pts)
c. Display the first name of the object (5 pts)
d. Display the number of words forming the object’s name (5 pts)
e. Format his/her name and then display it (5 pts)
f. Display whether the student is an Honor student or not (5 pts)
g. Print the description of the object(5 pts)

You might also like