BCS-452 (Object Oriented Programming Using Java Lab)
BCS-452 (Object Oriented Programming Using Java Lab)
Object Oriented
Programming using Java
Lab
BCS-452
Table of Contents
Syllabus
Lab Plan
List of Experiments
To achieve excellence in professional education and create an ecosystem for the holistic
development of all stakeholders.
1. To provide broad based quality education with knowledge and attitude to succeed in
Computer Science & Engineering careers.
2. To prepare students for emerging trends in computer and related industry.
3. To develop competence in students by providing them skills and aptitude to foster
culture of continuous and life-long learning.
4. To develop practicing engineers who investigate research, design and find workable
solutions to complex engineering problems with awareness & concern for society as
well as environment.
PO5 Modern Tool Usage Create, select, and apply appropriate techniques,
resources, and modern engineering and IT tools including
prediction and modeling to complex Computer Science &
Engineering activities with an understanding of the
limitations.
PO6 The Engineering Apply reasoning informed by the contextual knowledge
and Society to assess societal, health, safety, legal and cultural issues
and the consequent responsibilities relevant to the
professional engineering practice in the field of
Computer Science & Engineering.
PO7 Environment and Understand the impact of the professional Computer
Sustainability Science & Engineering solutions in societal and
environmental contexts, and demonstrate the knowledge
Syllabus
Following table outline the syllabus for Python Language Programming Lab (BCS-452) as
prescribed by Dr. A.P.J. Abdul Kalam Technical University, Uttar Pradesh, Lucknow.
The Syllabus can also seen on the university website:
[Link]
B.Tech_2nd_Yr_CSE_v3.pdf
LAB PLAN
List of Experiments
Attributes Values
barCode 1001
name Cadbury
weight 15
cost 50
Use the below skeleton code for the Tester class main
method and do the required implementation. public class
ChocolateTester{ public static void main (String[] args)
{ //Create an object of chocolate //Use getter methods to
display the values //Use setter methods to modify the
values //Use getter methods to display the modified
values } }
A company wants to keep a record of the employees
working in it. There are permanent employees as well as
contract employees. Contract employees work on an
hourly basis whereas permanent employees are paid
3 monthly salary. The class diagrams are as given below:
Employee:
Employee
empId : int
name : String
salary : double
getSalary() : double
setSalary(salary:double) : void
getEmpId() : int
setEmpId(empId :int) : void
getName() : String
setName(name : String) : void
Method Description:
calculateSalary():This method calculates the salary using the
formula as given below:
Salary = variable component + Basic pay +HRA
The condition for calculating variable component is given
below:
ContractEmployee:
ContractEmployee
wages : double
hours : int
getWages(): double
setWages(wages: double): void
getHours(): int
setHours(hours: int): void
calculateSalary(): void
Method Description:
calculateSalary():This method calculates the salary
using the formula as given below: Salary = total
hours * wages
Implementation Details:
Create a class
EmployeeRecords and
implement the main method:
public class EmployeeRecords {
}
}
Provider (interface)
+ totalMaximumMarks: int
+ calcPercentage(): void
Intern: This class for interns who completed their course in
Institute A.
Intern (class)
- marksSecured: int
- graceMarks: int
+ Intern(marksSecured:int, graceMarks: int)
+ calcPercentage(): void
Trainee (class)
- marksSecured: int
+ Trainee(marksSecured: int)
Method +calcPercentage(): void
Description:
calcPercentage(): calculates the overall percentage of the
marks of the trainee.
Input (For Intern):
Attribute Values
Marks Secure 4500
Output: The Grace Marks 400 total aggregate
percentage secured is [Link] Input (For Trainee):
Attributes Values
Marks Secured 5500
Attributes Values
Marks Secured 8000
Grace Marks 500
Student (class)
- name: String
- course : String
- rollNumber : int
+ Student(name: String, course: String, rollNumber:int)
+ toString() : String
+ add() : boolean
Student (class)
- name: String
- course : String
- rollNumber : int
+ Student(name: String, course: String, rollNumber:int)
Class Description:
MyPaymentServices: This is the base class for
CreditCardPayment and ShoppingPayment classes. It will
store the amount to be paid by the user in the instance
variable balance of the class.
MyPaymentService
-balance:double
-customerId:int
+MyPaymentService(balance:double, customerId:int)
+setBalance(balance:double):void
+getBalance():doublie
+getCustomerId():int
+payBill(amount:double):void
Method Description:
payBill(double amount): This is an abstract method that has
to be implemented by the child classes of
MyPaymentServices.
ShoppingPayment:
This class is a child class of MyPaymentServices. It has a
static variable counter, to set the paymentID. The class
diagram is shown below:
ShoppingPayment
- static counter: int
- pymentId:String
+ ShoppingPayment(balance:double, customerId:int)
+ getPaymentId(): String
+ payBill(amount: double): void
Method DeSscription:
payBill(double amount): For a shopping bill payment, the
payment id should start with 'S' followed by a four digit
integer number. If the user enters an amount not equal to the
balance which is due, an appropriate error message should
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING BCS-452
PSIT-Pranveer Singh Institute of Technology
Kanpur-Delhi National Highway (NH-19), Bhauti, Kanpur-209305 (U.P.), India
CreditCardPayment
- static conter:int
- paymentId:String
- cashBack: double
- balanceDue: double
+ CreditCardPayment(balance:double, customerId:int)
+ getPaymentId(): String
+ getCashBack(): double
+ getBalanceDue(): double
+ payBill(amount:double):void
Method Description:
payBill(double amount): For credit card bill payment, if a
user enters an amount more than the amount to be paid, the
excess amount should be stored as cashBack. The payBill
method is used to pay the bill and generate
the transaction id. The id should start with 'C' followed by a
four-digit integer number. In case the user enters an amount
less than the amount to be paid, then the remaining amount
should be stored in the instance variable balanceDue of
class CreditCardPayment.
Use a Tester class to test your code and display the
payment information.
The balanceDue after the payment should be
communicated to the user.
Some outputs with different inputs are given below for your
reference.
Output
Congratulations: You have successfully made a
payment of Rs. 15000 .Payment details are:-
Customer Id: 5001
Payment Id: 1001
Previous Due: 10000.56
Remaining Due: 0
Cash Back Wallet Balance: 4999.44
Attributes Values
Balance 10000.56
Customer Id 5001
Paid Amount 0
Output
Congratulations: You have successfully made a
payment of Rs. 0.0 .Payment details are:-
Customer Id: 5001
Payment Id: C1002
Previous Due: 10000.56
Remaining Due: 10000.56
Cash Back Wallet Balance : 0.0
Attributes Values
Attributes Values
Balance 5000.56
Customer Id 561328
Paid Amount 5000.00
Output
Congratulations: You have successfully made a payment
of Rs. 0.0 with Payment Id: s1001
Experiment No. 1
Objective:. Write a program to track of 10 employees in the project and their salaries,
and also find out the average of their salaries. They also want to find the number of
employees who get a salary greater than the average salary and those who get lesser.
Consider that the salaries are stored in an array of double variables as given below:
double salary[] = {23500.0, 25080.0, 28760.0, 22340.0, 19890.0, 23555.0, 25980.0,
29760.0, 23340.0, 29890.0} Create a class EmployeeRecord and write a program to
implement the above requirement. Refer to the output given below: The average salary of
the employee is : XXXXXX The number of employees having salary greater than the
average is : Y The number of employees having salary lesser than the average is : Z.
Program:
belowAverageCount++;
}
}
// Output results
[Link]("The average salary of the employees is: " + averageSalary);
[Link]("The number of employees having salary greater than the
average is: " + aboveAverageCount);
[Link]("The number of employees having salary lesser than the average
is: " + belowAverageCount);
}
}
Experiment No. 2
Objective:. Create a class Chocolate, with a parameterized constructor and a default
constructor. Also, use the "this" keyword while initializing member variables within the
parameterized constructor. Every chocolate which is manufactured will be with a default
weight and cost. The cost and weight might be modified later based on business needs.
Constructor Description: Chocolate( int barCode, String name, double weight, double
cost): In the constructor initialize the member variables, barCode, name, weight, and cost,
according to the table given below:
Attributes Values
barCode 1001
name Cadbury
weight 15
cost 50
Use the below skeleton code for the Tester class main method and do the required
implementation. public class ChocolateTester{ public static void main (String[] args)
{ //Create an object of chocolate //Use getter methods to display the values //Use setter
methods to modify the values //Use getter methods to display the modified values } }
Program:
public class Chocolate {
// Member variables
// Setter methods
public void setBarCode(int barCode) {
[Link] = barCode;
}
public void setName(String name) {
[Link] = name;
}
public void setWeight(double weight) {
[Link] = weight;
}
public void setCost(double cost) {
[Link] = cost;
}
}
public class ChocolateTester {
public static void main(String[] args) {
// Create an object of chocolate using default constructor
Chocolate chocolate1 = new Chocolate();
[Link]("\nModified Values:");
[Link]("Bar Code: " + [Link]());
[Link]("Name: " + [Link]());
[Link]("Weight: " + [Link]() + "g");
[Link]("Cost: $" + [Link]());
}
}
Experiment No. 3
Objective:. A company wants to keep a record of the employees working in it. There are
permanent employees as well as contract employees. Contract employees work on an
hourly basis whereas permanent employees are paid monthly salary. The class diagrams
are as given below: Employee:
Employee
empId : int
name : String
salary : double
getSalary() : double
setSalary(salary:double) : void
getEmpId() : int
setEmpId(empId :int) : void
getName() : String
setName(name : String) : void
A record of the employee name, salary, and the employee Id has to be maintained for
each employee. PermanentEmployee:
PermanentEmployee
basicPay : double
hra : double
experience : int
getBasicPay() : double
setBasicPay(salary:double) : void
getHra() : double
setHra(empId :double) : void
getExperience() : int
setExperience(name : int) : void
calculateSalary() : void
Method Description:
calculateSalary():This method calculates the salary using the formula as given below:
Salary = variable component + Basic pay +HRA
The condition for calculating variable component is given below:
Experience (in years) % of Basic pay
<5 0
>= 5 and < 7 5
>= 7 and < 12 10
>= 12 15
ContractEmployee:
ContractEmployee
wages : double
hours : int
getWages(): double
setWages(wages: double): void
getHours(): int
setHours(hours: int): void
calculateSalary(): void
Method Description:
calculateSalary():This method calculates the salary using the formula as given below:
Salary = total hours * wages
Implementation Details:
Create a class EmployeeRecords and implement the main method: public class
EmployeeRecords {
Public static void main(String str[]){
{
}
}
Provide the following inputs:
Input (For PermanentEmployee):
Attributes Values
Name Abc
Employee Id 1001
Basic Pay 12500
HRA 3500
Experience 6
Output: Permanent Employee: Your Salary is : XXXX
Input (For ContractEmployee):
Attributes Values
Name Xyz
Employee Id 7001
Wages 750
Hours 15
Output: Contract Employee: Your Salary is : XXXX
Note:- You call setter and getter method of salary of Employee class using an instance of
both Permanent as well as Contract Employee. The getter and setter method of instance
variable in parent class can be reused by child classes as it is inherited from parent and
hence need not be created again.
Program:
class Employee {
// Member variables
private String name;
private int employeeId;
private double salary;
// Constructor
public Employee(String name, int employeeId) {
[Link] = name;
[Link] = employeeId;
}
// Getter and setter methods
public double getSalary() {
return salary;
}
variableComponent = 0;
else if (experience < 7)
variableComponent = 0.05 * basicPay;
else if (experience < 12)
variableComponent = 0.10 * basicPay;
else
variableComponent = 0.15 * basicPay;
// Constructor
public ContractEmployee(String name, int employeeId, double wages, int hours) {
super(name, employeeId);
[Link] = wages;
[Link] = hours;
}
// Method to calculate salary for contract employees
public void calculateSalary() {
double salary = wages * hours;
setSalary(salary);
}
}
public class EmployeeRecords {
public static void main(String[] args) {
// Creating a PermanentEmployee object and calculating salary
PermanentEmployee permanentEmployee = new PermanentEmployee("Abc",
1001, 12500, 3500, 6);
[Link]();
[Link]("Permanent Employee: Your Salary is: $" +
[Link]());
// Creating a ContractEmployee object and calculating salary
ContractEmployee contractEmployee = new ContractEmployee("Xyz", 7001,
750, 15);
[Link]();
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING BCS-452
PSIT-Pranveer Singh Institute of Technology
Kanpur-Delhi National Highway (NH-19), Bhauti, Kanpur-209305 (U.P.), India
Experiment No. 4
Objective:. The Provider as interface, provides an efficient way for students to calculate their
overall percentage of all the courses. The total Maximum Marks for all courses is 8000. Intern
studied in Institute A, where each semester comprises of 1000 marks, in which 900 marks are for
courses and 100 marks are kept for co-curricular activities (grace Marks). Whereas Trainee
studied in Institute B where each semester comprises of 1000 marks for courses.
Provider (interface)
+ totalMaximumMarks: int
+ calcPercentage(): void
Intern: This class for interns who completed their course in Institute A.
Intern (class)
- marksSecured: int
- graceMarks: int
+ Intern(marksSecured:int, graceMarks: int)
+ calcPercentage(): void
Method Description: calcPercentage(): This method will calculate the total marks of the intern
which is the sum of grace marks and the marks secured by the intern, and hence
calculate the percentage on the totalMaximumMarks.
Trainee: This class is for trainees who completed their course in Institute B.
Trainee (class)
- marksSecured: int
+ Trainee(marksSecured: int)
+calcPercentage(): void
Method Description: calcPercentage(): calculates the overall percentage of the marks of the
trainee.
Attribute Values
Output: The total aggregate Marks Secure 4500 percentage secured is [Link] Input
(For Trainee): Grace Marks 400
Attributes Values
Marks Secured 5500
Program:
> [Link]
public class Employee { private String empName; private int empAge; private double empSalary;
return empSalary;
}
>[Link]
> [Link]
public class Service {
public static void checkEmployeeSalary(Employee emp) throws EmpSalaryException {
if ([Link]() < 1000) {
throw new EmpSalaryException("Salary is less than 1000 for employee:
" + [Link]());
}
}
Experiment No. 6
Objective:. Create a Java program that adds Student objects into a HashSet. The Student
class has name, course and rollNumber as its attributes and a toString() method. If we add
two Student objects having the same rollNumber to the HashSet, it should be considered as
duplicate and should not get added.
Student (class)
- name: String
- course : String
- rollNumber : int
+ Student(name: String, course: String, rollNumber:int)
+ toString() : String
+ add() : boolean
Program:
@Override
public String toString() { return "Student{" +
"name='" + name + '\'' +
", course='" + course + '\'' +
", rollNumber=" + rollNumber + '}';
}
@Override
public boolean equals(Object o) { if (this == o) return true;
if (o == null || getClass() != [Link]()) return false; Student student = (Student) o;
return rollNumber == [Link];
@Override
public int hashCode() {
return [Link](rollNumber);
}
}
Student student1 = new Student("Alice", "Math", 101); Student student2 = new Student("Bob",
"Science", 102);
Student student3 = new Student("Charlie", "Math", 101); // Duplicate rollNumber
public class Employee { private String empName; private int empAge; private double empSalary;
Experiment No. 7
Objective:. Write a Java program that creates a “XYZBank” saving account with
concurrent deposits and withdrawals using threads.
The XYZBank class represents a bank saving account with a balance. For deposit() and
withdrawal() methods, different threads can execute them concurrently without conflict.
In the deposit() method, the lock is acquired before updating the balance with the
deposited amount. The lock is acquired in the withdraw() method before checking the
balance and completing the withdrawal. If withdraw amount is greater than balance
amount then show insufficient balance message.
The main method creates an instance of XYZBank and starts four threads: two for
deposits and two for withdrawals. Each thread invokes the corresponding method on the
BankAccount instance, simulating concurrent deposits and withdrawals.
Program:
import [Link];
import [Link];
class XYZBank {
private double balance;
private final Lock lock = new ReentrantLock();
}
};
[Link]();
[Link]();
[Link]();
[Link]();
try {
[Link]();
[Link]();
[Link]();
[Link]();
} catch (InterruptedException e) {
[Link]().interrupt();
}
Experiment No. 8
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING BCS-452
PSIT-Pranveer Singh Institute of Technology
Kanpur-Delhi National Highway (NH-19), Bhauti, Kanpur-209305 (U.P.), India
Objective:. Write a code using lambda expressions to display the name of all
the employees and their [Link] the following Employee class:
class Employee {
public int id;
public String
name; private int
salary;
private double yearsInOrg;
private String role;
private String gender;
public Employee(int id, String name, int salary, double years, String role, String
gender) { [Link] = id;
[Link] = name;
[Link] = salary;
[Link] = years;
[Link] = role;
[Link] = gender;
}
// Getters and setters
}
class LambdaExercise {
public static void main(String[] args) {
Employee e1 = new Employee(1069001, "John", 100000, 1.0, "Manager", "M");
Employee e2 = new Employee(1069002, "Mike", 50000, 1.7, "Systems Engineer",
"M"); Employee e3 = new Employee(1069003, "Harvey", 75000, 6.9, "Manager",
"M"); Employee e4 = new Employee(1069004, "Jessica", 25000, 3.1, "Trainee",
"F");
Employee e5 = new Employee(1069005, "Rachel", 53000, 2.0, "Support", "F");
ArrayList<Employee> employeeArr = new
ArrayList<>(); [Link](e1);
[Link](e2);
[Link](e3);
[Link](e4);
[Link](e5);
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING BCS-452
PSIT-Pranveer Singh Institute of Technology
Kanpur-Delhi National Highway (NH-19), Bhauti, Kanpur-209305 (U.P.), India
Program:
### Part 1: Using Lambda Expressions to Display Employee Names and Genders
Let's start with the first part of your request, which involves using lambda expressions to
display the names and genders of employees from a list. The `Employee` class will have
getters for the `name` and `gender` properties, and we'll utilize lambda expressions to
print these details.
class Employee {
public int id;
public String name;
private int salary;
private double yearsInOrg;
private String role;
private String gender;
public Employee(int id, String name, int salary, double years, String role, String
gender) {
[Link] = id;
[Link] = name;
[Link] = salary;
[Link] = years;
[Link] = role;
[Link] = gender;
}
// Using lambda expressions to display the name and gender of each employee
[Link](e -> [Link]("Name: " + [Link]() + ",
Gender: " + [Link]()));
}
}
```
For the second part, let's create a Spring application to display the details of a `Student`
on the console. This involves creating a `Student` class, a Spring XML configuration file,
and a main application class to load the context and display the student details.
[Link] = name;
[Link] = course;
[Link] = rollNumber;
}
@Override
public String toString() {
return "Student{name='" + name + "', course='" + course + "', rollNumber=" +
rollNumber + "}";
}
}
```
</beans>
```
3. **Create the main application class to load the context and display the student
details:**
```java
import [Link];
import [Link];
By following these steps, you can display the names and genders of employees using
lambda expressions and create a Spring application to display student details on the
console.
Experiment No. 9
Objective:. Create an application to display the details of the Student on the console. A
Model class “Student” has the below properties.
Student (class)
- name: String
- course : String
- rollNumber : int
+ Student(name: String, course: String, rollNumber:int)
Create a spring xml configuration file to create a bean entry for the Movie object with
some sample property values.
Program:
### Step 1: Define the `Student` Class
```java
public class Student {
private String name;
private String course;
private int rollNumber;
// Getters
public String getName() {
return name;
}
@Override
public String toString() {
return "Student{name='" + name + "', course='" + course + "', rollNumber=" + rollNumber +
"}";
}
}
```
```java
public class Movie {
private String title;
private String genre;
private int duration; // duration in minutes
// Getters
public String getTitle() {
return title;
}
@Override
public String toString() {
return "Movie{title='" + title + "', genre='" + genre + "', duration=" + duration + " minutes}";
}
}
```
```xml
<?xml version="1.0" encoding="UTF-8"?>
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING BCS-452
PSIT-Pranveer Singh Institute of Technology
Kanpur-Delhi National Highway (NH-19), Bhauti, Kanpur-209305 (U.P.), India
<beans xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link]
[Link]
</beans>
```
### Step 4: Create the Main Application Class to Load the Context and Display the Details
```java
import [Link];
import [Link];
1. Ensure your project includes Spring framework dependencies. For example, if you are using
Maven, include the following dependencies in your `[Link]`:
```xml
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.10</version>
</dependency>
</dependencies>
```
2. Place the `[Link]` file in the classpath, typically in the `src/main/resources` directory.
3. Run the `MainApp` class to see the student and movie details printed on the console.
```
Student{name='Alice', course='Computer Science', rollNumber=101}
Movie{title='Inception', genre='Science Fiction', duration=148 minutes}
```
This setup creates a Spring application that loads the context from an XML configuration file,
instantiates `Student` and `Movie` beans with sample values, and prints their details on the
console.
Experiment No. 10
Objective:. According to question 9, use annotations for the configuration, instead of the
xml. Also, add the init method, destroy method. Implement these methods with the logic
to show the current system date and time.
Program:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link]; import [Link];
@Component
@Autowired
public Student(@Value("${[Link]}")
String name, @Value("${[Link]}")
String course, @Value("${[Link]}")
int rollNumber()
{
[Link] = name;
[Link] = course;
[Link] = rollNumber;
}
}
@PostConstruct
public void init() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss"); String currentDateAndTime = [Link](new Date());
[Link]("Initialization method called. Current system date and time: " +
currentDateAndTime);
@PreDestroy
Experiment No. 11
Programs:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@SpringBootApplication
String[] beanNames =
[Link](); for
(String beanName : beanNames) {
[Link](beanName);
@RestController
class StudentController {
@Autowired
private Student student;
@Autowired
private Address address;
@GetMapping("/
student/name") public
String
getStudentName() {
return "Student Name: " + [Link]();
}
@GetMapping("/
student/address")
public String
getStudentAddress() {
return "Student Address: " + [Link]();
}
}
class Student {
private String name;
public String getName() { return name;
}
class Address {
private String address;
public String getAddress() {
return address;
}
Experiment No. 12
Objective:. Amit wants to start a payment service portal for making payments for the credit
card bill and online shopping. He will need a base class (MyPaymentServices) to store balance
and customer ID information. He will use two classes- CreditCardPayment and
ShoppingPayment for paying Credit card bills and shopping bills respectively. The bill
payment and id generation is different for both payment modes.
Class Description:
MyPaymentServices: This is the base class for CreditCardPayment and ShoppingPayment
classes. It will store the amount to be paid by the user in the instance variable balance of the
class.
MyPaymentService
-balance:double
-customerId:int
+MyPaymentService(balance:double, customerId:int)
+setBalance(balance:double):void
+getBalance():doublie
+getCustomerId():int
+payBill(amount:double):void
Method Description:
payBill(double amount): This is an abstract method that has to be implemented by the child
classes of MyPaymentServices.
ShoppingPayment:
This class is a child class of MyPaymentServices. It has a static variable counter, to set the
paymentID. The class diagram is shown below:
ShoppingPayment
- static counter: int
- pymentId:String
+ ShoppingPayment(balance:double, customerId:int)
+ getPaymentId(): String
+ payBill(amount: double): void
Method Description:
payBill(double amount): For a shopping bill payment, the payment id should start with 'S'
followed by a four digit integer number. If the user enters an amount not equal to the balance
which is due, an appropriate error message should be displayed and the id should get generated
only for valid payments.
CreditCardPayment:
This class is another child class of MyPaymentServices. It has a static variable counter,
to generate the paymentID. The class diagram is shown below:
CreditCardPayment
- static conter:int
- paymentId:String
- cashBack: double
- balanceDue: double
+ CreditCardPayment(balance:double, customerId:int)
+ getPaymentId(): String
+ getCashBack(): double
+ getBalanceDue(): double
+ payBill(amount:double):void
Method Description:
payBill(double amount): For credit card bill payment, if a user enters an amount more than the
amount to be paid, the excess amount should be stored as cashBack. The payBill method is used
to pay the bill and generate
the transaction id. The id should start with 'C' followed by a four-digit integer number. In case
the user enters an amount less than the amount to be paid, then the remaining amount should be
stored in the instance variable balanceDue of class CreditCardPayment.
Use a Tester class to test your code and display the payment information.
The balanceDue after the payment should be communicated to the user.
Some outputs with different inputs are given below for your reference. Input1 (For credit card)
Attributes Values
Balance 10000.56
Customer Id 5001
Paid Amount 15000.00
Output
Congratulations: You have successfully made a payment
of Rs. 15000 .Payment details are:-
Customer Id: 5001
Payment Id: 1001
Previous Due:
10000.56
Remaining Due: 0
Cash Back Wallet Balance: 4999.44
Attributes Values
Balance 10000.56
Customer Id 5001
Paid Amount 0
Output
Congratulations: You have successfully made a
payment of Rs. 0.0 .Payment details are:-
Customer Id: 5001
Payment Id: C1002
Previous Due: 10000.56
Remaining Due: 10000.56
Cash Back Wallet
Balance : 0.0
Attributes Values
Balance 10000.56
Customer Id 5001
Paid Amount 5000
Output:
Attributes Values
Balance 5000.56
Customer Id 561328
Paid Amount 5000.00
Output
Congratulations: You have successfully made a payment of Rs. 0.0 with Payment Id: s1001
Program:
@Override
public void payBill(double amount) { if (amount != getBalance()) {
[Link]("Error: Amount should be equal to the balance.");
return;
}
[Link]("Congratulations: You have successfully made a
payment of Rs. " + amount + ". Payment details are:-");
[Link]("Customer Id: " + getCustomerId());
[Link]("Payment Id: " + getPaymentId());
[Link]("Previous Due: " + getBalance());
setBalance(0); [Link]("Remaining Due: " + getBalance());
}
}
@Override
public void payBill(double amount) { if (amount > getBalance()) {