Programming Assignment 2

download Programming Assignment 2

of 4

description

Java assignemt, CPE 102, Cal poly, csc 102

Transcript of Programming Assignment 2

  • CS1A Assignment #2 Summer 2015 June15, 2015

    1

    Programming Assignment 2:

    Selection Control Structures - Mathematical Functions and Strings

    Total Points (60 pts) - Due Sunday, June 21 at 11:59 PM

    This programming assignment is intended to demonstrate your knowledge of the following:

    Constructing Boolean expressions to evaluate a given condition

    Constructing if and if-else-if statements to perform a specific task

    Importing the appropriate packages - usually when you use classes from a library you

    need to put the import declaration at the top of your program.

    Using format numbers

    Part 1: Bank Charges [30 points]

    A bank charges $10 per month plus the following check fees for a commercial checking account:

    $.10 for each check if less than 20 checks were written

    $.08 for each check if 20 through 39 checks were written

    $.06 for each check if 40 through 59 checks were written

    $.04 for each check if 60 or more checks were written

    The bank also charges an extra $15 if the account balance falls below $400 (before any heck

    fees are applied).

    Write a program that asks for the beginning balance and the number of checks written. Compute

    and display the banks service fees for the month.

    Name the source code file Bank Charges.java

    Here are sample runs of the program:

    Sample Run 1:

    Enter the following information about your checking account.

    Beginning balance: $1000

    Number of checks written: 50

    The bank fee this month is $13.00

    Sample Run 2:

    Enter the following information about your checking account.

    Beginning balance: $405.25

    Number of checks written: 5

    The bank fee this month is $10.50

    Sample Run 3:

    Enter the following information about your checking account.

    Beginning balance: $100.05

    Number of checks written: 100

    The bank fee this month is $29.00

  • CS1A Assignment #2 Summer 2015 June15, 2015

    2

    Part 2: Game (scissor, rock, paper) [30 points]

    Write a program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a

    rock can knock a scissor, and a paper can wrap a rock.) The program randomly generates a

    number 1, 2, or 3 representing scissor, rock, and paper. The program prompts the user to enter a

    number 1, 2, or 3 and displays a message indicating whether the user or the computer wins,

    loses, or draws.

    NOTE: present user with option to exit the game and do so if they choose this.

    Name the source code file RockGame.java

    Background

    Rock-paper-scissors is a hand game usually played by two people, where players simultaneously

    form one of three shapes with an outstretched hand. The "rock" beats scissors, the "scissors" beat

    paper and the "paper" beats rock; if both players throw the same shape, the game is tied.

    Rock, Paper, Scissors (see http://en.wikipedia.org/wiki/Rock_paper_scissors) is a popular game.

    Here are sample runs:

    Sample Run 1:

    Let's play Rock, Paper, Scissors!

    Game Menu

    ---------

    1) Rock

    2) Paper

    3) Scissors

    4) Quit

    Enter your choice: 1

    You selected: Rock

    The computer is paper. You are rock. You lost

    Sample Run 2:

    Let's play Rock, Paper, Scissors!

    Game Menu

    ---------

    1) Rock

    2) Paper

    3) Scissors

    4) Quit

    Enter your choice: 2

    You selected: Paper

    The computer is paper. You are paper too. It is a draw

  • CS1A Assignment #2 Summer 2015 June15, 2015

    3

    Sample Run 3:

    Let's play Rock, Paper, Scissors!

    Game Menu

    ---------

    1) Rock

    2) Paper

    3) Scissors

    4) Quit

    Enter your choice: 1

    You selected: Rock

    The computer is scissor. You are rock. You won

    Sample Run 4:

    Let's play Rock, Paper, Scissors!

    Game Menu

    ---------

    1) Rock

    2) Paper

    3) Scissors

    4) Quit

    Enter your choice: 2

    You selected: Paper

    The computer is scissor. You are paper. You lost

    Sample Run 5:

    Let's play Rock, Paper, Scissors!

    Game Menu

    ---------

    1) Rock

    2) Paper

    3) Scissors

    4) Quit

    Enter your choice: 1

    You selected: Rock

    The computer is Rock. You are Rock. It is a draw

    Sample Run 6:

    Let's play Rock, Paper, Scissors!

    Game Menu

    ---------

    1) Rock

    2) Paper

    3) Scissors

    4) Quit

    Enter your choice: 3

    You selected: Scissors

    The computer selected: Rock

    The computer is Rock. Scissors. You lost

  • CS1A Assignment #2 Summer 2015 June15, 2015

    4

    Submission:

    The submission must include .java files /run output.

    README.doc (you must edit this and insert your own screen shot or a sample run of

    each program)

    Turn in your README.doc and your Java source code files electronically from the

    Assignment link on the Etudes system. Submit the following files:

    1. BankCharges.java

    2. RockGame.java

    3. README.doc (you must edit this and insert your own screen shot or a sample run of

    each program)

    You MUST keep the filenames above I have given you.

    Standard program header

    Each programming assignment should have the following header, with italicized text

    appropriately replaced.

    Note: You can copy and paste the comment lines shown here to the top of your assignment each

    time. You will need to make the appropriate changes for each assignment (assignment number,

    assignment name, due date, and description). /**

    * Class: CS1A Object-Oriented Programming Methodologies in Java

    * Description: (Give a brief description for Assignment 2)

    * Due date:

    * Name: (your name)

    * File name: BankCharges.java

    */