Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

LabExercises

The document outlines a series of Java programming tasks, including creating classes for currency conversion, customer and employee representation, mobile billing, book discount calculations, bank account management, and invoice handling. It also includes tasks for implementing interfaces, exception handling, and database operations, as well as Spring Boot project creation and service implementations. Each task is designed to reinforce object-oriented programming concepts and practical application development in Java.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

LabExercises

The document outlines a series of Java programming tasks, including creating classes for currency conversion, customer and employee representation, mobile billing, book discount calculations, bank account management, and invoice handling. It also includes tasks for implementing interfaces, exception handling, and database operations, as well as Spring Boot project creation and service implementations. Each task is designed to reinforce object-oriented programming concepts and practical application development in Java.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Task - 1

Create a Java Class Currency Converter with a method usDollorToInr(double


dlrAmount)
Add the logic for conversion
Create a Java Class Application with main method and Test Current Converter
dollorToInr method

Task-2

Create Java classes to represent a Customer , Employee, Hotel in separate packages

Add the Consturctors, setter/getter methods and Check its working properly using
the Main Method

Task -3

Create a Java Class EmployeeService add a Method public double


calculateBonus(Employee object)
Calculate the bonus as the 33% of the monthly salary.

Task -4

1 Create a Java Class MobileBill


2 Add attributes like String customerName, long mobilenumber ,String planname
and Address address
3 Create overloaded constructor zero and parametrized
4 Define one Constant(public static final) in the class
5. Create a Method findAmount and Use switch case to calculate the amount based on
the planName
If its prepaid amount is 200 and postpaid its 300
6. Test the Methods by Calling from the main Method

Task -5

1. Create Java Class Book with details like int id, String bookName, String
author, double price.
2. Create a Java Class BookService Which will have overloaded methods to
calculate the discount .
3. One Method will take book Object as argument and calculate the discount on
the basis of price
a. use a simple if else ladder if Price < 500 5 % discount if price >500 and
price <1000 10 % and if price>1000 12%
4. Another Method will take book and customer type -> Corporate or Retail and
the discount will be calculated using both switch case(Using String-Java 7
feature)
and if else-if ladder
a. For Corporate Customer if Price < 500 7 % discount if price >500 and
price <1000 12 % and if price>1000 15%
b. For Retial Customer if Price < 500 5 % discount if price >500 and price
<1000 10 % and if price>1000 12%
5. Take the input for the application in the main method using scanner class
6. Try Invoking Both the Methods from the Main Method

Task-6
1. Create a Abstract Class Class Bank Account with two abstract methods double
deposit(double amount) , double withdraw(double amount)
2. Create two sub classes SavingsAccount and Business Account override deposit
and withdraw methods
3. SavingsAccount Holders are required to maintain a minimum balance of 5000
4. Business Account Holders are required to maintain a minimum balance of 25000
5. Saving Account holder can deposit upto 100000
6. Business Account Holder can deposit upto 1000000

Show a error message if the above condition is not met

Test both deposit and withdraw methods from the Main application

Task -7

1. Create an Interface Billable - with a method public double calculate(Object[]


objects).
2. Calculate method will calculate the salary based on some condition which
will differ for different classes
3. Create classes like SoftwareEnginner , CivilEnginner, Plumber ,Advocate etc.,
4. Implement the Billable interface in all these classes and override the
calculate method
5. Create a Service with One Method which take Billable as argument and print the
calculated amount

Task -8

Create a Java Class EmployeeService with a method double


calculateTotalSalary(Employee[] empList)
The Method should return the total salary of all the employees
If the size of the empList is less than 2 or greater than 5 throw the Custom
Execpetion RangeCheckException.
Test the code from the main method .

Task -9

1 Create a Java Class InvalidEmailException by extending Exception Class


2 Override the getMessage method
3 Create a Class Customer with properties like
customerId,customerName ,phoneNumber and email.
4 If the email doesnot contain the character "@" or ".com" or ".org" or ".in"
throw InvalidEmailException with suitable message
5.Use the String class method no need to use regurlar expressions
6. Check the email both in the constructor and setEmail method
7. Create a Logger and Add the log message to the console and to a file

Task -10

1. Create a Java Class called Doctor props(id,name,specialization,location)


2. Doctor has a Set of Patients props(id,parientName,address,email)
3. Doctor also has a list of Staff Members represented by a Map the key being
String which represents the designation and value being Staff represented
by a Java class Staff (can decided by developers)
4. Given a DoctorName application should return list of Patient
5. Given a DoctorName application should return list of Staff Memebers
6. Use a Interface Based design with a Service Class and Main method
Task -11

Create a Java Class Invoice with following fields


private int invoiceNumber;
private String customerName;
private double quantity;
private double ratePerUnit;
private LocalDate invoiceDate;
Create Service InvoiceService with a method public static List<Invoice>
getInvoice(){} which return a list of Invoices
Create the following utility methods and test the application

public static List<Invoice> sortedByRatePerUnitAsc(Collection<Invoice>


invList){}
public Map<String,Double> mapViewOfList(Collection<Invoice> invList) {}
public Set<Invoice> setViewOfList(Collection<Invoice> invList,
Predicate<Invoice> predicate){}
public long findMaxInvoiceValue(Collection<Invoice> invList,Comparator comp) {}

Task -11

1. Create a Java Class called Doctor props(id,name,specialization,location)


2. Store the Details of the Doctors in a plain text file
3. Read the doctors details from the text file and store into a collection
4. Create a Method which take the specialization as arguemnt and returns the
List of doctors with that specialization
5. Create a Method which takes the location as argument and returns the List
of doctors in that location
6. Create a Method which takes the location and specialization and return the
list of the doctors with that specialization and location

Task -12

The personal details of all employees are stored in a Database


It’s required to create an application that can fulfil the requirements to store
and view the details of employees:

The following are the requirements


1. The Database should have following details stored
• FirstName
• Last Name
• Address
• Email address
• Phone number
• Birthday
• Wedding Anniversary
2. Should be able to add employee details
3. Should be able retrieve information already stored by entering employees
firstName.
4. Should be able edit the details of a particular employee.
5. Should be able to get the list of employees with their firstName and email_id
whose Birthday falls on the given date
6. Should be able to get the list of employee with their firstName and phone
Number whose Wedding Anniversary falls on the given date
7. Should be to get the details of FirstName and Phone Number of all the
employees
===================================================================================
=====================

Task -13

Create a Spring Boot Strater Project and practice the following

1. Create a Spring Boot Starter Project


2. Create a Java Bean Customer with the following fields

public class Customer {

int customerId;
String customerName;
long mobileNumber;
String email;

3. Create a Java Bean Invoice with the following fields

public class Invoice{

int invoiceNumber;
Customer customer;
double amount

4. Create a Java Class with the Annotation @Configuration and register the Customer
and
Invoice bean using the Factory Method with @Bean annotation

5. Test the application by accessing the Customer and invoice beans from the main
method

6. Create More than one Customer and observer the output , if there are any
exection thrown
make the suitable changes

Task -14

Create a Java class SalesOrder with properties ( int orderId, LocalDate


createdDate,Customer customer, List<Item> itemList)
Create a Customer Class with properties ( int id, String customerName, String
address)
Create a Item class with (long itemNumber, String itemName,double quantity ,double
ratePerUnit)
Create a Configuration Class and Register the Item Beans Using @Bean annotation
Register the SalesOrder class with @Component Annotation
Use @AutoWire on the SalesOrder class constructor and wire the propertiers
Create a Java Class OrderService which has the SalesOrder and a method public
double findTotal() which return total of the orderDetails

Try Practising => @Configuration,@Bean,@Component and @AutoWire and @Qualifier


Try Using the alias name for the bean
Task -15
interface Automobile
getColor
getModel
getPrice

public class MarutiCar implements Automobile

public class ToyotaCar implements Automobile

public class ObjectFactory

public Automobile getObject(int key){}

public void printQuote(Automobile poly){}

public class Application


main
getObject()
printQuote()

Task -16

1) Create a Maven Project credit-card-service


2) Create a Class CreditCard with properties like
cardNumber,cardHolderName,amountDue
3) Create a class CreditCardService with two methods
public boolean addCard(CreditCard card) public CreditCard[] getCards()
4) The Add Card method should store the card details in an Array
5) getCard Method will return the Array
6) Test the Code From the Main Method
7) From the Main Iterate through the array and Print total total amount Due

QUIZ LINKS

1. 10th Dec 2021 https://app.sli.do/event/qwTga7bMpsbz2t8DJ7YHye


2. 14th Dec 2021 https://app.sli.do/event/6p1VVLsb8wUTorm4V79JVc
3. 15th Dec 2021 https://app.sli.do/event/h9ykurdAtRHz3dm72NWVwH
4. 21st Dec 2021 https://app.sli.do/event/jPSZWpxsqfqbhpiLsADTfk
5. 22nd Dec 2021 https://app.sli.do/event/tZCRMVTC31Z6goLmKYpSU5

You might also like