Starting from:

$30

ASSIGNMENT 1 primitive data types

COMPUTER SCIENCE 12B 
ADVANCED PROGRAMMING TECHNIQUES IN JAVA

PROGRAMMING ASSIGNMENT 1
Program Description:
This assignment will give you practice with primitive data types, variables, expressions, the use of
Scanner objects, Strings, loops, and if/else statements.
You should limit yourself to the Java features covered in class so far (lecture 3). For this assignment
you are allowed to write your code in the main method, however we will soon see that modularity
in your code is very important and we will use static methods.
Problem 1:
Write a program that reads a positive integer value, and compute the following sequence:
o If the value is even, halve it.
o If it's odd, multiply by 3 and add 1.
o Repeat this process until the value is 1, printing out each value.
o Finally print out how many of these operations you performed.
Note: If the input value is less than 1, print a message containing the word Error and exit the
program.
This is how the output should look like:
Initial value is: 9
Next value is: 28
Next value is: 14
Next value is: 7
Next value is: 22
Next value is: 11
Next value is: 34
Next value is: 17
Next value is: 52
Next value is: 26
Next value is: 13
Next value is: 40
Next value is: 20
Next value is: 10
Next value is: 5
Next value is: 16
Next value is: 8
Next value is: 4
Next value is: 2
Final value 1, number of operations performed 19
Problem 2:
Write a program that prompts the user for a number (not bigger than 4999) and displays it in Roman
numerals.
Problem 3:
Write a program that produces a Caesar cipher of a given message string. A Caesar cipher is formed
by rotating each letter of a message by a given amount. For example, if your rotate by 3, every A
becomes D; every B becomes E; and so on. Toward the end of the alphabet, you wrap around: X
becomes A; Y becomes B; and Z becomes C. Your program should prompt for a message and an
amount by which to rotate each letter and should output the encoded message.
Log of execution (user input underlined)
Your message? Attack zerg at dawn
Encoding key? 3
Your message: DWWDFN CHUJ DW GDZQ
Problem 4:
Write a program that accepts two string variables, first and last, which the user should
populate with his or her name. First, convert both strings to all lowercase. Your program should
then create a new string that contains the full name in pig latin with the first letter capitalized for
the first and last name. Use only the pig latin rule of moving the first letter to the end of the word
and adding “ay”. Output the pig latin name to the screen.
For example, if the user inputs “Iraklis” for the first name and “Tsekourakis” for the last name,
then the program should create a new string with the text “Raklisiay Sekourakistay” and print it.
Problem 5: Write a program that prompts the user for any positive integer, for example 190245,
and then displays the digits, one per line, like so:
1
9
0
2
4
5
You are not allowed to use String; you should only work with integers.
Grading:
You will be graded on
o External Correctness: The output of your program should match exactly what is expected.
Programs that do not compile will not receive points for external correctness.
o Internal Correctness: Your source code should follow the stylistic guidelines linked in
LATTE. Also, remember to include the comment header at the beginning of your program,
and proper documentation/comments throughout your source code files.
Submission:
Create a folder containing your Java source code (programs). Compress (zip) the folder and
upload it to Latte by the day it is due. For late policy check the syllabus. This is an individual
assignment, and any sign of collaboration will result in a zero. Please check the syllabus for the
academic integrity policy.
Header comment example:
# Name Student
# COSI 12b, Fall 2021
# Programming Assignment #1
#
# Description: ...

More products