$29.99
Computer Science 12b Programming in Java
Assignment 0
Program Description:
This assignment tests your understanding of data types, for loops, variables,
and if statements.
Write eight programs to solve the following problems. Write each program in a different
file with extension .java
Problem 1:
Write a program that given your birth year, such as 1998, displays it one digit per line. Use
arithmetic operations (+,-,*,/,%) to isolate each digit. A possible output might be:
1
9
9
8
Problem 2:
A cookie recipe calls for the following ingredients:
• 1.5 cups of sugar
• 1.0 cup of butter
• 2.75 cups of flour
The recipe produces 48 cookies with these amounts of the ingredients. Write a program that
displays the number of cups of each ingredient needed for 144 cookies and for 72 cookies. Your
solution should calculate the appropriate amount of ingredients for any of the cases. Your output
should be:
Ingredients Recipe 1
1.5
1.0
2.75
Ingredients Recipe 2
4.5
3.0
8.25
Ingredients Recipe 3
2.25
COMPUTER SCIENCE 12B (SPRING 2020)
PROGRAMMING IN JAVA
PROGRAMMING ASSIGNMENT 0
1.5
4.125
Problem 3:
Write a program that calculates 215 and prints 2 to that exponent starting from 20 up to 215
You may NOT use the Math class to solve this problem.
Problem 4:
The factorial function is used frequently in probability problems. The factorial of a positive
integer n (written n! and pronounced “n factorial”) is equal to the product of the positive integers
from 1 to n. Write a program that calculates and displays the factorial of a variable x.
Initialize the variable x to 10. Your program should display 3628800.
Problem 5:
The Fibonacci numbers are a sequence of integers in which the first two numbers are 0 and 1, and
each following number is the sum of the previous two. For example, the first ten Fibonacci
numbers are: 0 1 1 2 3 5 8 13 21 34
The mathematical definition of each k-th Fibonacci number is the following:
Write a program that calculates and displays the first x Fibonacci numbers for some variable x.
Initialize the variable x to 10. Your program should display 0 1 1 2 3 5 8 13 21 34.
Problem 6:
Write a program that calculates the quadrant of the point pair made by two variables x and y.
Recall that quadrants are numbered as integers from 1 to 4 with upper-right quadrant numbered 1
and the subsequent quadrants numbered in a counterclockwise fashion:
For example:
if the point pair (x, y) is set to (1,2) your program should display 1
if the point pair (x, y) is set to (0,4) your program should display 0
Problem 7:
In modern unsolved problem in the mathematic world is the ability to predict successive large
prime numbers without requiring the on-loading of a massive computational burden. Recall that
a prime number is only divisible by 1 and itself. For example, 17 is only divisible by 17 and 1, so
it is prime, while 18 can be divided by 2 so it is not prime.
Write a program that displays whether or not a variable x is prime.
For example, if x is set to 17 the program should display true, but if x is set to 15, the program
should display false.
Problem 8:
Write a program that produces the following output:
***** ////////// *****
**** ////////\\ ****
*** //////\\\\ ***
** ////\\\\\\ **
* //\\\\\\\\ *
\\\\\\\\\\
Guidelines:
Add a comment header for each program:
// FirstName LastName
// PA#0
// date
For this assignment, you should limit yourself to the Java features covered in class so far.
Although we will cover other topics while you are working on this assignment, do not use any of
those features.
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 shown in
class. Also, remember to include the comment header at the beginning of your program.
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.