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
4 Easy Exercises
4 Medium Exercises
3 Hard Exercises

Easy Exercises - Start Here!

1.1

Create Your First Java File

Easy

Write 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
1.2

Verify Java Installation

Easy

Create 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)
1.3

Personal Information Collector

Easy

Create 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 and printf 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.
1.4

Calculator Interface

Easy

Create 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

2.1

Student Grade Calculator

Medium

Create 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!
2.2

Temperature Converter

Medium

Create 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
2.3

Menu-Driven Program

Medium

Create 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...
2.4

Data Formatter

Medium

Create 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

3.1

Input Validation Program

Hard

Create 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
3.2

Debugging Exercise

Hard

Create 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);
    }
}
3.3

Student Information System

Hard

Create 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:

  1. Create the Java file with the exact class name specified
  2. Include proper comments and documentation
  3. Test your program with various inputs
  4. Ensure clean, readable code following naming conventions
  5. 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.

?? Ready to Start Coding?

Complete these exercises to master Java fundamentals and environment setup. Remember: Practice makes perfect!