Home CPSC 240

Lab 1: IntelliJ and Java

 

Objective

To solve a simple programming problem with Java, and to make sure you have a working Java environment with IntelliJ.


 

Setting up IntelliJ

  1. Download and install IntelliJ Community edition onto your system.
  2. When you open the program, you should see a screen like this:

    Click "New Project".
  3. Now you should see a window like this:

    Under Project SDK, wither choose an existing Java SDK (if one shows up), or choose Download JDK. The default selections (currently OpenJDK 17) should be fine, so click download.
  4. When it finishes downloading, click "Next". Then click next again, using no template.
  5. Give the project whatever name you like, maybe "lab1".
  6. Now, we need to add a .java file. To do this, right click on "src" in the project tree to the right, and choose "New -> Java Class". Name it something, maybe "Lab1".
  7. To get things running, just put in a basic "Hello World" program, like this:

  8. To run it, choose "Run -> Run..." from the menu. Then click "Lab 1" in the popup window.
  9. You should now see the output in the terminal at the bottom of the screen:


 

Task

Your task for this lab is to write a program to generate the lyrics to the song "99 Bottles of Beer". However, your program should read in the starting number of bottles the user wants in the song, it won't always be 99.

Also, you should read in the user's favorite beverage to use in the lyrics, instead of just using "beer" — some users may not be 21 (or indeed like beer).


 

Details


 

Example Run

Here is an example run of the program, so you can see how the program should work, and to see the lyrics to the song in case you're not familiar with them:

How many bottles to start with? 5
What is your favorite beverage? iced tea

5 bottles of iced tea on the wall, 5 bottles of iced tea.
Take one down and pass it around, 4 bottles of iced tea on the wall.

4 bottles of iced tea on the wall, 4 bottles of iced tea.
Take one down and pass it around, 3 bottles of iced tea on the wall.

3 bottles of iced tea on the wall, 3 bottles of iced tea.
Take one down and pass it around, 2 bottles of iced tea on the wall.

2 bottles of iced tea on the wall, 2 bottles of iced tea.
Take one down and pass it around, 1 bottle of iced tea on the wall.

1 bottle of iced tea on the wall, 1 bottle of iced tea.
Take one down and pass it around, 0 bottles of iced tea on the wall.

0 bottles of iced tea on the wall, 0 bottles of iced tea.
Go to the store and buy some more, 5 bottles of iced tea on the wall.

 

Submitting

When you are finished, please submit the .java file (and not the .class or other files) for the lab on Canvas.

Copyright © 2022 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.