CS111 Programming Assignment 0

  1. Programs will be evaluated on functionality and code quality.
  2. Provide comments for all source code.
  3. Execute multiple test runs for programs 1-4.



Program 1


Write a Java program that generates a username. To do this, the program must prompt for and read the user’s first and last name (separately).
Assume all first and last names will consist of at least two characters.

The username will be generated as follows:


    Example:

      First Name: Bobo
      Last Name: Chavez
      Generated Username: BEZ*39






Program 2


Write a Java program that prompts the user for anytwo integers X and Y - positive or negative.
Calculate X * Y without using the multiplication operator. TIP: Use addition and a loop.
Use methods to perform input of X and Y, calculation of product, and the output.

  Perform the following tests executions:
  • User inputs a zero for X and any other integer for Y.
  • User inputs a zero for Y and any other integer for X.
  • User inputs positive integers greater than 2 for both X and Y.
  • User inputs negative integers less than -5 for both X and Y.
  • User inputs a positive integer greater than 10 for X and a negative integer less than -10 for Y.
  • User inputs a negative integer less than -10 for X and a positive integer greater than 10 for Y.






Program 3


Write an interactive program that prompts the user to input a string of words.

Translate the given sentence to Pig Latin and display it.

NOTE: Use methodsto make your code as efficient and as organized as possible.
Correctness is the most important element, however, points will be given for the quality of your code.
The Pig Latin system works as follows: Incorporate the following features :

    Example:

      Input:        These awful french fries are getting cold

      Output:        Hesetay awfulway renchfay riesfay areway ettinggay oldcay






Program 4


Write a Java program that prompts the user for a positive integer n .
Use a for loop to calculate the following sum (a real number):
     sum = 1 + 1/2 + 1/3 . . . . + 1/n

For accuracy, use the long double data type. Use methods to perform input, calculations, and output.

1.  Print the the source code for the program.
2.  Print a single output window that performs the following:
  • Execution 1: Let n be equal to any negative number.
  • Execution 2: Input n as zero.
  • Execution 3: Let n be equal to any positive number.

3.  use functions where needed : Input, Calculation, Display.
The Input function should employ a forever loop to ensure that a positive integer is entered.






Program 5


Write Java code that utilizes a nested loop to display a multiplication table from 1 to a positive integer n, between 5 and 10.
Allow the user to enter a valid integer n. See the image below.