Constructor Injection
custId | int |
custName | String |
emailId | String |
contactNo | long |
membershipId | int |
membershipType | String |
visitsPerYear | int |
customer | Customer |
Attributes should be private.
Customer has to set to the membership via constructor injection in the XML file.
Create a class called Driver with the main method and write the logic to get input from the user such as the customer details, membership details and display the details to verify the correctness of your code. (Note: UI will not be tested).
Design Constraints
Customer class and the MemberShip class should be present in com.spring.app package.
Write appropriate getters and setters and constructors
The className/Attribute Name/PackageName should be same as specified in the problem statement. Do not create any new packages.
The Customer bean in the applicationContext.xml should have id value as "custObj"
CODE SOLUTION IN JAVA
pom.xml
Customer.java
package com.spring.app; | |
public class Customer { | |
private int custId; | |
private String custName; | |
private String emailId; | |
private long contactNo; | |
public Customer(int custId, String custName, String emailId, long contactNo) { | |
super(); | |
this.custId = custId; | |
this.custName = custName; | |
this.emailId = emailId; | |
this.contactNo = contactNo; | |
} | |
public int getCustId() { | |
return custId; | |
} | |
public void setCustId(int custId) { | |
this.custId = custId; | |
} | |
public String getCustName() { | |
return custName; | |
} | |
public void setCustName(String custName) { | |
this.custName = custName; | |
} | |
public String getEmailId() { | |
return emailId; | |
} | |
public void setEmailId(String emailId) { | |
this.emailId = emailId; | |
} | |
public long getContactNo() { | |
return contactNo; | |
} | |
public void setContactNo(long contactNo) { | |
this.contactNo = contactNo; | |
} | |
} |
Driver.java
package com.spring.app; | |
import java.util.*; | |
public class Driver { | |
public static void main(String[] args) { | |
} | |
} |
MemberShip.java
package com.spring.app;
public class MemberShip { private int membershipId; private String membershipType; private int visitsPerYear; private Customer customer;
public MemberShip(int membershipId, String membershipType,
int visitsPerYear, Customer customer) { super(); this.membershipId = membershipId; this.membershipType = membershipType; this.visitsPerYear = visitsPerYear; this.customer = customer; }
public int getMembershipId() { return membershipId; }
public void setMembershipId(int membershipId) { this.membershipId = membershipId; }
public String getMembershipType() { return membershipType; }
public void setMembershipType(String membershipType) { this.membershipType = membershipType; }
public int getVisitsPerYear() { return visitsPerYear; }
public void setVisitsPerYear(int visitsPerYear) { this.visitsPerYear = visitsPerYear; }
public Customer getCustomer() { return customer; }
public void setCustomer(Customer customer) { this.customer = customer; } }
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<bean id="custObj" class="com.spring.app.Customer">
| ||||||
0 Comments