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

Intro - To - Programming - Assignment #2 - Spring - 2024

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

Intro - To - Programming - Assignment #2 - Spring - 2024

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

AL AIN UNIVERSITY

College of Engineering (CoE)

Introduction to Programming (0102220)

Assignment #2
Student Name
Student ID
25 March 2024 @ 11:59 PM Due Date

Student Total Course Learning


Question #
Mark Mark Outcomes (CLO)
10 1 1

10

Out of (5)
Question 1: (CLO#3,4) (10 marks)
Write a Java program that performs the following tasks:
1. Read the student's full name with spaces. For example, if the full name is "Mohammad
Sharif", the program should read it with spaces separating the first name, (Middle name)
and family name.
2. Convert each character of the entered name to its ASCII code(spaces among names have to
be excluded).
3. Convert each ASCII code to its binary representation.
4. If the ASCII code length is less than 8 bits, add leading zeros to make the total length 8.
For example, for the character 'M', the ASCII code is 77, and its binary representation is
1001101. In this case, the binary length is 7 digits. Therefore, to ensure the length is 8 bits,
we add a zero at the beginning. The new ASCII representation for 'M' is 01001101.

Requirement: The use of built-in methods such as charAt(),length(), nextLine(),Math.pow() are


permitted. Should a student breach this condition, it will result in a score of zero.

Example :
The program should provide the output in the following format:
Please enter your full name with spaces: Mohammad Sharif

"M" the ascii code is((77))the Binary Code: 01001101


"o" the ascii code is((111))the Binary Code: 01101111
"h" the ascii code is((104))the Binary Code: 01101000
"a" the ascii code is((97))the Binary Code: 01100001
"m" the ascii code is((109))the Binary Code: 01101101
"m" the ascii code is((109))the Binary Code: 01101101
"a" the ascii code is((97))the Binary Code: 01100001
"d" the ascii code is((100))the Binary Code: 01100100
"S" the ascii code is((83))the Binary Code: 01010011
"h" the ascii code is((104))the Binary Code: 01101000
"a" the ascii code is((97))the Binary Code: 01100001
"r" the ascii code is((114))the Binary Code: 01110010
"i" the ascii code is((105))the Binary Code: 01101001
"f" the ascii code is((102))the Binary Code: 01100110

Best Wishes

You might also like