Question

In: Computer Science

Create a new project for Constructor Injection. Create three classes, Address.java, Employee.java and Department.java with the...

Create a new project for Constructor Injection. Create three classes, Address.java, Employee.java and Department.java with the following fields :

Address.java

1) int houseNumber

2) String streetName

3) String zipCode

Department.java

int departmentId

String departmentName

Employee.java

1) String firstName

2) String lastName

3) String ssn;

4) Address address

5) Department department

Using Spring Constructor Injection inject Address and Department into the Employee class.

Solutions

Expert Solution

java code

import java.io.*;

class Address

{

int houseNumber;

String streetName;

String zipcode;

public String.toString()

{

return "streetname"+"zipcode";

}

public Integer.toString()

{ return "houseNumber";

}

}

class Department

{

String departmentName;

int departmentd;

public String.toString()

{

return "departmentName";

}

public Integer.toString()

{ return "departmentId";

}

}

class Employee

{

String firstname;

String ssn;

String lastname;

Address address=new Address();

Department department=new Department()

Employee(String t,int y,String f,String l,String m ,int a,string b,string c) //Constructor Injection

{

Address.streetName=b;

Address.zipcode=c;

Address.houseNumber=a

Department.departmentName=t;

Department.departmentId=y;

firstname=f;

ssn=m;

lastname=l;

}

}

void display()

{

System.out.println(address);

System.out.println(department);

System.out.println(firstname+""+lastname+""+ssn+""+Address.streetName+""+Address.zipcode+""+Address.houseNumber +""+Department.departmentName+""+Department.departmentId);

}

}class Emain

{

public static void main(String args[])

{Employee e=new Employee("computerSc",23,"Rahul","sharma","abc",56,"madis_street",3454);

e.display();

}

}


Related Solutions

Create a new project in BlueJ. Create two new classes in the project, with the following...
Create a new project in BlueJ. Create two new classes in the project, with the following specifications: Class name: Part Fields: id (int) description (String) price (double) onSale (boolean) 1 Constructor: takes parameters partId, partDescrip, and partPrice to initialize fields id, description, and price; sets onSale field to false. Methods: Write get-methods (getters) for all four fields. The getters should be named getId, getDescription, getPrice, and isOnSale.
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In my case the project would be called rghanbarPart1. Select the option to create a main method. Create a new class called Vehicle. In the Vehicle class write the code for: • Instance variables that store the vehicle’s make, model, colour, and fuel type • A default constructor, and a second constructor that initialises all the instance variables • Accessor (getters) and mutator (setters) methods...
FlashCards with Classes and Exception Handling – Project Project Overview Create at least 2 object classes...
FlashCards with Classes and Exception Handling – Project Project Overview Create at least 2 object classes (Session and Problems) and one driver class and ensure the user inputs cannot cause the system to fail by using exception handling. Overview from Project . Implement a Java program that creates math flashcards for elementary grade students. User will enter his/her name, the type (+,-, *, /), the range of the factors to be used in the problems, and the number of problems...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
in java language. There are three classes for the project, and two inner classes defined in...
in java language. There are three classes for the project, and two inner classes defined in the Cuboid class. Create the following classes: •   Shape. It’s an abstract class with two abstract methods, area and perimeter. •   Rectangle. It’s a concrete class that extends Shape. Implement area() and perimeter(). Implement the compareTo(object) method to sort rectangles by area in ascending order. •   Cuboid. It’s a concrete class that extends Rectangle. A cuboid is a 3D rectangle. The shape has a...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This project will be used to calculate the area of certain figures, like circles, squares and rectangles. So add a title to the Form. The Form Title should say “Area”. Also add 3 labels, 3 Buttons, 3 Textboxes and 3 RadioButtons. The 3 Buttons should be near the bottom of the Form and say “Calc Area”, “Clear” and “Exit”. Make sure to give all your...
C++ Project 1 For this project, we are going to create our own classes and use...
C++ Project 1 For this project, we are going to create our own classes and use them to build objects. For each class you will create an *.h and *.cpp file that contains the class definition and the member functions. There will also be one file called 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them. You will create 2 new classes for this project, one will be from the list below and one...
in java Create a class called Customer in three steps: • (Step-1): • Add a constructor...
in java Create a class called Customer in three steps: • (Step-1): • Add a constructor of the class Customer that takes the name and purchase amount of the customer as inputs. • Write getter methods getName and getPrice to return the name and price of the customer. You can write a toString() method which returns printed string of Customer name and its purchase. • (Step-2): Create a class called Restaurant. • Write a method addsale that takes customer name...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT