Java Intro 1
Scona Rap Battle!
Mr. Couprie grew up on the mean streets of St. Albert. It was a hard gangsta life but as you are no doubt aware, he emerged from this life and eventually grew into the music icon he is today. This assignment is dedicated to that time, not so long ago.
Set up
- Create a new class as As1_Rap.java in your existing Java project.
- Add a run method to this new class and call it from the main method.
Variables Required
- Two String variables for Contestant1 and Contestant2’s names
- Two int variables for their ages
- Four String variables for Contestant1 and Contestant2’s raps
- line1Contestant1
- line2Contestant1
- line1Contestant2
- line2Contestant2
- Three double variables for the judges scores
- Two double variables for the two contestants’ average scores
The program begins off air.
- Ask Contestant 1 for their name. Then scan it into their name variable.
- Ask Contestant 1 for their age. Then scan it into their age variable.
- Repeat for Contestant 2.
- Then ask for each of their raps. Ask for line 1 and then scan it into the Line1Contestant1 variable. Then ask for line 2. Then repeat for contestant 2.
- You will print back these variables in the blank spaces below in the next section.
Then it is showtime! It is time to get into your show hosting character.
- Begin by introducing the program with a lines such as the following:
Yo, yo, yo homies. Welcome to Scona Rap Battle!
Lets’ say SUP to our first contestant _____ who is age ____.
And earlier we recorded the rap battles. Let’s hear ____ 's beats:
___________ (lines one and 2 are printed)
Yo dawg that was the shizzle.
Now we are hanging with contestant two who is ___. His handle is ___
And here comes his rap:
_____ (lines one and 2 are printed)
Daaang. This is going to be close.
- The user will then enter the 3 judges scores out of 100 for the first contestant.
- Ask the user to enter the score for the first judge and scan it in.
- Then repeat for the other two judges
- OR, practice using random for the 3rd judge's score:
judge3 = (int) (Math.random( ) * 100 + 1);
- Calculate the average score for the contestant 1 and then store that average into the first average variable.
- Repeat for the second contestant, again asking and scanning in the 3 judges scores and again calculating the average score.
Now it is time to announce your winner (after an age bonus)
- Announce the average scores of each contestant. If you get a really long decimal number, just ignore it. It is surprisingly difficult to round in Java.
- If one contestant is less than 18 AND the other is 18 or older, give the younger contestant a bonus 10 points and add a print out to explain. If both are under or both over, give no bonus. The bonus would be added to their average.
- Using an IF statement, state who wins
Extra Challenge - Not for marks:
Add some Bonus Rap Points to your scoring (before averages are calculated)
- If your contestants have two lines that rhyme, they should get bonus marks. For our purposes, we are going to assume that if the last 3 characters of the two lines are the same, it is a valid rhyme.
- Go to this list of Java String Methods. Then find and link into the endsWith() method.
- See if you can figure out how to use endsWith() to test if the lines end with the same 3 characters. If they do, tell the user that they get 10 bonus points for the quality of their jam and then add those points to their score.
- Use the ANSII color codes to change the text color at appropriate times in the console.
Pausing between rap lines
- I have had a few students ask how to make the program pause for a few seconds before moving on. Want to know how to make your program pause? Try this:
try {
Thread.sleep(1000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
The 1000 is milliseconds so 2000 is a 2 second pause.