Input and Output Mini-Lab
This series of labs require you to write program code to use the following topics.
Prepare Your IDE
The Java Playground is great for trying out segments of code, but if we write print
statements to show that the output doesn't move to the next line, it won't behave as we expect. That is because it will treat each print
statement distinctly. At this time, to test out some code, we will want to move over to an IDE. If you need help, please reference the Getting Set-up page.
In this section, we will be using preview features in JDK 24. To use features that are still in preview, you will need to enable preview features in your IDE.
- Create a
.java
file. The file name should start with an uppercase letter.
- Use the following
main
method template. Add your statements to the body of the main
method. A comment is in the body of the main
. A comment is ignored by the compiler. Comments are added to the program code to help programmers understand what the program code does. There are three types of comments:
- single-line comments start with
//
- multi-line comments start with
/*
and end with */
- document comments, which generate documentation, start with
/**
and end with */
void main() {
//add your statements here
}
Missions
Here are a series of missions to apply what you have learned about using the console for input and output. Before writing the code for these missions, answer the following guiding questions:
- What data is the program using?
- What data is being produced?
- What is the type of this data?
- What are good variables names for this data?
- What are the steps to write the program?
Mission 1 - Certificate Printing
You have been asked to print certificates for the top student in each grade. Write a program that will prompt the user to enter the students name and the grade they are in. Then print a congratulatory message to the screen in the following format:
Congratulations Student Name!
Grade Level Award
Replace "Student Name" with the name entered and "Grade Level" with the grade entered.
Mission 2 - Vehicle Transportation
A car carrier, which is a large truck that transports new vehicles, can hold 6 SUVs or 8 cars. Each car carrier will transport only SUVs or cars, but not both. A car carrier can only be used if it is full. If there are more SUVs or cars than will fit on the car carrier they will not be transported. Prompt the user for the number of SUVs that need to be transported as well as the number of cars that need to be transported. Determine how many full car carriers that will be needed to transport the vehicles. Print the number of car carriers needed as well as the number of SUVs and the number of cars that will not be transported at this time.
For example, if there are 35 SUVs and 40 cars to transport, we would need 5 car carriers for the SUVs and 4 for the cars. The program should output:
9 car carriers will be needed
5 SUVs will not be transported
0 cars will not be transported