Assignment+5
Assignment+5
Prompt the user to enter in a number of price values they wish to collect. Ensure that
the user enters a positive number when prompted.
Next, prompt the user for the desired # of price values. Ensure that each individual price
value provided is non-zero. Re-prompt the user as necessary.
When you are finished output the following:
Assignment 5 1
2. The savings — the total discounts received, which is the sum of all the negative
numbers times -1 ) — note this should be a positive number.
b. Average Discount — The average of all the negative prices times -1 . Note this
should be a positive number.
Input assumptions:
Number of prices: a value of data type 'integer' within the range -2147483648 to
2147483647
Individual price value: a value of data type 'integer' within the range -2147483648 to
2147483647
Assignment 5 2
Problem 1: Red Leader, Ready
This is a solo project. You may work as a group to help each other
out, but everyone should be writing a separate file on their own
computer. You will be doing yourself a HUGE disservice by not
working on this project by yourself! If you do share tips with one
another please be sure to include everyone's name at the top of
your program. Note that "sharing tips" does not mean "copied the
entire program" from someone else.
The Galactic Empire, led by Emperor Palpatine and his apprentice, Darth Vader, now
rule the galaxy. However, a small group of freedom fighters known as the Rebel
Alliance, is actively fighting to overthrow the Emperor.
The Rebel Alliance has acquired intelligence that the Empire is building a planet-
blasting super weapon, known as the Death Star. The Alliance’s first priority is to take
out this super weapon, as it poses a threat to their very existence.
To destroy this weapon, the Alliance need to train pilots, and track their progress.
Admiral Raddus has commissioned you to help write a program to track and rate pilots.
Pilots are grouped into “cohorts”, and trained and rated in the following activities:
2. Space Dogfighting — The ability to defeat hostile fighters in 1:1 space combat
Certain cohorts of pilots also need training on Hyperspace Navigation. However, not all
pilots need this training.
Your job is to write a program that lets the instructor of each cohort keep track of his or
her pilots. Your program should begin by asking the instructor for a few inputs that will
be used to control how the system works. The program should begin by gathering the
following information - all of this data must be validated:
Assignment 5 3
Number of pilots in the cohort: must be positive, no upper limit
Whether or not Hyperspace Navigation is a required activity for the pilots. Valid
inputs are “yes” or “no” in any combination of cases.
Number of training exercises for each of the training activities (Bombing Runs,
Space Dogfighting, Maneuverability, and perhaps Hyperspace Navigation). These
must be must be positive, no upper limit
Drop lowest score mode: Sometimes pilots get jittery. This option allows the
instructor to enable the system to drop the lowest score for each pilot in their cohort.
Valid inputs are "yes" or "no". Note: this mode should be “no” for any training activity
that has only one training exercises, and the user should be informed (see the
second example below for how this is to be done)
Next, prompt the instructor to enter in scores for each pilot. Ensure that the test score
values entered are within the range 0-100 (inclusive on both ends) This data must be
validated. Hint: you may need to use nested loops here! A while loop can be placed
inside of a for loop, if necessary.
If "drop lowest score mode" is turned on the system should figure out the lowest score
entered for each pilot, for each of the training activities, and report it to the user and
remove it from the grade calculation for the pilot.
You can assume that the user will enter integers when prompted (but they may not be
within the range you are expecting, hence the need for validation)
Once your program has collected all test scores for a pilot it should display that
student's average formatted to 2 decimal places. The program should also compute the
pilot’s letter grade for each training activity, using the following chart:
A: 90 or above
Assignment 5 4
The program should then move onto the next pilot. When all the grades for each pilot
have been calculated, the program should compute the overall average scores for each
training activity for the entire cohort.
Here's are a few sample runnings of your program (user input is highlighted):
Would you like to drop the lowest test for each pilot? (yes/no): no
Assignment 5 5
BOMBING RUNS: 60.00 (F)
SPACE DOGFIGHTING: 90.00 (A)
MANUEVERABILITY: 87.00 (B)
How many training exercises will you have for BOMBING RUNS? 3
How many training exercises will you have for SPACE DOGFIGHTING? 2
How many training exercises will you have for MANUEVERABILITY? 1
How many training exercises will you have for HYPERSPACE NAVIGATION? 1
Would you like to drop the lowest test for each pilot? (yes/no): yes
Note that the lowest score will NOT be dropped for the following activities because they o
nly have 1 training exercise each: MANUEVERABILITY, HYPERSPACE NAVIGATION
Assignment 5 6
HYPERSPACE NAVIGATION: 60.00 (F)
Number of pilots in class: a value of data type 'integer' within the range
-2147483648 to 2147483647
Number of training exercises for each activity type: a value of data type 'integer'
within the range -2147483648 to 2147483647
Assignment 5 7
Individual training exercise score: a value of data type 'integer' within the range
-2147483648 to 2147483647
Some hints:
You can assume that the user will enter integers for the # of pilots and # of training
exercises for each activity in the cohort, but you cannot assume the range of these
integers.
You can assume the user will enter floating point numbers when prompted for a test
score, but you cannot assume the range of these floating point values.
To collect pilot data you should probably begin by constructing a "for" loop to iterate
over all pilots in the class
Once you're inside of this "for" loop you will probably need nested loops to handle
inputting the scores for each activity for a particular pilot. Remember there are only
4 activities (and one of them is based on whether “Hyperspace Navigation” is
enabled).
Big hint: Try to get your program to work first without any data validation. You can
add this in later once you figure out the general structure of the program.
Remember the difference between "for" and "while" loops! "for" loops are used
when you want to iterate over a know # of items, and "while" loops can be used to
keep the user "caught" indefinitely until they fulfill a particular condition. You will
probably need to use a combination of these loops to solve this problem.
If you shared any code or helped out a group member with this project please be sure to
give credit to that person by including their names in the commented header of your
program.
Assignment 5 8
Problem 2: For the Republic — Court
Reform
After the destruction of the second Death Star and the defeat of the Galactic Empire, a
new government, called the “New Republic” was formed. This New Republic hoped to
engage in large scale reforms in an effort to improve fairness and equity throughout the
galaxy.
Leia Organa Solo, a senator in the new Galactic Senate, had her eyes set on reforming
the Supreme Court of the Republic. The Supreme Court consists of 2 associate justices,
and one chief justice, for a total of 3 justices. Each of these justices, including the chief
justice are appointed by the Supreme Chancellor (the executive of the New Republic),
and confirmed by the Galactic Senate, and each justice serves a lifetime appointment.
However, this model leads to significant inequities in which Supreme Chancellor gets to
appoint which justices. For example, if a significant number of justices pass away or
retire during the term of a particular Supreme Chancellor, that Supreme Chancellor has
a disproportionate sway in shaping the the makeup of the highest court in the galaxy.
Senator Organa Solo’s proposal to resolve this is to do the following:
1. Randomly choose the all 3 associate justices from the 10 appellate court justices
that exist (appellate courts very high courts in the galaxy, only lower than the
supreme court itself)
2. The senior-most of the individuals chosen is named the chief justice. If there’s a tie
in seniority, one of the selected individuals involved in the tie is picked at random as
the chief justice.
This process will be repeated for every case that comes before the Supreme Court of
the Republic. This means, for example, that if there are 5 cases that come before the
Supreme Court every year, 5 different combinations (of 3 justices each) will be chosen
at random. Note that a single individual can serve as a justice for multiple cases.
Senator Organa Solo has commissioned you to write a program to do demonstrate this
proposal. To do this, your program will have to collect the following information, and
validate each input, like in Problem 1.
Assignment 5 9
3. The year each of the appellate court justices started their tenure (integer)
Then you must print out the random combinations of courts for each case.
Assignment 5 10
Name: Aayla Secura
Start Year: 1110
*****************
** CASE PANELS **
*****************
** Case 1 Justices **
Chief Justice: Peggy Carter
Associate Justices: Aayla Secura, Dante Basco
** Case 2 Justices **
Chief Justice: Hermione Granger
Associate Justices: Christopher Pike, James Kirk
** Case 3 Justices **
Chief Justice: Alexander Hamilton
Associate Justices: Leslie Knope, Jessica Jones
** Case 4 Justices **
Chief Justice: Bilbo Baggins
Associate Justices: Peggy Carter, Dante Basco
** Case 5 Justices **
Chief Justice: James Kirk
Associate Justices: Leslie Knope, Jessica Jones
Number of cases: a value of data type 'integer' within the range -2147483648 to
2147483647
“Start Year”: a value of data type 'integer' within the range -2147483648 to
2147483647
Some hints:
You can always assume the user will enter an integer when prompted, but you will
need to validate it so that it falls within the desired range (1 or larger)
Note that 0 is technically a valid year. You should, however, validate for negative
years.
Assignment 5 11
Remember that it is possible for all 3 selected justices to have the same start year.
In the case the chief justice will be picked at random amongst all 3 chosen justices.
Remember that all the individuals serving on a single case must be unique. For
example, a single person cannot be both an associate justice and a chief justice —
each position must be occupied by someone unique (associate justice 1, associate
justice 2, and chief justice)
Assignment 5 12