Programming Fundamentals
Lab 02
Topic Getting Started with Java
Tool Installation
Basic Java Syntax
Objective
Input/Output
Datatypes and Variables
Installation Guide:
Installation Guide for IntelliJ IDEA Community Edition
IntelliJ IDEA is a powerful IDE for Java development. This guide walks you through installing
the free Community Edition.
Step 1: Download IntelliJ IDEA
1. Open your web browser and go to the official JetBrains website:
🔗 https://www.jetbrains.com/idea/download/
2. Select the Community Edition (free version).
3. Click the Download button.
Step 2: Install IntelliJ IDEA
For Windows:
1. Run the downloaded .exe file.
2. Click Next to begin the installation.
3. Choose the installation path (default is recommended).
4. Select additional options:
o Add launcher to the desktop (optional).
o Associate .java files with IntelliJ IDEA (recommended).
5. Click Install and wait for the process to complete.
6. Once installed, click Finish and launch IntelliJ IDEA.
For macOS:
1. Open the downloaded .dmg file.
2. Drag and drop IntelliJ IDEA into the Applications folder.
3. Open IntelliJ IDEA from the Applications folder.
For Linux:
1. Extract the downloaded .tar.gz file to a preferred location.
2. Open a terminal and navigate to the bin folder inside the extracted directory.
3. Run the command:
4. ./idea.sh
5. The IntelliJ IDEA setup wizard will open.
Step 3: Initial Setup
1. On the first launch, choose whether to import previous settings or start fresh.
2. Select the UI theme (Light or Dark).
3. Click Next and install necessary plugins if needed.
4. Click Start IntelliJ IDEA to complete the setup.
Step 4: Creating Your First Java Project
1. Click New Project on the welcome screen.
2. Select Empty Project and choose the installed JDK (download if not available).
3. Set the project name and location.
4. Click Finish to create your project.
5. Write click on the project name and add.java file
6. Write a simple Java program and run it using the Run button.
Lab task
Write Java Code for each given Problem
Task1: Monthly Budget Planner
You are building a monthly budget planner to help users manage their expenses. The system
should:
1. Ask the user to input their total monthly income.
2. Ask the user to input their expenses in categories like rent, groceries, utilities,
transportation, and entertainment.
3. Calculate and display the total expenses.
4. Calculate and display the remaining balance (income - expenses).
Input/Output Steps:
1. Input: Monthly income and expenses in different categories.
2. Output: Total expenses and remaining balance.
Task 2: Loan Payment Calculator
A user wants to calculate their monthly loan payment. The system should:
1. Ask the user to input the loan amount, interest rate, and the number of years for the loan.
2. Use a simple formula to calculate the monthly payment:
Monthly Payment= (Loan Amount × Interest Rate) / number of years
3. Display the calculated monthly payment.
Input/Output Steps:
1. Input: Loan amount, interest rate, and number of years.
2. Output: Monthly payment.
Task 3: Currency Converter (USD to PKR)
You are building a currency converter for a travel website. The system should:
1. Ask the user to input the amount of money they want to convert.
2. Based on the exchange rate, calculate the converted amount.
3. Display the converted amount.
Input/Output Steps:
1. Input: source currency and target currency.
2. Output: Converted amount based on exchange rate.
Task 4: Employee Paycheck Generator
A company wants to generate paychecks for its employees. The system should:
1. Ask the user to input the employee’s ID (numeric), hourly wage, and number of hours
worked.
2. Calculate the gross pay (hours worked × hourly wage).
3. Calculate the net pay after deducting taxes (assume a tax rate of 20%).
4. Display the paycheck details (employee ID, gross pay, and net pay).
Input/Output Steps:
1. Input: Employee ID, hourly wage, and hours worked.
2. Output: Gross pay and net pay.
Task 5: Classroom Average Marks Calculator
A teacher wants to calculate the average marks for a class. The system should:
1. Ask the user to input the number of students.
2. For each student, input their marks out of 100.
3. Calculate and display the average marks for the class.
Input/Output Steps:
1. Input: Number of students and each student’s grade.
2. Output: Average marks.
Task 6: Fuel Cost Estimator for a Trip
A driver wants to estimate the cost of fuel for a road trip. The system should:
1. Ask the user to input the distance of the trip (in kilometers).
2. Ask the user to input their vehicle's fuel efficiency (liters per 100 kilometers) and the current
price of fuel per liter.
3. Calculate the total fuel cost for the trip.
4. Display the estimated fuel cost.
Input/Output Steps:
1. Input: Trip distance, fuel efficiency, and fuel price.
2. Output: Total fuel cost for the trip.
Task 7: Event Ticket Price Calculator
You are designing a system for an event ticket booth. The system should:
1. Ask the user to input the number of adults and children attending the event.
2. The price per adult is $20, and the price per child is $10.
3. Calculate and display the total cost of the tickets.
Input/Output Steps:
1. Input: Number of adults and children.
2. Output: Total cost for the tickets.
Home Task
Task: Write a Java Program
A household wants to calculate their monthly electricity bill. The system should:
1. Ask the user to input the number of units of electricity consumed.
2. Charge $0.12 per unit for the first 100 units, $0.15 per unit for the next 200 units, and $0.20
per unit for additional units.
3. Calculate and display the total electricity bill.
Input/Output Steps:
1. Input: Number of units consumed.
2. Output: Total electricity bill.
Note: Do not use any conditional statements
Hint: Use multiple variables to achieve your answer