0% found this document useful (0 votes)
25 views2 pages

Java Annotation-Based Payment Processing

Uploaded by

Army
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)
25 views2 pages

Java Annotation-Based Payment Processing

Uploaded by

Army
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

Assignment-5

Base on Java Annotation

1. Create an interface ‘PaymentProcessor’ with a method String


processPayment(double amount,String currency). Create 3 classes
named creditCardProcessor, payPalProcessor,and
BankTransferProcessor each implementing the PaymentProcessor
interface. In each class, override the processPayment method to return a
string that includes the type of paymentprocessor([Link] crd),the
amount, and currency. Create a class named PaymentService that contains
a dependency on the PaymentProcessor interface and a method void
makePayment(double amount, String currency) that calls the
processPayment method. The method should print a message
“processing creditcard payment of 100.0USD.
Use setter method to add dependencies. Use annotation based
configuration and create different beans to populate PaymentProcessor
with the creditCardProcessor, PayPalProcessor, and
BankTransferProcessor [Link] a Run class of Spring application
to execute the application.
2. Write a java program to create a class Book with private data members
such as bookName, authorName,and edition. Use setter and getter, and
display method. Create a annotation based configuration and display book
detail in the main class of Spring Application.
3. Create class named as Student which contain a method
printMessage(String name) and it returns Hello yourname. Create a bean
object of this class and call the method printMessage in the main class of
Springboot Application by using following ways
a. By implementing CommandLineRunner interface method.
b. Without implementing commandLineRunner.(use separate
configuration class)
4. Create a constructor called MyClass which consists of following
attributes
Name, regdNo, subjectName and markSecured. Write a display() method
which displays above details.
Create 2 bean object of the constructor for two students and call the
display method in the main class of Springboot Application by using
both ways of 3.a and 3.b.
5. Create a package of 4 classes named as address, Teacher, app,
javaConfig.
Address has fields as houseNo, city, postOffice, pin, state. Use setter
method for the given fields and toString method to print string
representation of the object.
Teacher class has name, id, mobileNo, and address fields. Use the setter
method and toString method for this class. javaConfig class is java
annotation-based configuration file which creates two address beans and
on teacher bean and initialize the fields of both classes. In teacher class
use any one address by using @Qualifier annotation.
Call the teacher object in app class which consists of main method of
Spring application.
6. Create a customer class which consists of customerName, accountNo,
IFSCCode, use setter method and override the toString Method.
Create a configuration class(annotation based) named as conFig. Use
configuration and componntscan Annotatuion and create a bean for
customer class and initialize the field by calling setter method of
customer class. Display details of customer in the app/run class which
consists of main method of SpringApplication.
7. Create a class named as Book having fields title, price, pDate(reference
of class pubDate) and override the toString Method. Use
@value ,@Autowire @Component and @override annotation in
appropriate position. The class pubDate consists of filed day, month, and
year. Use @value to give value of each field and write toString method.
Display book details in the main method of [Link] of Spring
Application.
8. Create a class and use appropriate annotation to display your name in
browser when user [Link]/home.

Common questions

Powered by AI

Annotation-based autowiring reduces the verbosity of configuration files, simplifies the binding of beans, and improves code readability by allowing autowiring directly in the class source, all of which streamline the development process compared to the more cumbersome XML files .

Using interfaces like PaymentProcessor encourages decoupling of implementations, which allows for easy extension and swapping of modules. It supports the open/closed principle, where new processors can be added without modifying existing code, promoting scalability .

Using a separate class like pubDate for date attributes promotes encapsulation and reusability. It organizes related data into a single coherent unit, which simplifies management and potential reusability across different parts of the application .

@Qualifier provides a way to specify which bean should be autowired when multiple beans of the same type exist, avoiding ambiguity by explicitly indicating the desired bean to use, thereby ensuring the correct dependency is injected .

Annotation-based configuration streamlines dependency management by allowing developers to define dependencies via annotations, which reduces boilerplate code and enhances readability. It enables the automatic wiring of beans using annotations like @Autowired, making applications easier to configure and maintain .

Implementing CommandLineRunner allows one to execute a block of code at startup before the application is fully operational. It provides an opportunity to initialize data or execute tasks that should be performed at application startup .

A Spring Boot application can display a static name using a Controller class annotated with @Controller. A method, mapped with @RequestMapping("/home"), should return a plain string or a model pointing to a view page that displays the name .

@Value is used to inject property values into beans, @Component marks a class as a Spring component for auto-detection, and @Autowired automatically injects required dependencies, reducing manual wiring effort .

The toString method provides a string representation of an object, which is particularly useful for logging and debugging, making it easier to understand an object's state without needing to inspect each attribute individually .

Setter methods provide a means to inject dependencies in Spring beans, allowing for the flexibility of configuration during runtime. By using setter methods, one can easily swap or modify the dependencies, such as switching between creditCardProcessor, PayPalProcessor, and BankTransferProcessor .

You might also like