CISC 1115
Introduction to Programming Using Java
Lab #1
Introductory Lab
Overview
The purpose of this introductory lab is to:
- Get you acquainted with IntelliJ
- Give you some practice writing code
- Get you to write some new code
- Get you to enhance your program's output
Getting You Acquainted with The Lab Machines
If you will be working on your own laptop, that's fine, and you can skip this section.
Room 130NE was designed specifically with the 1115 student in mind. The machines are Intel based boxes
running Windows. Each of you should stake out a machine and try to use the same machine during each lab.
(This is a suggestion, not a requirement-- while you cannot absolutely rely on these machines to retain
their contents-- the folks maintaining the lab are perfectly within their rights to wipe them clean and reload
them-- that should not happen too often, and this way, you will feel more 'at home' if you use the same machine
each time). Of course, if oyu have a laptop, you are free to use that.
Introducing You to the Software You Will be Using
As we may have mentioned in class, there are several basic software tools used in the development and testing of
software: an editor, a compiler, and some mechanism for executing ('launching' or 'running' the resulting program.
These three components are often combined (integrated) into a sINgle piece of software known as an integrated development
environment (IDE). An IDE, addition to the basic three tools listed above, often provides other facilities, for example
a debugger-- a tool that aids in the tracking down and correction of program errors.
We will be using an IDE to develop our programs, for most, if not all, of the semester. The CIS official 1115 Web page
(accessible from my 1115 page) contains links and detailed installations/usage instructions for several popular (i.e., free)
IDE's used in the development of Java program. I will be using IntelliJ in the class and suggest you do so aas well — at least
initially. Of course, feel free to try and/or use any of the others (or all of them — one of the desirable
characteristics of a good computer scientist is the willingness and ability to try new techniques/methodologies/software).
The lab machines have all the IDE's (including Intellij) installed, and there are instructions linked from the course home
page for installing IntelliJ on your own personal machine.
Overview
The exercises in Lab 1 are meant to get you acquainted with IntelliJ as well as with CodeLab. Please first develop your lab in IntelliJ, and only submit to CodeLab once you have a program
that runs. In IntelliJ, type in the entire program — boilerplate and all — use the 'New File' option when creating the source file; there will be plenty of opportunity to use
the 'New Java Class' option later once you've gotten familiar with the basic Java boilerplate.
With the exception of the last two labs (Lab01.10 and Lab101.11), each of the following labs closely follow the corresponding program in Lecture 1.
Lab 1.1 — The Empty Application (EmptyApp
)
Edit and execute the
EmptyApp
program presented in class
Sample Test Run
Notes
- Note the absence of any output … this is the minimal Java program (application)
All these exercises in Lab 1 are meant to get you acquainted with IntelliJ. Please type in the entire program — boilerplate and all — use the 'New File'
option when creating the source file; there will be plenty of opportunity to use the 'New Java Class' option later once you've gotten familiar with the basic Java
boilerplate.
Lab 1.2 — The Hello World Application (HelloWorld
)
Edit and execute the HelloWorld program presented in class
Sample Test Run
Hello world
Again, this is meant to get you acquainted with IntelliJ.
Lab 1.3 — The Two-Exam Grader Application (ExamGrader
)
Edit and execute the ExamGrader program presented in class
Sample Test Run
90
More of the same.
Lab 1.4 — A Three-Exam Grader Application (ExamGrader
)
Modify Lab 1.3 (Two-exam Grader) so that it prints out the average of three exam grades 72, 84, and 96.
Sample Test Run
84
This is the first exercise that asks you to write new code (as opposed to simply copying code we wrote in class). There are
also a couple of items of note:
- Notice that the class name is the same as that of Lab 1.3. This is neither usual nor unusual; we will see more examples of this
over the course of the semester.
Lab 1.5 — The Three-Exam Grader Application with Variables (ExamGrader
) Approval
Modify Lab 1.4 to use variables (name, exams, and average) and print out a more descriptive output.
Sample Test Run
Gerald Weiss scored 72, 84, and 96 for an average of 84
- Variables, types, and declarations and initializations
- Note that this is an Approval exercise. Make sure you read the Labs Home page section on Approval exercises.
- The reason it is an Approval is that there is no easy way to have CodeLab check that you used variables; therefor I will
be examining your code.
- I will also be looking at your indentation
- You can use any variable names here, CodeLab will only be checking the final average printed
- However, it IS an Approval, which means I will be looking at it, and will reject non-meaningful variable names
Lab 1.6 — The Three-Exam Grader Application with Pass/Fail Logic (ExamGrader
) Approval
Add pass/fail logic to Lab 1.5 (60 and above is passing).
Sample Test Run
Gerald Weiss scored 72, 84, and 96 for an average of 84
Gerald Weiss passes
- Variables, types, and declarations and initializations
- Note that this is also an Approval exercise; I want to check your indentation for the
if
statement
Lab 1.7 — The Three-Exam Grader Application with Keyboard Input (ExamGrader
)
Modify Lab 1.6 so that it accepts its data from the keyboard
Sample Test Run
Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:
last name? Weiss
first name? Gerald
exam1? 72
exam2? 84
final? 96
Gerald Weiss scored 72, 84, and 96 for an average of 84
Weiss, Gerald passes
- Use of
Scanner
, next
, and nextInt
- Up until now, all the data has been hardocded; i.e., the program produces the same output
each and every run. Now that there is input coming from the keyboard, the output will depend on the input data.
- The sample input data is the same as what we've been using until now. However, when you submit t CodeLab, other data
will be supplied to the program as well — in particular exam grades producing average above, below, and equal to 60.
Lab 1.8 — The Three-Exam Grader Application for Four Students (ExamGrader
)
Modify Lab 1.7 so that it processes four students using a
for
loop and reading data from the keyboard
Sample Test Run
Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:
last name? Weiss
first name? Gerald
exam1? 72
exam2? 84
final? 96
Gerald Weiss scored 72, 84, and 96 for an average of 84
Weiss, Gerald passes
last name? Doe
first name? John
exam1? 40
exam2? 50
final? 56
John Doe scored 40, 50, and 56 for an average of 48
Doe, John fails
last name? Doe
first name? Jane
exam1? 57
exam2? 61
final? 59
Jane Doe scored 57, 61, and 59 for an average of 59
Doe, Jane fails
last name? Sokol
first name? Dina
exam1? 60
exam2? 60
final? 60
Dina Sokol scored 60, 60, and 60 for an average of 60
Sokol, Dina passes
- Simply following the lecture — using a
for
loop
Lab 1.9 — The Three-Exam Grader Application Where the User Specifies the Number of Students (ExamGrader
) Approval
Modify Lab 1.8 so the user is prompted for the number of students to grade.
Sample Test Run
User input is in bold. Your program should replicate the prompts and output:
How many students?
2
last name? Weiss
first name? Gerald
exam1? 72
exam2? 84
final? 96
Gerald Weiss scored 72, 84, and 96 for an average of 84
Weiss, Gerald passes
last name? Doe
first name? John
exam1? 40
exam2? 50
final? 56
John Doe scored 40, 50, and 56 for an average of 48
Doe, John fails
- A for loop with a count read in from the keyboard
Lab 1.10 — A Payroll Processing Application (PayrollProcessor
)
Read in from the keyboard:
- last name
- first name
- hours worked
- rate per hour
and print out the information together with the amount earned. Also print out whether the person worked overtime (more than 40 hours).
Sample Test Run #1
User input is in bold. Your program should replicate the prompts and output:
last name? Weiss
first name? Gerald
hours? 20
hourly rate? 25
Gerald Weiss worked 20 hours for $25/hour and earned $500.
Weiss, Gerald did not work overtime
Sample Test Run #2
User input is in bold. Your program should replicate the prompts and output:
last name? Doe
first name? John
hours? 50
hourly rate? 30
John Doe worked 50 hours for $30/hour and earned $1500.
Doe, John worked overtime
This lab is similar to Lab 1.7 in that it accepts input from the keyboard. However, this lab is for a payroll application
rather than an exam grading system.
- As you progress in your programming skills, you will acquire various programming patterns that are the same regardless of the particular application
Lab 1.11 — A Payroll Processing Application Where the User Specifies the Number of Employees (PayrollProcessor
) Approval
Modify Lab 1.10 so that it processes multiple employees using a
for
loop. The number of employees is provided by the user from the keyboard.
Sample Test Run
User input is in bold. Your program should replicate the prompts and output:
How many employees? 2
last name? Weiss
first name? Gerald
hours? 20
hourly rate? 25
Gerald Weiss worked 20 hours for $25/hour and earned $500.
Weiss, Gerald did not work overtime
last name? Doe
first name? John
hours? 50
hourly rate? 30
John Doe worked 50 hours for $30/hour and earned $1500.
Doe, John worked overtime
This lab is similar to Lab 1.9 in that it processes multiple entries from the keyboard with the number of entries supplied by the use with the number of entries supplied by the user.
However (as with Lab 1.10), this lab is for a payroll application rather than an exam grading system.