0% found this document useful (0 votes)
131 views28 pages

PBL Report On Java

The document describes an application to be created for allowing debit card and credit card payments. It provides class diagrams and descriptions for Payment, DebitCardPayment and CreditCardPayment classes. The methods calculate service tax, discount and final bill amount for a payment.

Uploaded by

22eg105q15
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)
131 views28 pages

PBL Report On Java

The document describes an application to be created for allowing debit card and credit card payments. It provides class diagrams and descriptions for Payment, DebitCardPayment and CreditCardPayment classes. The methods calculate service tax, discount and final bill amount for a payment.

Uploaded by

22eg105q15
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/ 28

PBL REPORT ON JAVA

KOUDAGANI SANJANA
22EG105Q15

By faculty
Dr.G.Prabhakar Raju
PROBLEM-09

Happy Mobiles is a mobile manufacturer and they want to


increase the rate of production. So, they have decided to add a
feature for easily testing the compatibility of mobile operating

system with generation of cellular network. You need to help


them by creating an application based on the class diagram
and description given below.
Method Description Mobile Mobile(String name, String brand,
String operatingSystemName, String operatingSystemVersion)
• Initialize all the instance variables with the values passed to
the constructor
Implement the getter and setter methods appropriately.

SmartPhone(String name, String brand, String


operatingSystemName, String operatingSystemVersion, String
networkGeneration)
• Initialize all the instance variables with the values passed to
the constructor testCompatibility()

• Check the compatibility of mobile operating system with


network generation based on the table given below.
Return true if compatible, else return false

mplement the getter and setter methods appropriately.


Perform case sensitive comparison wherever applicable.
Test the functionalities using the provided Tester class.

Sample Input and Output Input


OUTPUT

Input

Output

CODE SOLUTION
import java.util.*; class Mobile
{ private String name; private String
brand; private String
operatingSystemName; private String
operatingSystemVersion;

public Mobile(String name, String brand, String


operatingSystemName, String operatingSystemVersion) {
this.name = name; this.brand = brand;
this.operatingSystemName = operatingSystemName;
this.operatingSystemVersion = operatingSystemVersion;
}
public String getName()
{ return name;
}
public void setName(String name)
{ this.name = name;
}
public String getBrand()
{ return brand;
}
public void setBrand(String brand)
{ this.brand = brand;

}
public String getOperatingSystemName()
{ return operatingSystemName;
}
public void setOperatingSystemName(String
operatingSystemName) { this.operatingSystemName =
operatingSystemName;
}
public String getOperatingSystemVersion()
{ return operatingSystemVersion;
}
public void setOperatingSystemVersion(String
operatingSystemVersion) { this.operatingSystemVersion =
operatingSystemVersion;
}
@Override public
String toString()
{ return "Mobile{" +
"name='" + name + '\'' +
", brand='" + brand + '\'' +
", operatingSystemName='" + operatingSystemName +
'\'' +
", operatingSystemVersion='" + operatingSystemVersion
+ '\'' +
'}';
}
}
class SmartPhone extends Mobile
{ private String networkGeneration;

public SmartPhone(String name, String brand,


String operatingSystemName, String operatingSystemVersion,
String networkGeneration) {
super(name, brand, operatingSystemName,
operatingSystemVersion); this.networkGeneration =
networkGeneration;
}
public String getNetworkGeneration()
{ return networkGeneration;
}
public void setNetworkGeneration(String networkGeneration) {
this.networkGeneration = networkGeneration;
}
public boolean testCompatibility() {
Map<String, List<String>> compatibilityTable = new
HashMap<>(); compatibilityTable.put("saturn3G",
Arrays.asList("1.1",
"1.2", "1.3")); compatibilityTable.put("saturn4G",

Arrays.asList("1.2",

"1.3"));
compatibilityTable.put("saturn5G",
Collections.singletonList("1.3"));
compatibilityTable.put("Gara3G", Arrays.asList("EXRT.1",
"EXRT.2", "EXRU.1"));
compatibilityTable.put("Gara4G", Arrays.asList("EXRT.2",
"EXRU.1"));
compatibilityTable.put("Gara5G",
Collections.singletonList("EXRU.1"));
String key = getOperatingSystemName() +
getNetworkGeneration();
List<String> supportedVersions =
compatibilityTable.getOrDefault(key, new ArrayList<>());
return
supportedVersions.contains(getOperatingSystemVersion());
}
@Override public
String toString() {
return "SmartPhone{" +
"name='" + getName() + '\'' +
", brand='" + getBrand() + '\'' +
", operatingSystemName='" +
getOperatingSystemName() + '\'' +
", operatingSystemVersion='" +
getOperatingSystemVersion() + '\'' +
", networkGeneration='" + networkGeneration + '\'' +
'}';
}
}

public class MobileDemo { public


static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter name: ");
String name = scanner.nextLine();
System.out.print("Enter brand: ");
String brand = scanner.nextLine();
System.out.print("Enter operatingSystemName: ");
String operatingSystemName = scanner.nextLine();
System.out.print("Enter operatingSystemVersion: ");
String operatingSystemVersion = scanner.nextLine();
System.out.print("Enter networkGeneration: ");
String networkGeneration = scanner.nextLine();
SmartPhone phone = new SmartPhone(name, brand,
operatingSystemName, operatingSystemVersion,
networkGeneration);
if (phone.testCompatibility()) {
System.out.println("The mobile OS is compatible with the
network generation!");
} else {
System.out.println("The mobile OS is not compatible with
the network generation!");
}
scanner.close();
}
}

PROBLEM-08
An educational institution provides stipends for post-graduate
students every year. For calculating the stipend, the institution
has fixed a base amount of $100 which is provided to all the
students. The students who perform exceptionally well during
the academics get an extra amount based on their
performance.
You need to help the institution in developing an application
for calculating the stipend by implementing the class based on
the class diagram and description given below.

Method Description calculateTotalStipend()


Calculate and return the total stipend amount based on the
aggregate marks of the student using the below table.

Note: STIPEND is a final variable.


Implement the getter and setter methods appropriately.
Test the functionalities using the provided Tester class.
Sample Input and Output
Input
Output

Input

Output

CODE SOLUTION
import java.util.Scanner; class Student { private int
studentId; private double aggregateMarks; private final
double STIPEND = 100.0; public Student(int studentId,
double aggregateMarks) { this.studentId
= studentId; this.aggregateMarks = aggregateMarks;
}
public int getStudentId() { return
studentId;
}
public void setStudentId(int studentId) { this.studentId
= studentId;
}
public double getAggregateMarks()
{ return aggregateMarks;
}
public void setAggregateMarks(double aggregateMarks)
{ this.aggregateMarks = aggregateMarks;

}
public double calculateTotalStipend() { double
totalStipend = STIPEND;
if (aggregateMarks >= 85 && aggregateMarks < 90) {
totalStipend += 10.0;
} else if (aggregateMarks >= 90 && aggregateMarks < 95) {
totalStipend += 15.0;
} else if (aggregateMarks >= 95 && aggregateMarks <= 100) {
totalStipend += 20.0;
}
return totalStipend;
}
}
public class StudentDemo { public static
void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter student ID: "); int studentId
= scanner.nextInt();
System.out.print("Enter aggregate marks: "); double
aggregateMarks = scanner.nextDouble();
Student student = new Student(studentId, aggregateMarks);
double totalStipend = student.calculateTotalStipend();

System.out.println("The final stipend of " +


student.getStudentId() + " is $" + totalStipend); scanner.close();
}
}
PROBLEM-07
An e-commerce company wants to start a payment service application
for allowing payments using debit card and credit card. You need to
help them in creating the application by implementing the classes
based on the class diagram and description given below.
Method Description
Payment
Payment(int customerId)
Initialize the customerId instance variable with the value passed to the
constructor

Implement the getter and setter methods appropriately.


DebitCardPayment
DebitCardPayment(int customerId)
Initialize the customerId instance variable with the value passed to the
constructor.
Generate the paymentId using the static variable counter. The value of
paymentId should start from 'D1000' and the numerical part should be
incremented by 1 for the subsequent values. Initialize the counter in
static block.
payBill(double amount)
Initialize the serviceTaxPercentage instance variable based on the
details given below and calculate the service tax amount.

Initialize the discountPercentage instance variable based on the details


given below and calculate the discount amount.
Calculate and return the final bill amount.

Implement the getter and setter methods appropriately.

CreditCardPayment
CreditCardPayment(int customerId)
Initialize the customerId instance variable with the value passed to the
constructor.
Generate the paymentId using the static variable counter. The value of
paymentId should start from 'C1000' and the numerical part should be
incremented by 1 for the subsequent values. Initialize the counter in
static block.
payBill(double amount)
Initialize the serviceTaxPercentage instance variable based on the
details given below and calculate the service tax amount.
Calculate and return the final bill amount.
Implement the getter and setter methods appropriately.
Test the functionalities using the provided Tester class.
Sample Input and Output
Input
DebitCardPayment object

payBill parameters

Output

payBill parameters

Output
CODE SOLUTION
import java.util.Scanner; class
Payment { private int
customerId; public Payment(int
customerId) { this.customerId
= customerId;
}
public int getCustomerId()
{ return customerId;
}
public void setCustomerId(int customerId)
{ this.customerId = customerId;
}
}
class DebitCardPayment extends Payment {
private static int counter = 1000;
private String paymentId; private
double serviceTaxPercentage; private
double discountPercentage;
static {
counter = 1000;
}
public DebitCardPayment(int customerId)

{ super(customerId); paymentId =

"D" + counter++; } public double

payBill(double amount) {

if (amount <= 500)


{ serviceTaxPercentage = 2.5;
discountPercentage = 1.0;
} else if (amount > 500 && amount <= 1000)
{ serviceTaxPercentage = 4.0; discountPercentage
= 2.0;
} else {
serviceTaxPercentage = 5.0;
discountPercentage = 3.0;
}
double serviceTaxAmount = (amount * serviceTaxPercentage)
/ 100;
double discountAmount = (amount * discountPercentage) /
100;
double totalBillAmount = amount + serviceTaxAmount -
discountAmount; return totalBillAmount;
}
public String getPaymentId()
{ return paymentId;
}
public double getServiceTaxPercentage()
{ return serviceTaxPercentage;
}
public double getDiscountPercentage()
{ return discountPercentage;
}
}
public class CustomerDemo { public
static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter customer ID: "); int
customerId = scanner.nextInt();
System.out.print("Enter bill amount: $"); double
amount = scanner.nextDouble();
DebitCardPayment debitCardPayment = new
DebitCardPayment(customerId); double totalBill =
debitCardPayment.payBill(amount);
System.out.println("Customer ID: " +
debitCardPayment.getCustomerId());
System.out.println("Payment ID: " +
debitCardPayment.getPaymentId());
System.out.println("Service tax Percentage: " +
debitCardPayment.getServiceTaxPercentage());
System.out.println("Discount Percentage: " +
debitCardPayment.getDiscountPercentage());
System.out.println("Total bill amount: $" + totalBill);
scanner.close();
}
}
PROBLEM-4
Rainbow Cinemas is an upcoming multiplex in the city with a
seating capacity of 400 people. They need an application to be
developed for booking of tickets.
You need to implement a Booking class based on the class
diagram and description given below.

Method Description Booking(String customerEmail, int


seatsRequired)
Initialize the customerEmail and seatsRequired instance
variable appropriately with the values passed to the constructor.
If the required number of seats are available, set the value of
isBooked to true and update the value of seatsAvailable
accordingly. The total number of seats available is 400 and
should be initialized in static block.
If the required number of seats are not available, set the value
of isBooked to false.
Implement the appropriate getter and setter methods.
Test the functionalities using the provided Tester class. Create
two or more Booking objects and validate that the values of the
member variables are proper.

Sample Input and Output For constructor Input For first Booking
object

For second Booking object

Output

CODE SOLUTION
import java.util.Scanner; class
Booking {
private String customerEmail;
private int seatsRequired; private static
int seatsAvailable; private boolean
isBooked;
static {
seatsAvailable = 400;
}
public Booking(String customerEmail, int seatsRequired)
{ this.customerEmail = customerEmail; this.seatsRequired
= seatsRequired; this.isBooked = false;
if (seatsRequired <= seatsAvailable) {
isBooked = true; seatsAvailable -=
seatsRequired;
System.out.println(seatsRequired + " seats successfully booked
for " + customerEmail);
} else {
System.out.println("Sorry " + customerEmail + ", required
number of seats are not available!");
System.out.println("Seats available are: " + seatsAvailable);
}
}
public String getCustomerEmail()
{ return customerEmail;

}
public void setCustomerEmail(String customerEmail)
{ this.customerEmail = customerEmail;
}
public int getSeatsRequired()
{ return seatsRequired;
}
public void setSeatsRequired(int seatsRequired)
{ this.seatsRequired = seatsRequired;
}
public boolean isBooked()
{ return isBooked;
}
public static int getSeatsAvailable()
{ return seatsAvailable;
}
public static void setSeatsAvailable(int seatsAvailable) {
Booking.seatsAvailable = seatsAvailable;
}
}
public class BookingDemo { public
static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter customer email for the first booking:");
String email1 = scanner.nextLine();
System.out.println("Enter number of seats required for the
first booking:"); int seats1 = scanner.nextInt();
scanner.nextLine();
Booking booking1 = new Booking(email1, seats1);
System.out.println("\nEnter customer email for the second
booking:");
String email2 = scanner.nextLine();
System.out.println("Enter number of seats required for the second
booking:"); int seats2 = scanner.nextInt();
scanner.nextLine();
Booking booking2 = new Booking(email2, seats2);
scanner.close();
}
}

You might also like