Java Bootcamp – Workbooks and Challenges
)}

Workbook 3.3

From the Java-Bootcamp-Resources, launch the Workbook 3.3 folder.

Screen Shot 2022-10-16 at 5.44.01 PM.png

The Quidditch Championship

This is a modified passage from the book: Harry Potter and the Half-Blood Prince.

Screen Shot 2022-10-16 at 8.27.45 PM.png

We're going to convert this passage into code. The code starts with the number of points scored by gryffindor and ravenclaw.

public class Championship { public static void main(String[] args) { int gryffindor = 400; //gryffindor points   int ravenclaw = 200; //ravenclaw points }

1. Calculate the difference in points.


Make an int variable called margin. It will calculate the margin of points gryffindor scored over ravenclaw.

public class Championship { public static void main(String[] args) { int gryffindor = 400; //gryffindor points int ravenclaw = 200; //ravenclaw points // margin: amount of points by which gryffindor scored over ravenclaw ; } }

2. if - else if - else.


If gryffindor wins by a margin of 300 points or more, print:

Gryffindor takes the house cup!

If gryffindor wins by a margin of any points or ties, print:

In second place, Gryffindor!

If gryffindor loses within 100 points, print:

In third place, Gryffindor!

else, print:

In fourth place, Gryffindor!

Run your Code

Test Case 1

int gryffindor = 400; int ravenclaw = 200;

>>In second place, Gryffindor!

Test Case 2:

int gryffindor = 850; int ravenclaw = 500;

>>Gryffindor takes the house cup!

Test Case 3:

int gryffindor = 620; int ravenclaw = 500;

>>In second place, Gryffindor!

Test Case 4:

int gryffindor = 450; int ravenclaw = 500;

>>In third place, Gryffindor!

Test Case 5:

int gryffindor = 100; int ravenclaw = 500;

>>In fourth place, Gryffindor!

Visualizing the Runtime

After you solve this workbook, I still recommend watching the video solution on Udemy.

Screen Shot 2022-10-16 at 5.57.44 PM.png

It will show you how to visualize the runtime using Visual Studio Code.

Solution Code

The solution code is inside the same folder as the starter project.

Screen Shot 2022-10-16 at 5.57.24 PM.png

Good Luck!


Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer

Feedback Summary
4.7
43 students
5

91%
4

2%
3

0%
2

0%
1

7%
Written Reviews
There are no written reviews yet.