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

Assignment ONE OOP

The document outlines a programming assignment due on May 07, 2023, consisting of various tasks that require writing Java applications. Tasks include operations on integers, string immutability, calculating mileage, employee gross pay, binary to decimal conversion, factorial computation, palindrome checking, data encryption, and generating specific patterns. The assignment emphasizes the use of classes like Scanner and requires the implementation of loops and conditional statements.

Uploaded by

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

Assignment ONE OOP

The document outlines a programming assignment due on May 07, 2023, consisting of various tasks that require writing Java applications. Tasks include operations on integers, string immutability, calculating mileage, employee gross pay, binary to decimal conversion, factorial computation, palindrome checking, data encryption, and generating specific patterns. The assignment emphasizes the use of classes like Scanner and requires the implementation of loops and conditional statements.

Uploaded by

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

OOP: [Assignment/Project] One Due Date: May 07, 2023

1. Write a java code to Assign the sum of x and y to z, and increment x by 1 after the calculation. Use
only one statement.
2. Why java string is immutable? Explain what does this mean and the detailed reasons why string
immutability is needed in java.
3. Teacher collects marks for student assessment, the total mark that will be allowed is maximum of
100. However, due a lot of assessment the total mark of a student can be well over a 100. Devise
a solution that will help the teacher to change the current mark to out of 100. The code should
run and accept the current total mark and provide the corresponding out of 100 total mark in
array.
4. Drivers are concerned with the mileage their automobiles get. One driver has kept track of several
trips by recording the miles driven and gallons used for each tankful. Develop a Java application
that will input the miles driven and gallons used (both as integers) for each trip. The program
should calculate and display the miles per gallon obtained for each trip and print the combined
miles per gallon obtained for all trips up to this point. All averaging calculations should produce
floating-point results. Use class Scanner and sentinel-controlled repetition to obtain the data from
the user.
5. Develop a Java application that determines the gross pay for each of three employees. The
company pays straight time for the first 40 hours worked by each employee and time and a half
for all hours worked in excess of 40. You’re given a list of the employees, their number of hours
worked last week and their hourly rates. Your program should input this information for each
employee, then determine and display the employee’s gross pay. Use class Scanner to input the
data
6. Write an application that inputs an integer containing only 0s and 1s (i.e., a binary integer) and
prints its decimal equivalent. [Hint: Use the remainder and division operators to pick off the binary
number’s digits one at a time, from right to left. In the decimal number system, the rightmost
digit has a positional value of 1 and the next digit to the left a positional value of 10, then 100,
then 1000, and so on. The decimal number 234 can be interpreted as 4 * 1 + 3 * 10 + 2 * 100. In
the binary number system, the rightmost digit has a positional value of 1, the next digit to the left
a positional value of 2, then 4, then 8, and so on. The decimal equivalent of binary 1101 is 1 * 1 +
0 * 2 + 1 * 4 + 1 * 8, or 1 + 0 + 4 + 8 or, 13.]
7. Write an application that reads a nonnegative integer and computes and prints its factorial.
8. A palindrome is a sequence of characters that reads the same backward as forward. For example,
each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write
an application that reads in a five-digit integer and determines whether it is a palindrome. If the
number is not five digits long, display an error message dialog indicating the problem to the user.
When the user dismisses the error dialog, allow the user to enter a new value.
9. A company wants to transmit data over the telephone, but is concerned that its phones may be
tapped. It has asked you to write a program that will encrypt its data so that the data may be
transmitted more securely. All of its data is transmitted as four-digit integers. Your application
should read a four-digit integer entered by the user in an input dialog and encrypt it as follows:
Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing
the new value by 10. Then swap the first digit with the third, and swap the second digit with the
fourth. Then print the encrypted integer. Write a separate application that inputs an encrypted
four-digit integer and decrypts it to form the original number
10. Write an application that displays the following patterns separately, one below the other. Use for
loops to generate the patterns. All asterisks (*) should be printed by a single statement of the
form System.out.print( '*' ); which causes the asterisks to print side by side. A statement of the
form System.out.println(); can be used to position to the next line. A statement of the form
System.out.print( ' ' ); can be used to display a space for the last two patterns. There should be no
other output statements in the program. [Hint: The last two patterns require that each line begin
with an appropriate number of blank spaces.]

11. Write an application that prints the following diamond shape. You may use output statements
that print a single asterisk (*), a single space or a single newline character. Maximize your use of
repetition (with nested for statements), and minimize the number of output statements.

You might also like