605.201 Mini-Project 1: Solved

30.00 $ 15.00 $

Category:

Description

Purpose:

The purpose of this project is to provide non-trivial practice in the use of Java programming constructs discussed from the beginning of the course through Module 05 and have a bit of fun doing it.

Resources Needed:

You will need a computer system with Java 7 or greater SE edition run-time and JDK. You may optionally use a Java IDE for example NetBeans, Eclipse, etc.

 

Submitted Files:

 

Design and Analysis:

 

  1. What alternative approaches were considered and why were they rejected?
  2. What did you learn from doing this project and what would you do differently?

 

Source file:

 

The format of the Java source must meet the general Java coding style guidelines discussed so far during the course. Please use course office hours or contact the instructor directly if there are any coding style questions.

 

Collaboration:

 

It is encouraged to discuss technical or small design parts of this project with your fellow students. However the resulting design and implementation must be your own. When in doubt, ask during office hours or contact your instructor.

Program Specification:

 

This project involves writing a program to simulate a tortoise and hare race. The contenders will each race along a horizontal course that contains at least 50 positions. You may add more if you wish. The race begins with each contender at position 1. The contender that first reaches or passes the last position of the course is the winner of the race.

 

The following table indicates the types of moves that each contender can make.

 

 

Contender

 

Type of Move

 

Percentage of Time

 

Result of Move

 

Tortoise Fast plod 50% 3 squares to right
Slow plod 30% 1 square to right
Slip 20% 6 squares to left
Hare Big hop 20% 9 squares to right
Small hop 30% 1 square to right
Big slip 10% 12 squares to left
Small slip 20% 2 squares to left
Fall asleep 20%

 

 

Each contender starts at position 1. When a contender slips, they can’t slip any further left than  position

  1. You will use a random number generator to simulate the percentages of each type of move indicated in the table. To generate random numbers, you can research the built-in Java random number method that is part of the Math class.

 

Generate a random integer, n, in the range 1 ≤ n ≤ 10. For the tortoise, perform a fast plod if the number is 1-5, a slow plod if the number is 6-8, and a slip if the number is 9-10. For the hare, perform a big hop if the number is 1-2, a small hop if the number is 3-5, a big slip if the number is 6, a small slip if the number is 7-8, and fall asleep if the number is 9-10.

 

There are a number of ways to design this program. One way would be to have a looping construct be the overall controller of things. Each iteration would adjust the contender positions, and the loop would terminate when one of the contenders reaches the last square of the race course. You will decide on an approach as part of your design step.

 

 

You must keep track of each contender’s position and display it each time positions change.

Show the letter “T” in the position of the tortoise, and the letter “H” in the position of the Hare. It is possible for the contenders to land on the same square. When this happens, the tortoise bites the hare, and your program should display “OUCH!!” beginning at that square. All output positions other than the “T”, the “H”, and the “OUCH!!” should be blank.

 

If the tortoise wins, display “TORTOISE WINS!!”. If the hare wins, display “HARE WINS!!”. If the race is a tie, display “IT’S A TIE!!”. At the beginning of the race, display “AND THEY’RE OFF!!”.

Requirements are WHAT the program performs.  Design describes HOW the program meets the requirements.  If you are exactly performing what the assignment states with no changes the requirements can be a copy, summary, or list of the stated assignment requirements.  If you are adding more functionality please state what you are adding. Design can be captured in a UML Diagram, a tool created diagram (Powerpoint, Visio, etc), hand drawn on paper diagram, or a written paragraph describing how the program is designed to meet the requirements.  The design can be minimal such as one diagram or one short paragraph. You should always capture requirements and design before starting to implement in code.  Submit the requirements, design, source code and screen shots of each program’s output in a zip file named as follows:  Project1 followed by an underscore (_) followed by your first name initial, followed by your last name, followed by your course section number. For example, if your name is Jane Smith and you are in section 81 your zip file would be Project1_jsmith81.zip.