Exercise Overview
How to Use These Exercises
These exercises are designed to reinforce your understanding of Java fundamentals. Start with the easy exercises and progress to more challenging ones as you build confidence.
Tips for Success:
- Read the requirements carefully before starting
- Test your programs with various inputs
- Follow Java naming conventions
- Include proper comments and documentation
- Handle edge cases appropriately
Easy Exercises - Start Here!
Create Your First Java File
EasyWrite a program that demonstrates basic Java syntax and structure.
Requirements:
- Create a class called
MyFirstJava
- Include a main method
- Add at least 3 different types of comments
- Display a welcome message
- Show your name and student ID
Verify Java Installation
EasyCreate a program to verify your Java installation and display system information.
Requirements:
- Create a class called
SystemInfo
- Display Java version, vendor, and home directory
- Display operating system information
- Display available memory information
Expected Output:
Java Version: 24.0.1
Java Vendor: Oracle Corporation
Java Home: C:\Program Files\Java\jdk-24
OS Name: Windows 10
OS Version: 10.0
Available Memory: 8192 MB
Hints:
- Use
System.getProperty()
method (returns a string value)
- Properties to check:
java.version
,java.vendor
,java.home
,os.name
,os.version
- For memory:
Runtime.getRuntime().maxMemory()
(returns a long value)
Personal Information Collector
EasyCreate a program that collects and displays personal information.
Requirements:
- Create a class called
PersonalInfo
- Ask for: name, age, city, favorite programming language
- Use appropriate input methods for each data type
- Display the information in a formatted way
- Use both
println
andprintf
methods
Sample Output:
Personal Information Collector
============================
Enter your name: John Doe
Enter your age: 20
Enter your city: New York
Enter your favorite programming language: Java
Personal Information:
Name: John Doe
Age: 20
City: New York
Favorite Language: Java
Formatted Output:
Hello John Doe! You are 20 years old and live in New York.
Your favorite programming language is Java.
Calculator Interface
EasyCreate a simple calculator interface that demonstrates input/output operations.
Requirements:
- Create a class called
SimpleCalculator
- Ask for two numbers
- Display the result of addition, subtraction, multiplication, and division
- Format the output nicely with proper spacing
- Handle division by zero gracefully
Sample Output:
Simple Calculator
================
Enter first number: 15
Enter second number: 3
Results:
15 + 3 = 18
15 - 3 = 12
15 * 3 = 45
15 / 3 = 5.0
Medium Exercises - Build Your Skills
Student Grade Calculator
MediumCreate a program to calculate and display student grades with proper documentation.
Requirements:
- Create a class called
GradeCalculator
- Include JavaDoc comments for the class and main method
- Add single-line and multi-line comments explaining the logic
- Calculate average grade from 3 subjects
- Display the result with appropriate formatting
Sample Output:
Student Grade Calculator
=======================
Enter grade for Mathematics: 85
Enter grade for Science: 92
Enter grade for English: 78
Grade Summary:
Mathematics: 85
Science: 92
English: 78
Average Grade: 85.0
Grade Analysis:
Excellent performance! Keep up the good work!
Temperature Converter
MediumCreate a temperature converter with comprehensive commenting.
Requirements:
- Create a class called
TemperatureConverter
- Convert Celsius to Fahrenheit and Kelvin
- Include detailed comments explaining the conversion formulas
- Use constants for conversion factors
- Display results in a table format
Sample Output:
Temperature Converter
====================
Enter temperature in Celsius: 25
Conversion Results:
==================
Celsius: 25.0�C
Fahrenheit: 77.0�F
Kelvin: 298.15K
Conversion Formulas Used:
- Fahrenheit = (Celsius � 9/5) + 32
- Kelvin = Celsius + 273.15
Menu-Driven Program
MediumCreate a menu-driven program that demonstrates various input/output operations.
Requirements:
- Create a class called
MenuProgram
- Display a menu with at least 4 options
- Handle different types of input (strings, numbers, booleans)
- Use proper formatting and spacing
- Include input validation (basic)
Sample Output:
Welcome to the Menu Program!
============================
1. Enter personal details
2. Calculate area of circle
3. Check if number is even/odd
4. Exit
Enter your choice (1-4): 2
Enter radius of circle: 5.0
Area of circle: 78.54 square units
Press Enter to continue...
Data Formatter
MediumCreate a program that formats and displays data in various ways.
Requirements:
- Create a class called
DataFormatter
- Accept different types of data (name, age, salary, date)
- Format the output using different methods
- Demonstrate alignment and spacing
- Use escape sequences for special formatting
Sample Output:
Data Formatter
==============
Enter employee name: Alice Johnson
Enter employee age: 28
Enter employee salary: 65000
Enter hire date: 2023-01-15
Employee Information:
====================
Name: Alice Johnson
Age: 28
Salary: $65,000.00
Hire Date: 2023-01-15
Formatted Output:
Employee: Alice Johnson (28)
Salary: $65,000.00
Hired: 2023-01-15
Hard Exercises - Master the Concepts
Input Validation Program
HardCreate a program that handles various input scenarios gracefully.
Requirements:
- Create a class called
InputValidator
- Ask for age, height, and weight
- Validate that age is between 0-150
- Validate that height is between 0.5-3.0 meters
- Validate that weight is between 1-500 kg
- Display appropriate error messages for invalid input
Sample Output:
Input Validator
===============
Enter your age: 25
Enter your height (in meters): 1.75
Enter your weight (in kg): 70
All inputs are valid!
Age: 25 years
Height: 1.75 meters
Weight: 70 kg
Body Mass Index: 22.86
Debugging Exercise
HardCreate a program with intentional errors for debugging practice.
Requirements:
- Create a class called
DebugExercise
(with errors) - Include syntax errors, logical errors, and runtime errors
- Students must identify and fix the errors
- Program should eventually work correctly
Initial Code (with errors):
public class DebugExercise {
public static void main(String[] args) {
// This program has several errors - fix them!
int number = 10
String message = "Hello World"
System.out.println("Number: " + number);
System.out.println("Message: " + message);
// Calculate sum of numbers 1 to 10
int sum = 0;
for(int i = 1; i <= 10; i++) {
sum = sum + i;
}
System.out.println("Sum: " + sum);
// Calculate average
double average = sum / 10;
System.out.println("Average: " + average);
}
}
Student Information System
HardCreate a comprehensive program that integrates all concepts from Module 1.
Requirements:
- Create a class called
StudentInfoSystem
- Collect student information (ID, name, age, major, GPA)
- Display information in multiple formats
- Include proper documentation and comments
- Use all input/output methods learned
- Format output professionally
Sample Output:
Student Information System
==========================
Enter Student ID: S001
Enter Student Name: Maria Garcia
Enter Student Age: 22
Enter Student Major: Computer Science
Enter Student GPA: 3.85
Student Information:
===================
ID: S001
Name: Maria Garcia
Age: 22
Major: Computer Science
GPA: 3.85
Academic Status: Excellent
Recommendation: Eligible for honors program
Formatted Summary:
Student S001 (Maria Garcia) is a 22-year-old Computer Science major
with an excellent GPA of 3.85.
Submission Guidelines
For Each Exercise:
- Create the Java file with the exact class name specified
- Include proper comments and documentation
- Test your program with various inputs
- Ensure clean, readable code following naming conventions
- Handle edge cases appropriately
Code Quality Requirements:
- ? Proper indentation and spacing
- ? Meaningful variable names
- ? Comprehensive comments
- ? Error handling where appropriate
- ? Professional output formatting
Testing Checklist:
- ? Program compiles without errors
- ? Program runs without runtime errors
- ? Output matches expected format
- ? Input validation works correctly
- ? Edge cases are handled properly
Bonus Challenges
Challenge 1: ASCII Art Generator
Create a program that generates ASCII art using the concepts learned.
Challenge 2: Interactive Quiz System
Build a simple quiz system with multiple-choice questions.
Challenge 3: Data Visualization
Create a program that displays data in a visual format using ASCII characters.