0% found this document useful (0 votes)
5 views3 pages

Lab Tasks Spring 2025

The document contains two Java programming tasks authored by Muhammad Ahmed Rashid Paracha for the CL1002 course. Task 1 involves creating a class to calculate the average of purchase amounts entered by the user, while Task 2 involves a billing application for a stationary shop that calculates the total bill based on product code and quantity. Both tasks demonstrate fundamental programming concepts and user input handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Lab Tasks Spring 2025

The document contains two Java programming tasks authored by Muhammad Ahmed Rashid Paracha for the CL1002 course. Task 1 involves creating a class to calculate the average of purchase amounts entered by the user, while Task 2 involves a billing application for a stationary shop that calculates the total bill based on product code and quantity. Both tasks demonstrate fundamental programming concepts and user input handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Tasks

**Author:** Muhammad Ahmed Rashid Paracha

**Student ID:** 24K-6040

**Course:** CL1002 - Programming Fundamentals - LAB

**Spring 2025**

Task 1: Average Purchase Class


```java

// Author: Muhammad Ahmed Rashid Paracha


// Student ID: 24K-6040
import java.util.Scanner;

class AveragePurchase {
private double[] purchases;

public AveragePurchase(int n) {
purchases = new double[n];
}

public void takeInput() {


Scanner scanner = new Scanner(System.in);
for (int i = 0; i < purchases.length; i++) {
System.out.print("Enter purchase amount " + (i + 1) + ": ");
purchases[i] = scanner.nextDouble();
}
}

public void displayPurchases() {


System.out.println("Purchased items:");
for (double purchase : purchases) {
System.out.println("$" + purchase);
}
}

public double calculateAverage() {


double sum = 0;
for (double purchase : purchases) {
sum += purchase;
}
return sum / purchases.length;
}

public static void main(String[] args) {


AveragePurchase ap = new AveragePurchase(3);
ap.takeInput();
ap.displayPurchases();
System.out.println("Average purchase: $" + ap.calculateAverage());
}
}

```

Task 2: Billing Application for Stationary Shop


```java

// Author: Muhammad Ahmed Rashid Paracha


// Student ID: 24K-6040
import java.util.Scanner;

class BillingApplication {
private static final int[][] stock = {{1, 20}, {2, 25}};

public static int calculateBill(int productCode, int quantity) {


for (int[] item : stock) {
if (item[0] == productCode) {
return item[1] * quantity;
}
}
return 0;
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
System.out.print("Enter product code (1 or 2): ");
int productCode = scanner.nextInt();
System.out.print("Enter quantity: ");
int quantity = scanner.nextInt();

int totalBill = calculateBill(productCode, quantity);

System.out.println("Invoice:");
System.out.println("Product Code: " + productCode);
System.out.println("Total Bill: $" + totalBill);
}
}

```

You might also like