Concordia University
COMP 248 – Fall 2025
Assignment 1
Due Date:
Evaluation:
Late Submission:
Purpose:
By 11:59 pm Friday September 26, 2025
2% of final mark (see marking rubric at the end of handout)
none accepted
The purpose of this assignment is to help you learn Java
identifiers, assignments, input/output and string manipulation.
CEAB/CIPS Attributes: Design/Problem analysis/Communication Skills
NOTE 1: You are NOT allowed to post any assignment and/or its solution anywhere on the
World Wide Web (WWW) and/or the Internet. Intellectual Property Rights are reserved. If any
case is discovered via your account or IP address; your submission will NOT be considered and
will be reported immediately to the appropriate authority.
NOTE 2: (i) Neither use nor import any other library/package aside from: java.util.Scanner,
java.lang.Math, java.lang.String, and import java.util.Random;
(ii) Neither implement nor use any custom/user-defined function(s)/methods for any task
herein.
General Guidelines When Writing Programs:
Include the following comments at the top of your source codes
// ------------------------------------------------------// Assignment (include number)
// Written by: (include your name and student id)
// For COMP 248 Section (your section) – Fall 2025
// --------------------------------------------------------
● In a comment, give a general explanation of what your program does. As the programming
questions get more complex, the explanations will get lengthier.
● Include comments in your program describing the main steps in your program. Focus your
comments more on the why than the how.
● Display a welcome message.
● Display clear prompts for users when you are expecting the user to enter data from the
keyboard.
● All output should be displayed with clear messages and in an easy to read format.
● End your program with a closing message so that the user knows that the program has
terminated.
Question 1 - Manipulating integer (4 pts)
Write a program that reads two times (hours and minutes) into four variables of integer type. It is
safe to assume the user will enter valid values (0 ≤ hours ≤ 23, 0 ≤ minutes ≤ 59). You can assume
the two times are from the same calendar day, and the first time is before the second time.
- Your program first outputs each time in 24-hour format (hh:mm).
COMP248/Fall 2025- Assignment 1
Page 1 of 4
- Your program then computes and outputs the difference in minutes between the two times
(absolute value).
Following is a sample output screen. Data entered by the user is in green. Your program should work
for any numbers entered, not just the ones in the samples below.
Note: Your program must display the same information, but can be formatted differently.
Figure 1. Sample output of Question#1
Figure 2. Sample output of Question#1
Question 2 – User Registration (8 points)
Write a program that prompts the user for their favorite color, favorite animal, and birth city, and
automatically generates a screen name and secret code. Your program should behave as follows:
1. Display a welcome message.
2. Ask the user for input on three strings: favorite color, favorite animal, and birth city.
You can assume the user provides non-empty strings and that each string has at least three
characters.
3. A screen name is generated by:
3.1. taking the last 3 letters of the color,
3.2. appending the first 3 letters of the animal,
COMP248/Fall 2025- Assignment 1
Page 2 of 4
3.3.
4.
A secret code is generated using the following steps:
4.1.
4.2.
4.3.
4.4.
4.5.
5.
appending the length of the birth city string.
Concatenate the three user-input strings in the order they were entered.
Construct a new string by swapping the first and last letters, then keeping the middle
part unchanged (this avoids a full reverse).
Make the very first letter of this new string uppercase.
Take the first 5 letters of the new string, and replace the 3rd character with *.
Append a random digit between 0 and 9 at the end.
Display the generated screen name and secret code.
Restrictions: No looping statements allowed (or needed). This question requires the use of the
functions: length(), substring(), charAt(), toUpperCase()
The following are the sample screenshots to illustrate the expected behavior of your program.
Figure 3. Sample output of Question#2
Figure 4. Sample output of Question#2
COMP248/Fall 2025- Assignment 1
Page 3 of 4
Submitting Assignment 1
Please check your course Moodle webpage on how to submit the assignment.
Evaluation Criteria for Assignment 1 (20 points)
Source Code
Comments for all 2 questions (5 pts.)
Description of the program (authors, date, purpose)
Description of variables and constants
Description of the algorithm
Programming Style for all 2 questions (3 pts.)
Use of significant names for identifiers
Indentation and readability
Welcome Banner or message/Closing message
Question 1 (4 pts.)
Prompt and display the user’s input
Follow the rules to calculate the difference
Display the correct result
Question 2 (8 pts.)
Prompt user’s inputs
Follow the rules to generate a screen name
Follow the rules to generate a secret code
Display result
TOTAL
COMP248/Fall 2025- Assignment 1
2
1
2
pts.
pt.
pts.
1
1
1
pt.
pt.
pt.
1
2
1
pt.
pts.
pt.
1
2
3
2
20
pt.
pt
pts.
pts.
pts.
Page 4 of 4