CIS 120
Mathematical Operators
Project-1
Max possible pts 100
Write a program called “Project_01_MathOperators” that prompts for the user’s name, reads two
integers, then displays user’s name and the sum, product, difference, quotient and modulus of the
two numbers.
1. Create a header for your project as follows:
/******************************************************************
* Programmer: Your Name (1 pt)
*
* Class: CIS 120 (1 pt)
*
* Section: (1 pt)
*
* Instructor: (1 pt)
*
* Program Name: Mathematical Operators (1 pt)
*
* Description: This Java program will ask the user to enter his/hers first name,
*
* last name and two integers. The program will then display the sum, product,
*
* difference, quotient and modulus of the two numbers.
*
******************************************************************/
(5 pts)
2. Display a friendly message: Good Morning!! (2 pts)
3. Explain your program to the user: This Java program can add, subtract, multiply, divide
and calculate the remainder of any two integers you enter. Let’s get started…. (5 pts)
4. Prompt the user- Please enter your first name: and store the value entered by user in a
string variable firstName.(4 pts)
5. Prompt the user- Please enter your last name: and store the value entered by user in a
string variable lastName.(4 pts)
6. Prompt the user- Enter the first integer: and store the value entered by user in an integer
variable num1.(5 pts)
7. Prompt the user- Enter the second integer: and store the value entered by user in an
integer variable num2.(5 pts)
8. Display the numbers entered by the user as: firstName lastName has entered the numbers
num1and num2.(5 pts)
9. Calculate sum, product, difference, quotients and modulus of the two numbers. ( 30 pts)
10. Display sum, product, difference, quotient and modulus of the two numbers. ( 10 pts)
11. Terminate your program with a friendly message: Thanks for using my program. Have a
nice day!!(2 pts)
12. Run your program with different datasets to make sure it works, then submit it through
LiveLab as Project_01_MathOperators. Your output in LiveLab must be displayed as
shown in the sample run below. For LiveLab to grade your output as correct, you must
pay attention to all capitalizations and punctuation marks including semicolon, commas
and periods.
13. Your program must be written using good programming practices.
a. Use comments (10 pts)
b. Use proper indentation. (8 pts)
Here is sample run of the program:
Good Morning!!
This Java program can add, subtract, multiply, divide and calculate the remainder of any
two integers you enter.
Let’s get started….
Please enter your first name: John
Please enter your last name: Doe
Enter first integer number: 6
Enter second integer number: 3
John Doe has entered the numbers 6 and 3
Sum = 9
Product = 18
Difference = 3
Quotient = 2.00
Modulus = 0
Thanks for using my program. Have a nice day!!
CIS 120
Introduction to Programming
Project-2
Heads or Tails
Write a program called “Project_02_CoinFlip” that simulates a coin being flipped in four trials
of 10, 100, 1000, and 10000 times each. After each trial, print the number of flips, the number of
heads, the number of tails, the percentage of heads, and the percentage of tails in the trial.
1. Include the java.util.Random class as the first line of your program. This will be needed
to generate random values. (5 pts)
2. Declare two variables of the appropriate type to accumulate the total heads flipped and
total tails flipped during each trial. (5 pts)
3. Write a loop to run the four trials. Print the number of flips being simulated for each trial
within the loop. Test your program at this point. (20 pts)
4. Write a second loop inside the first loop to simulate the coin being flipped the required
number of times in the trial. Initialize the two variables that accumulate the total heads
flipped and total tails flipped at the appropriate place in the code. (20 pts)
5. Write the code to simulate the coin flip and update the appropriate accumulation variable
based on whether heads or tails were flipped. (20 pts)
6. Print out the results of the trial as the number of heads, the number of tails, the
percentage of heads, and the percentage of tails in the trial. Make sure the output of
percentage of heads and tails includes decimal places. (10 pts)
7. Run your finished program using Eclipse and confirm your output is similar to the sample
output below. Be prepared to explain why your numbers are different than the sample
output.
8. Submit your program through LiveLab as Project_02_CoinFlip. Make sure the program
compiles and executes in LiveLab. It will be marked as Incorrect because it uses random
numbers.
9. Your program must reflect the use of good programming practices.
a. Include your name, class, section and a short description of your program at the top of
the code. (5 pts)
b. Use proper indentation and comments. (10 pts)
c. Use descriptive variable names and follow conventions for capitalization of variable
names. (5 pts)
Here is a sample run of the program:
For 10 flips of the coin:
heads = 3 tails = 7
% heads = 30.0 % tails = 70.0
For 100 flips of the coin:
heads = 49 tails = 51
% heads = 49.0 % tails = 51.0
For 1000 flips of the coin:
heads = 509 tails = 491
% heads = 50.9 % tails = 49.1
For 10000 flips of the coin:
heads = 4952 tails = 5048
% heads = 49.52 % tails = 50.48
CIS 120
Introduction to Programming
Project-2b
Stay or Switch
Write a program called “Project_02b_StayOrSwitch” that simulates a game show where you try
to pick which one of three closed doors has a prize behind it. After you pick a door, the host of
the show will open one of the other doors revealing no prize. He then asks you if you want to
change your mind by choosing the other closed door or stay with your original door. Simulate
playing the game 30,000 times. Keep track of the times you would have won by switching doors
and the times you would have won by staying with your original door. Print out both numbers
and percentage wins after 30,000 games have been played.
1. Include the java.util.Random class as the first line of your program. This will be needed
to generate random values. (5 pts)
2. Declare two variables of the appropriate type to accumulate the times you win by
switching and the times you win by staying during the trial. Both variables should be
initialized to zero before each game begins. (5 pts)
3. Write a loop to play the game 30,000 times. (5 pts)
4. Within the loop, put the prize behind a random door and pick a random door as your first
choice. (20 pts)
5. Within the loop, pick a door for the host to open that is not the winning door or the door
you picked. (15 pts)
6. Within the loop, add one to the appropriate accumulation variable if you would have won
the game by staying with your original door or by switching doors. (20 pts)
7. After playing the game 30,000 times, print out the number of times and percentage that
staying with your original door would have won and the number of times and percentage
that switching doors would have won. (10 pts)
8. Run your finished program using Eclipse and confirm your output is similar to the sample
output below. The numbers given in the sample output are not the same as your program
will generate. Be prepared to explain why your numbers are different.
9. Submit your program through LiveLab as Project_02b_StayOrSwitch. Make sure the
program compiles and executes successfully in LiveLab.
10. Your program must reflect the use of good programming practices.
a. Include your name, class, section and a short description of your program at the top of
the code. (5 pts)
b. Use proper indentation and comments. (10 pts)
c. Use descriptive variable names and follow conventions for capitalization of variable
names. (5 pts)
Here is a sample run of the program:
Switching doors wins 15000 times (50%)
Staying wins 15000 times (50%)
CIS 120
Project 3 - Calculator with Methods
Max possible pts 100
Write a program “Project_03_Calculator” that performs basic arithmetic operations and submit it
through Live Lab.
1. Prompt the user to enter two integers between 1 and 12. Verify that the values are within the
given range. (5 pts)
2. Let the user choose an operation by entering the character in ( ), e.g. for addition enter ‘A’.
Verify that the entry is correct or display the message ”Invalid Choice” and terminate the
program with a friendly message. (5 pts)
(A)ddition
(S)ubtraction
(M)ultiplication
(D)ivision
(R)emainder
(E)xponentiation
3. To accept a character data from the user, first get a string value then convert it to a character by
using stringName.charAt(0) to read the first character of the string. (5 pts)
4. Convert the character to upper class by using method, Character.toUpperCase(char). (5 pts)
e.g.
char ch=’r’;
Character.toUpperCase(ch);
will return R
5. Print quotient in scientific notation with four decimal places.(5 pts)
6. Suggested methods are:
int getNum ( ) (5 pts)
boolean validateNum(int num) (10 pts)
char displayMenu( ) (5 pts)
int add (int addend1, int addend2) (5 pts)
int sub (int minuend, int subtrahend) (5 pts)
int mul (int multiplicand, int multiplier) (5 pts)
double div (int dividend, int divisor) (5 pts)
int mod (int num1, int num2) (5 pts)
int power (int base, int exponent) (10 pts)
printResults(int result, int num1, int num2, char op) (10 pts)
printResults(double result, int num1, int num2, char op) (10 pts)
7. To work correctly in Livelab, the following line should be written only once in the program
immediately following the class declaration and before any methods:
static Scanner input = new Scanner(System.in); // note the keyword “static”
Sample run 1:
This program will perform basic arithmetic operations on two integers between 1 and 12. Enter the first number: 1 Enter the second number: 3 Select an arithmetic operation from the following: (A)ddition (S)ubtraction (M)ultiplication (D)ivision (R)emainder (E)xponentiation D 1 / 3 = 3.3333e‐01 Sample run 2:
This program will perform basic arithmetic operations on two integers between 1 and 12. Enter the first integer: 3 Enter the second integer: 5 Select an arithmetic operation from the following: (A)ddition (S)ubtraction (M)ultiplication (D)ivision (R)emainder (E)xponentiation e 3 ^ 5 = 243 Thanks for using my program
Sample run 3:
This program will perform basic arithmetic operations on two integers between 1 and 12. Enter the first number: 3 Enter the second number: 15 Invalid Choice Thanks for using my program, please try again later Sample run 4:
This program will perform basic arithmetic operations on two integers between 1 and 12. Enter the first number: 8 Enter the second number: 4 Select an arithmetic operation from the following: (A)ddition (S)ubtraction (M)ultiplication (D)ivision (R)emainder (E)xponentiation G Invalid Choice Thanks for using my program, please try again later CIS 120
Introduction to Programming
Project-4
Manufacturing
Write a program called “Project_04_Manufacturing” that extends the features of the
Manufacturing code found in the Handouts section of Blackboard. The features you need to add
are:
Provide the two classes referenced in the main method: Factory and Warehouse
The Factory class must have a public method “buildOrder” and a private method
“incrementInventory” as explained below.
The Warehouse class must have a public method “shipOrder” and a private method
“decrementInventory” as explained below.
Both classes should have default constructors.
1. As required by the main method, the “buildOrder” method in the Factory class should be
public, return void, and accept a one-dimensional array of integers for build information
and the two-dimensional inventory array. This method should print a record of the build
information.
2. A private method, incrementInventory, must be provided in the Factory class that accepts
the material id, quantity made, and inventory array. It should increment the inventory of
the correct item in the inventory array.
3. As required by the main method, the “shipOrder” method in the Warehouse class should
be public, return void, and accept a one-dimensional array of integers for shipping
information and the two-dimensional inventory array. This method should print a record
of the shipping information.
4. A private method, decrementInventory, must be provided in the Warehouse class that
accepts the material id, quantity made, and inventory array. It should decrement the
inventory of the correct item in the inventory array.
5. Submit your program through LiveLab as Project_04_Manufacturing. Make sure the
program compiles and executes in LiveLab, then submit it.
6. Your program must reflect the use of good programming practices.
a. Include your name, class, section and a short description of your program at the top of
the code.
b. Use proper indentation and comments.
c. Use descriptive variable names and follow conventions for capitalization of variable
names, classes, and methods.
7. Grading will be based on 30% for program style, 60 % for program logic, and 10% for
formatting the output.
Here is a sample run of the program:
Opening Inventory Status:
[100, 50]
[101, 75]
Factory build record: 100 5
Factory build record: 101 10
Interim Inventory Status:
[100, 55]
[101, 85]
Warehouse shipping record: 100 5 200
Warehouse shipping record: 101 10 201
Closing Inventory Status:
[100, 50]
[101, 75]
Here are the codes being used:
100: Part #1
101: Part #2
200: Customer #1
201: Customer #2
CIS120–Project_BridgeDeal
Write a program called “Project_BridgeDeal” that extends “Project_DeckOfCards1” by adding the methods required for the main method shown below. The objective is to initialize the deck, shuffle the deck, deal thirteen cards to each of four players, and display the hand dealt to each player sorted by suit and rank. The names of the four players are North, East, South, and West. If you wish, you may show the hands using JOptionPane and the Unicode characters for the card suits. 1. These are the methods you need to add: public static int[] deal(int[] pack, int n, int offset) { // Deal “n” cards offset from the beginning of the deck. Return the hand dealt as an array of integers. public static void showHand(int[] hand, String player) { // Show a player’s hand sorted by suit and rank. The name of the player is passed as a string. You may want to use the “display” method from the prior project as a starting point for this method. 2. Comment the entire program. 3. Submit your program through LiveLab as Project_BridgeDeal. Make sure the program’s output in LiveLab is reasonable. LiveLab cannot evaluate the results because the deal is random. 4. Your program must reflect the use of good programming practices. a. Include your name, class, section and a short description of your program at the top of the code. b. Use proper indentation and comments. c. Use descriptive variable names and follow conventions for capitalization of variable names. 5. Grading will be based on 30% for program style, 60 % for program logic, and 10% for formatting the output. Page 1 of 3
6. The class declaration and main method shown below should be used as is: public class Project_BridgeDeal { public static void main(String[] args) { final int CARDS_PER_HAND = 13; int[] deck = new int[52]; unwrap(deck); shuffle(deck); int[] north = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 0); showHand(north, "North"); int[] east = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 1); showHand(east, "East"); int[] south = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 2); showHand(south, "South"); int[] west = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 3); showHand(west, "West"); } } Page 2 of 3
Here is a sample run of the program: North was dealt:
2 of Spades
6 of Spades
8 of Spades
2 of Hearts
3 of Hearts
8 of Hearts
10 of Hearts
6 of Diamonds
8 of Diamonds
Queen of Diamonds
King of Diamonds
4 of Clubs
5 of Clubs
East was dealt:
5 of Spades
King of Spades
6 of Hearts
9 of Hearts
Jack of Hearts
Queen of Hearts
Ace of Hearts
2 of Diamonds
4 of Diamonds
10 of Diamonds
Ace of Diamonds
9 of Clubs
Jack of Clubs
South was dealt:
3 of Spades
4 of Spades
9 of Spades
Jack of Spades
Ace of Spades
7 of Hearts
3 of Diamonds
5 of Diamonds
7 of Diamonds
Jack of Diamonds
3 of Clubs
7 of Clubs
King of Clubs
West was dealt:
7 of Spades
10 of Spades
Queen of Spades
4 of Hearts
5 of Hearts
King of Hearts
9 of Diamonds
2 of Clubs
6 of Clubs
8 of Clubs
10 of Clubs
Queen of Clubs
Ace of Clubs
Page 3 of 3
© Copyright 2026 Paperzz