COMSATS CSC103 Assignment 2 Guidelines
COMSATS CSC103 Assignment 2 Guidelines
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 .