project

advertisement
CS115
Project Assignment
TO BE DONE INDIVIDUALLY-you can work with
your lab partner but you have to present it
(and knowing the code) individually
Due Date: Up to December 01 or December 03, 2015 on Blackboard (can be submitted
earlier than that date if depending on your presentation date). Must be presented to the
instructor/TAs by everyone on either December 01 or December 03 Must also be uploaded
on blackboard by the time of presentation. No extensions and no corrections after the
presentation. A grade will be issued at the time of the presentation!!!
You can earn a partial credit even if the program is not totally working based on your
presentation and explanation of your source code.
Notice that his document is called a “SPECIFICATION”. Part of your grade will consist of how
well you adhered to this specification in your design.
You can sign up for a slot on the day the class is introduced to the project. The schedule will
also be posted for those absent on the course’s web site. If absent that day email your choice.
Grade: 8 points.
Instructions: zip all files and name it firstName_lastName_Project.zip then upload
on Blackboard.
Objective:

Design multiple classes that communicate with each other (called message passing).

Use arrays of primitive data types and arrays of objects.

Use looping and selection construct techniques in coding.

Use Math class methods.
1

Use Java API to decide how to use a library class and its methods.
Warnings: Read the following carefully:
1. This project is to be worked individually. Source code identical to another student’ s
source code will be disqualified from receiving a grade for all parties involved.
2. This project is different from previous Semester’s in various key points. If your code
matches a previous semester’s code in those key points then it will be assumed that
you copied. That will disqualify you from receiving a grade for the project.
In Class Discussions on Project: There would be a number of in class discussions on the project that
will provide clarifications, hints and other information. Feel free to come and see me in my office for
General Description of the project:
We are going to simulate a game:
This project is a game based on a lottery used by a car manufacturer to award cars to people as a
marketing promotion. The car manufacturer is going to give away 10 vehicles to people who have filled
out a form to participate in the promotion.
Based on the information provided by each person, a file is created with information about the
participants. Thirty five people participating in the promotion are recorded in a file called
participants.txt. Each person is assigned a lottery number which is recorded in the file participants.txt.
The car manufacturer has issued 50 tickets (15 more than the number of participants). That means
that some lottery tickets were not given away because not enough people participated (only 35 did).
The information about 10 vehicles to be awarded is recorded in a file called awards.txt. A
number is drawn and each time a car is awarded to the person whose lottery number matches the number
drawn. This lottery process is repeated until all 10 cars have been awarded. Notice that it could take more
than 10 drawings to give away the 10 cars because duplicate awards to the same participant are not
allowed. Also there is the possibility that a lottery number was chosen that was not given away to a
participant (one of the 15 tickets not distributed).
After the lottery, the 10 winners of the 10 cars then race their cars in a speedway. The car that
arrives first to the finishing line wins for its driver the top prize of $1,000,000.00. Everyone gets to keep
the car they drove.
2
Vehicles Information
The vehicles to be awarded are of 4 different types . The first type is SemiTruck, the second is
UtilityVeh, the third is Luxury and the fourth is SportsCar. There are 10 Vehicles available of all types
(two per type) in the awards.txt file. The information in the file awards.txt gives the type and the drive
attributes for each vehicle to be awarded, as well as the price of the vehicle. The attribute drive can have
one of the following String literal values: “frontwheel” , “rearwheel”, “either”. Notice that the
quotation marks should not be typed in the file.
The attributes values of each vehicle are separated by colon (: ) from each other in the text file
that provides the data. There is one line of data typed for each vehicle in the text file (total of 10 lines).
Prepare the text file awards.txt with the 10 lines of vehicles’ information with the following
values (using Notepad or an equivalent tool in MAC that generates pure text files. Remember that a tool
like WORD does NOT generate text files):
awards.txt file data:
23000:SemiTruck:frontwheel
21000:UtilityVeh:frontwheel
19650:Luxury:either
35000:SportsCar:rearwheel
15000:SportsCar:either
28000:UtilityVeh:frontwheel
36900:Luxury:either
27400:SemiTruck:either
59600:Luxury:rearwheel
15000:SportsCar:either
People Information in file participants.txt
There is a file that has the information on the 35 people participating in the award process. The
file contains information on first name,last name, social security number, and an attribute that
represents the lottery number issued for each person, separated by comma.
3
The lottery number held by each person is sequential starting from 35 for the first person and
ending with 1 for the last person (in between the lottery numbers are not in sequence). The information is
written in the file as one line per person. There are 35 people available in the file. Notice that the data in
each line is separated by the exclamation mark !
Prepare the text file paricipants.txt by entering the information shown below (again using an
application like Notepad):
John!Doe!1234!27
James!Doe1!2345!34
Mary!Doe2!5678!33
Helen!Doe3!7891!32
Maria!Doe4!2988!29
George!Doe5!6723!30
Frank!Doe6!2987!31
Anita!Doe7!1934!24
Dave!Doe8!267!35
Shara!Doe9!2988!26
Sylvester!Doe10!7895!25
Salvador!Doe11!4537!28
John!Doe12!1235!19
James!Doe13!2346!22
Mary!Doe14!5677!21
Helen!Doe15!7898!20
Maria!Doe16!2789!23
George!Doe17!6723!18
Frank!Doe18!2988!12
Anita!Doe19!1935!16
Dave!Doe20!2988!10
Shara!Doe21!3129!14
Sylvester!Doe22!7896!13
4
Salvador!Doe23!2988!17
John!Doe24!2234!11
James!Doe25!3345!15
Mary!Doe26!6678!5
Helen!Doe27!2988!8
Maria!Doe28!4781!2
George!Doe29!9723!6
Christina!Doe30!5678!9
Paola!Doe31!5678!3
Enrique!Doe32!6678!4
Emanuel!Doe33!6711!7
Frederica!Doe34!0987!1
Sequence of Program events during runtime of the progrm
Your program reads the participants.txt and awards.txt files and extracts the data. The game is as
follows:
The car manufacturer gives away a vehicle based on a drawn number (like a lottery) that
identifies the lottery number held by a customer. The number is drawn using uniform probability. There
are 10 unique numbers to be drawn (one for each vehicle to be given away).
A winner is declared if the drawn number (called lottery ticket) matches the lottery number of
one of the customers listed in the particiapants.txt file. Since there are more lottery numbers issued (50)
than available cars for the awards (10), and the participants (35 of the 50 tickets have been given away)
some drawn lottery numbers are not winning numbers and the person is notified that he/she lost. In this
case the awards process has to be repeated.
When a winner is found the person is checked against the previous winners in order to eliminate
double entries in the promotion. Two participants are declared equal if they have the same social security
number. If a winner has the same social security number as a previous winner, he/she is disqualified and
another number is drawn (the lottery process is repeated).
Also, if the same number is drawn more than once and it is a winning number, the number drawn
the second time is thrown out and a new number is drawn in its place (in other words a person can’t win
more than once). Each car has a unique id that is being assigned when the car is awarded. The id s run
from 1 to 10.
After all 10 cars have been awarded, the race takes place. Each vehicle is assigned an acceleration
randomly, using uniform probability distribution. Accelerations vary from 1 to 20 feet per second
square. Two cars can not have the same acceleration, therefore in case of duplicate acceleration numbers,
5
a new number has to be found. It is assumed that the timing of each car starts from the time they achieve
the assigned acceleration. From there on, the cars speed with a constant acceleration.
The winning car is the one that covers a distance of 50,000 feet in the shortest time.
Uniform Acceleration Motion Theory
When an object moves with constant acceleration the following formulas apply.
Let s be the distance traveled.
Let t be the time it traveled.
Let a be the acceleration.
Let v be the velocity.
s(t)=(1/2)*a*t2+v0*t+s0
v(t)=a*t+v0
a(t)=a
(constant, therefore acceleration is not a function of time).
Time is measured in seconds.
v0 is the initial velocity at time t=0. In our case the initial velocity is zero.
S0 is the initial distance at time t-=0. In our case the initial distance is also zero. Therefore the
formulas are reduced to:
1. s(t)=(1/2)*a*t2
2. v(t)=a*t
Use the above two formulas.
In our case we know the value of s(t) in formula 1 as being 50,000 feet. We solve formula 1 for
the variable t in order to calculate the time to travel a certain distance with a specific
acceleration:
t=square_root(2*a*S) / a
or
t=square_root(2*s/a)
The second formula (identified as #2 above) calculates the final velocity of the vehicle at the
end of time t.
Generating numbers with a uniform probability
Numbers can be generated based on a uniform probability of occurrence (in other words the probability
of a number to occur is the same for all numbers in the range). The example formula below generates
numbers in the range 1 to 20 with equal probability for each number.
int num=(int)(1+Math.random()*(20));
where num is the integer that will be generated randomly. The numbers 1 and 20 define the range of
the random numbers to be generated.
6
random() is a method in the library class Math.
Program Input:
The file with the people information called participants.txt, which contains information on 35
people.
The file with the Vehicles information called awards.txt, it contains information on 10
Vehicles.
Program Output:
The program outputs the following information:

For each winner: The first and last name, the social security number their lottery ticket
number, the type of the car won, the drive type of the car won, the id of the car won, the
price of the car won.

The first and last name of the people that lost and did not win anything.

Output the name of the cheaters, if any. Cheaters are people who had double entries
based on their social security number. If no cheaters were found indicate so.

The name of the person that won the race. The acceleration value assigned to his/her
vehicle, the id of the vehicle, the time it took to travel the distance and the final velocity
of that vehicle.

The sequence at which the cars arrived at the finishing line. For each car list it id number
and its acceleration.
TASKS

Sign up for the project presentation for either 12/01 or 12/03 choosing a time slot out of
the available time slots.

Upload on Blackboard the files by the time o fyour presentation but not any later than
that.
1. SOURCE CODE
Provide the source code files.
Each source code file must begin with your name at the top.
i.e.
//Joe Dow
2. Provide the compiled files (.class files)
3. Provide the two input text files.
7
Sample output of the program will be provided on a different file to be posted. Notice that the results
vary evry time the program is run because of the random statistics
Copyright: George koutsogiannakis, Illinois Institute of Technology- Fall 2015
8
Download