PBL Report On Java
PBL Report On Java
KOUDAGANI SANJANA
22EG105Q15
By faculty
Dr.G.Prabhakar Raju
PROBLEM-09
Input
Output
CODE SOLUTION
import java.util.*; class Mobile
{ private String name; private String
brand; private String
operatingSystemName; private String
operatingSystemVersion;
}
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;
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 + '\'' +
'}';
}
}
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.
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();
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 =
payBill(double amount) {
Sample Input and Output For constructor Input For first 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();
}
}