0% found this document useful (0 votes)
23 views8 pages

Bilal Rafique

The document is a lab exam submission by Muhammad Bilal Rafiuqe for the BS-IT program at the National University of Modern Languages. It includes code examples for a Book class, Employee classes, and a Student interface, with various corrections and improvements noted throughout. The document emphasizes proper naming conventions and coding practices in Java.

Uploaded by

Talha Khursheed
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)
23 views8 pages

Bilal Rafique

The document is a lab exam submission by Muhammad Bilal Rafiuqe for the BS-IT program at the National University of Modern Languages. It includes code examples for a Book class, Employee classes, and a Student interface, with various corrections and improvements noted throughout. The document emphasizes proper naming conventions and coding practices in Java.

Uploaded by

Talha Khursheed
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/ 8

Lab exam

Submitted By:
Muhammad Bilal Rafiuqe
Rc-50152
Submitted To:
Sir Faheem

CLASS: BS-IT (`2th Semester)

Department of Software Engineering


NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF Software Engineering

NATIONAL UNIVERSITY OF MODERN LANGUAGES -


RAWALPINDI

Code1:
public class Book {
private String name; // Use 'String' instead of 'string'
private String author;
private int count;

public Book(String name, String author, int count) {


this.name = name;
this.author = author;
this.count = count;
}

public void purchase() {


if (count > 0) {
count--;
System.out.println("You have purchased \"" +
name + "\". Remaining count: " + count);
} else {
System.out.println("\"" + name + "\" is out of
stock.");
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF Software Engineering

}
}
}

class Customer { // Class names should start with an


uppercase letter
private int customerId;
private String name;
private String address;

public Customer(int customerId, String name, String


address) {
this.customerId = customerId;
this.name = name;
this.address = address;
}

// Optional: You can add getters and setters here if


needed
}

public class EBookStall {


NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF Software Engineering

public static void main(String[] args) { // Use 'String'


instead of 'string'
Book book1 = new Book("The Hobbit", "J.R.R.
Tolkien", 5); // Corrected the author name
Customer customer1 = new Customer(1, "Afnan
Khan", "123 Main St"); // Added customer ID and
address

book1.purchase();
}
}
Code2:
abstract class Employee {
public abstract double getAmount();
}

class WeeklyEmployee extends Employee { // Class names


should start with an uppercase letter
private int weeksWorked; // Corrected variable name
private double weeklyPay;

public WeeklyEmployee(int weeksWorked, double


weeklyPay) { // Fixed parameter names
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF Software Engineering

this.weeksWorked = weeksWorked;
this.weeklyPay = weeklyPay; // Added missing
semicolon
}

@Override // Corrected annotation capitalization


public double getAmount() {
return weeksWorked * weeklyPay;
}
}

class HourlyEmployee extends Employee {


private int hoursWorked;
private double hourlyRate;

public HourlyEmployee(int hoursWorked, double


hourlyRate) {
this.hoursWorked = hoursWorked;
this.hourlyRate = hourlyRate;
}

@Override // Corrected annotation capitalization


NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF Software Engineering

public double getAmount() {


return hoursWorked * hourlyRate; // Fixed variable
name
}
}
Code3:
public class Student {

interface StudentFee {
double getAmount(); // Fixed spelling of 'getAmount'
String getFirstName(); // Changed 'string' to 'String'
and fixed method name
String getLastName(); // Changed 'string' to 'String'
String getAddress(); // Changed 'string' to 'String'
String getContact(); // Fixed method name and
changed 'string' to 'String'
}

class HostlerStudent implements StudentFee {


private String firstName; // Changed 'string' to
'String'
private String lastName; // Changed 'string' to
'String'
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF Software Engineering

private String address; // Changed '


NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF Software Engineering

You might also like