0% found this document useful (0 votes)
34 views

OOPs Programs-01

The document describes creating classes to model ticket booking, student records, bank account transactions, and a hostel management system. For ticket booking, it defines a Ticket class with fields for ID, price, and available tickets. It includes a method to calculate ticket cost by checking availability and returning the total or -1. For students, it creates a Student class with ID, name, address, and college fields. Constructors initialize values differently based on college. For bank accounts, an Account class is made with ID, type, and balance fields. A withdraw method deducts amount if sufficient balance, or returns error message. For hostels, a Student class holds base details and a Hosteller

Uploaded by

Saurabh Kaushik
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)
34 views

OOPs Programs-01

The document describes creating classes to model ticket booking, student records, bank account transactions, and a hostel management system. For ticket booking, it defines a Ticket class with fields for ID, price, and available tickets. It includes a method to calculate ticket cost by checking availability and returning the total or -1. For students, it creates a Student class with ID, name, address, and college fields. Constructors initialize values differently based on college. For bank accounts, an Account class is made with ID, type, and balance fields. A withdraw method deducts amount if sufficient balance, or returns error message. For hostels, a Student class holds base details and a Hosteller

Uploaded by

Saurabh Kaushik
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/ 9

1.

Ticket Price Calculation - Static


Ticket Calculation

Create a class Ticket with the following private variables


int ticketid;
int price;
static int availableTickets;

Include getters and setters methods in the Ticket class.

AvailableTickets should hold only positive value. Zero and negative


values are not allowed.(This logic should be checked inside the
corresponding setter method)

Write the following method in the Ticket class:

public int calculateTicketCost(int nooftickets) —this method should


check the ticket availability, If the tickets are available, reduce the
nooftickets from availableTickets and calculate the total amount as
nooftickets*price  and return the total amount.  If the tickets are not
available, this method should return -1.

Write a main method in the Main class to test the application.

Sample input and output

Enter no of bookings:
2
Enter the available tickets:
25
Enter the ticketid:
123
Enter the price:
100
Enter the no of tickets:
5
Available tickets: 25

Total amount:500

Available ticket after booking:20


Enter the ticketid:
124
Enter the price:
100
Enter the no of tickets:
2
Available tickets: 20

Total amount:200

Available ticket after booking:18

2. Create a class Student with the private attributes

int studentId

String studentName, studentAddress, collegeName. 

Include appropriate getter methods.

Write 2 constructors for the Student class based on the below


assumptions. 

Assume most of the students are from “NIT” college. So user has
to give input whether the student is from NIT or not. 

1. If student belongs to NIT, give input as 'yes/YES' and  skip


input for the attribute collegeName  and create student object
with 3-argument constructor to initilze the values for
studentId, studentName and studentAddress and
collegeName as “NIT”.
2. If student belongs to other college, give input as 'no/NO' and
get college name from the user and create student object with
4-argument constructor to initialize all the values. 
3. Instead of Yes / No, if user enters different input then display
'Wrong Input' and get the input again.

Based on the above assumptions write the necessary constructors


in the Student class.
Write a class StudentMain with the main method and test the
application. 

Get all the input needed from the main method. 

Sample Input 1:

Enter Student's Id:

12

Enter Student's Name:

John

Enter Student's address:

Chennai

Whether the student is from NIT(Yes/No):

NO

Enter the college name:

SVS

Sample Output 1:

Student id:12

Student name:John

Address:Chennai

College name:SVS

Sample Input 2:

Enter Student's Id:

43
Enter Student's Name:

Tom

Enter Student's address:

Coimbatore

Whether the student is from NIT(Yes/No):

Wrong Input

Whether the student is from NIT(Yes/No):

yes

Sample Output 2:

Student id:43

Student name:Tom

Address:Coimbatore

College name:NIT

3. In the first round of HR interview for a banking sector,  HR


decides to make candidates design an application which provides
only  information on transaction like amount withdrawn with
respect to fields given. Develop a program to implement this
scenario. 

Create a class Account with the private attributes: 

 accountId  int
 accountType String 
 balance int
The method public boolean withdraw(int) used  to calculate the
current balance of the respective account. Before that it should
enough balance.  If there is enough balance, deduct the amount
from the balance and print "Balance amount after withdraw: XXX"
and return true.  If there is no enough balance, print "Sorry!!! No
enough balance" and return false. 

Create a class AccountDetails with main function and the below


methods :

 public Account getAccountDetails() -  This methods gets the


input related to Account from the user and returns the
Account object with all values set.  If the input given for
balance is less than or equal to zero, consider it as invalid
and display "Balance should be positive". Continue this kind
of evaluation till user enters a positive value.

 public int getWithdrawAmount() -  This methods gets the


amount to be withdrawn as input from the user and returns
the same.  If the input given for amount is less than or equal
to zero, consider it as invalid and display "Amount should be
positive". Continue this kind of evaluation till user enters a
positive value.

Use appropriate getters and setters.

Sample input 1:

Enter account id:

100
Enter account type:

Savings

Enter balance:

10000
Enter amount to be withdrawn:

500
Sample Output 1:

Balance amount after withdraw: 9500

Sample input 2:
Enter account id:

101
Enter account type:

Savings
Enter balance:
1000
Enter amount to be withdrawn:
1500

Sample Output 2:

Sorry!!! No enough balance

Sample input 3:

Enter account id:

100

Enter account type:

Savings

Enter balance:

-100

Balance should be positive

Enter balance:

5000

Enter amount to be withdrawn:


500
Sample Output 1: SNMR College of Engineering and Technology
wants to create an application to store their students details as well
as the details of hostellers.

In case of any changes to be made to the attributes,  admin can


update the details like room number and phone number of the
hosteler.

Develop a program to implement this scenario.

Create a public class Student with  protected attributes :

int studentId

String name

int departmentId

String gender

String phone

Create a public class Hosteller with private attributes

String hostelName

int roomNumber

Make this class inherit the Student class, as it holds all the
properties of Student. 

Use appropriate public getters and setters for both the classes.

Write a class Main with the main function.

In Main class get the input of the hosteller using the method :

public static Hosteller getHostellerDetails().


Invoke this method from the main method and then modify the
room number and phone number, if needed.

Sample Input 1:

Enter the Details:


Student Id
1
Student Name
John
Department Id
101
Gender
Male
Phone Number
9876543210
Hostel Name
YMCA
Room Number
10
Modify Room Number(Y/N)
Y
New Room Number
11
Modify Phone Number(Y/N)
Y
New Phone Number
9876543121

Sample Output 1:

The Student Details


1 John 101 Male 9876543121 YMCA 11

Sample Input 2:
Enter the Details:
Student Id
2
Student Name
John Paul
Department Id
112
Gender
Male
Phone Number
9885526536
Hostel Name
YMBA
Room Number
5
Modify Room Number(Y/N)
N
Modify Phone Number(Y/N)
N

Sample Output 2:
The Student Details:
2 John Paul 112 Male 9885526536 YMBA 5

Balance amount after withdraw: 4500

4.

You might also like