Java Lab Assignment
Java Lab Assignment
Instructions:
Solve all the problems. Different submission link will be created for submitting different
problems. So submit carefully.
Codes will be checked against MOSS Standard copy checker. Any kind of plagiarism will
be punished with negative full marks. There will be no source and copier. Both will be
under penalty. So be careful because this can cause failure in this course.
Book.java
Library.java
public class Library {
// Add the missing implementation to this class
String address;
Book[] bookList;
int currentNumberofBooks;
int capacity;
}
void addBook(Book b){
//add this book object to bookList array. Update
currentNumberofBooks
}
void borrowBook(String title){
//search the book in the bookList array using the title
parameter. if book is available mark that book as borrowed
(Hint call method of book class)
}
void returnBook(String title){
//search the book in the bookList array using the title
parameter. mark that book as not borrowed (Hint call method of
book class)
}
void printAvailableBooks(){
//print the titles of the books which borrowed is false
}
System.out.println("Borrowing Bohubrihi:");
firstLibrary.borrowBook("Bohubrihi");
System.out.println("Borrowing Feluda Part-2:");
firstLibrary.borrowBook("Feluda Part-2");
// Print the titles of all available books from firstLibrary
System.out.println("Books available in the library:");
firstLibrary.printAvailableBooks();
System.out.println();
An employee gets paid (hours worked) × (base pay), for each hour up to 40 hours.
For every hour over 40, they get overtime = (base pay) × 1.5.
If the number of hours is greater than 60, print an error message.
Example: If an employee works for 45 hours, and his base pay is $8 , the he will get= (40 * 8)+
[5* (8 * 1.5)] = $380
Create a new class called StarkIndustry.
Write a method that takes the base pay and hours worked as parameters, and prints the total
pay or an error. Write a main method that calls this method for each of these employees:
Problem 3:
Complete this code: https://paste.ubuntu.com/p/kp25C3TSmG/
Description: Create a class Course and Student with the following attributes and methods;
Course:
Double gpa(private), String courseName(private), double credit(private)
course(String courseName, double gpa, double credit){Assign the corresponding variables}
Student:
Course[] C(private), String name(private), int totalCourse(private)
Student(String name, int totalCourse){Assign the corresponding variables, }
Void addCourse(Course c){Add the course to the course list}
Now in the main class, you will take n as input which will be the total number of students'
information. It will be followed by each students’ name, total course number and courseinfos’.
You have to print each student's information in the reverse order.
See all rows’, columns’ and diagonal’s sum is same. Write a main method where first you need
to input n. Then input n*n integers and form a 2D matrix. Print “YES” if the matrix is magic
square and print “NO” Otherwise.
Class Queue:
double[] queueElements (public), int queueCapacity (private), int lastIndex (private)
public Queue(int capacity) {
//assign the member variables
}
void enqueue(double n) {
//add this n to end of the queueElements array, show error if no capacity to hold this
value
}
void dequeue() {
//remove the first element of the queueElements array. Update the array accordingly.
}
void printElements() {
//show the elements of queueElements array.
}
See the following main method and observe the output. Complete the Queue class to get the
output exactly shown in the table below:
QueueTest.java Ouput
Create a class named vehicle and two sub classes private_vehicle and public_vehicle with the
following attributes and methods.
Vehicle:
double fitnessTax
//returns fitnessTax+roadTax
double fitnessTax
double total_tax(){
//returns 1.5*(fitnessTax+roadTax)
Now in the main class, create an array of 5 vehicles and assign some private vehicle and public
vehicle in different indexes. Now print every vehicle's total_tax.
a) An account holder can deposit or withdraw different amounts from a SavingsAccount and
pay an interest rate 0f 1.5% during withdrawal. A SavingsAccount can charge a fee if the
balance falls below a certain amount.
b) An account holder using a BasicAccount pays 0.5% during withdrawal and has only 3 free
transactions. Transaction includes both deposit and withdrawal of money. A BasicAccount can
charge a fee if the number of transactions exceeds the specified number of transactions.
The required variables for different classes are given. All these variables are private. You can
add any variable if you need.
Finally write a main function: create different SavingsAccount and BasicAccount objects. Then
check the functionalities of deposit and withdraw of different amounts.