0% found this document useful (0 votes)
27 views2 pages

COMSATS CSC103 Assignment 2 Guidelines

This document contains instructions for Assignment 2 for the Programming Fundamentals class. It provides 5 programming questions to answer in Java, with each question worth 5 marks for a total of 25 marks. The assignment is due on November 14, 2021. Students must submit their assignment in a Word document with their registration number as the file name. It must include the source code and output for each question. Plagiarism is not allowed and will result in zero marks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

COMSATS CSC103 Assignment 2 Guidelines

This document contains instructions for Assignment 2 for the Programming Fundamentals class. It provides 5 programming questions to answer in Java, with each question worth 5 marks for a total of 25 marks. The assignment is due on November 14, 2021. Students must submit their assignment in a Word document with their registration number as the file name. It must include the source code and output for each question. Plagiarism is not allowed and will result in zero marks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COMSATS University Islamabad

Department of Computer Science


Programming Fundamentals (CSC103) – BSCS-2A & 2B
Class Assignment – 2 (CLO-3)

Due Date: November 14, 2021 (11:59 pm)

Total Marks: 5 x 5 = 25

Instructions
Answer to all questions must be submitted in MS Word.

Answer to all questions should begin on new page.

Assignment document must contain a title page showing Assignment-2, your name and
registration number.

Assignment document must also contain JAVA source code along with output.

Solution to JAVA Programming problems must be created in separate .java file (for each
question). For example, [Link]

You must follow proper JAVA naming convention for identifiers and properly document your
source code

Combine all your work in one folder. The folder must contain .JAVA source files and a
.doc/.docx file.

Name of the Assignment document file should be your Registration Number. E.g.
[Link]

Submit your work via MS Teams

Plagiarism: Plagiarism is not allowed. If found plagiarized, zero marks will be awarded in the
assignment.
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103) – BSCS-2A & 2B
Class Assignment – 2 (CLO-3)
Question – 1: ______
Write a program that prompts the user to enter a Social Security number in the format DDD-DD-
DDDD, where D is a digit. Your program should check whether the input is valid. Here are
sample runs:
Enter a SSN: 232-23-5435
232-23-5435 is a valid social security number
Enter a SSN: 23-23-5435
23-23-5435 is an invalid social security number

Question – 2: ______
Write a program that prompts the user to enter two strings and reports whether the second string
is a substring of the first string
Enter string s1: ABCD
Enter string s2: BC
BC is a substring of ABCD

Question – 3: ______
Assume a vehicle plate number consists of three uppercase letters followed by four digits. Write a
program to generate a plate number.

Question – 4: ______
Write a program that displays all the leap years, ten per line, from 101 to 2100, separated by
exactly one space. Also display the number of leap years in this period.

Question – 5: ______

Write a program that prompts the user to enter a decimal integer and displays its corresponding
binary value. Don’t use Java’s [Link](int) in this program.

Common questions

Powered by AI

To generate a vehicle plate number, the algorithm involves creating a string consisting of three random uppercase letters and four random digits. This can be achieved by using Java's Random class. For the letters, select a character by generating a random number bounded by the alphabet length and adding it to 'A' to ensure uppercase. For the digits, generate random integers ranging from 0 to 9 and concatenate them to form four-digit sequences. The generated characters are then combined into a string to form the plate number, ensuring compliance with the specified format and randomness suited for unique identifier generation .

To manually convert a decimal integer to binary in Java, implement the logic through repeated division by 2. Keep track of the quotient and collect the remainders: the remainder of each division step represents the next bit of the binary number (from least to most significant bit). Continue dividing the quotient until it becomes zero, then print the collected remainders in reverse order to display the binary value. This approach gives a practical understanding of numerical bases and illustrates manipulation of basic arithmetic operations and loops without reliance on built-in utilities .

The task requires understanding the leap year conditions: a year is a leap year if it is divisible by 4, but not by 100 unless it is also divisible by 400. Implementing a loop from 101 to 2100, the program should apply these rules to append every leap year to the output, ensuring exactly ten are displayed per line. This task highlights important programming skills such as control flow, modular arithmetic, loop usage, and output formatting. It embodies aspects of computational thinking and precision, valuable in scenarios where temporal data accuracy is critical, such as developing calendar applications .

To develop a Java program that validates a Social Security number (SSN) format, you need to implement an input prompt that expects the user to enter the number in the format DDD-DD-DDDD, where each D is a digit. The program should then verify if the input matches this pattern exactly. This can be achieved using regular expressions. The regex pattern for this is "\\d{3}-\\d{2}-\\d{4}". Using Java's Pattern and Matcher classes allows for a systematic approach to check input validity. Validating SSNs is crucial since incorrect or malformed identifiers can lead to errors in identity verification systems, impacting user data integrity and legal compliance .

The approach involves utilizing Java's String class methods, particularly the 'contains()' method, which checks if a sequence of characters (a substring) is present in another string. By taking two input strings from the user and applying s1.contains(s2), you can ascertain whether the second string is a substring of the first. This functionality is commonly used in text processing, search optimization, and data filtering tasks where detecting specific patterns or content within larger datasets is essential .

You might also like