Professional Documents
Culture Documents
Disable external file upload, paste and drop external content: Yes
Run: Yes Evaluate: Yes
Automatic grade: Yes Maximum execution time: 240 s Maximum memory used: 1.50
GiB Maximum execution file size: 128 MiB Maximum number of processes: 10000
GO-GO Parcel Service – Courier Charge Calculation
GO-GO Parcel Service is one of the most widely used courier services in Tamilnadu. They are in
need of a system, which can be configured easily, to adapt to the changes they bring in with the
charges for the parcel in kilograms and need to calculate the courier charge for the customers.
You being their software consultant has been approached by them to develop a software system
which can be used for managing their business.
courierId int
weight int
serviceCharge ServiceChargeInfo
chargePerKg float
Getter and setter methods for all the above attributes has been provided as a part of code
skeleton. Courier class should be registered as a bean with the spring container via XML file.
locationServiceCharge Map<String,Float>
Getter and setter methods for the above attribute has been provided as a part of code skeleton.
The Map should be configured in the beans.xml file with the below key-values.
Overview of Service 1:
If the city is not available in the map then calculation should be as follows,
Technical Specifications:
Create a class called Driver with the main method and get the inputs like courierId, weight of the
parcel and city name from the user. Get the CourierService class object from the beans.xml file
and invoke the calculateCourierCharge(courierId,weight,city) which is in
the CourierService class to perform the implementation. Display the total Courier charge which
is returned from calculateCourierCharge method in CourierBO class.
Business Rules & Validations:
In CourierService class includes the following private attribute and inject via setter based
injection.
Getter and setter methods for the above attribute has been provided as a part of code skeleton.
12. charges.properties file will be provided with the value for charge per Kg, fetch and assign
values for chargePerKg attribute in Courier class via setter based injection. To read this property
file use <context:property-placeholder location="classpath:charges.properties" /> in beans.xml
file.
101
20
103
10
Bangalore // City name available in Map hence Service charge is not Applicable
210
Bangalore
Invalid Parcel Weight
Automatic evaluation[-]
Proposed grade: 100.0 / 100
Result Description
[+]Grading and Feedback
GoGoParcelService/pom.xml
1 // CourierBO
2
3 package com.spring.bo;
4
5 import com.spring.model.Courier; //importing the packages and subpackages required
6 import java.util.Map;
7 public class CourierBO {
8
9 public double calculateCourierCharge(Courier cObj,String city) {
10
11 double courierCharge=0.0;
12 //fill the code
13 courierCharge = cObj.getWeight() * cObj.getChargePerKg();
14 Map<String,Float> data = cObj.getServiceCharge().getLocationServiceCharge();
15 if(data.containsKey(city)){
16 courierCharge += data.get(city); //setting as counter
17 }
18
19 return courierCharge;
20 }
21
22 }
23
24
GoGoParcelService/src/main/java/com/spring/exception/InvalidParcelWei
ghtException.java
1 //Invalid
2 package com.spring.exception;
3
4 public class InvalidParcelWeightException extends Exception {
5
6 public InvalidParcelWeightException(String msg) {
7 super(msg); //argumentizing the string to superclass
8 //fill the code
9 }
10
11 }
GoGoParcelService/src/main/java/com/spring/main/Driver.java
1 //Driver
2 package com.spring.main;
3
4 import com.spring.exception.InvalidParcelWeightException; //importing packages and subpackages
required
5 import com.spring.service.CourierService;
6 import org.springframework.context.ApplicationContext;
7 import org.springframework.context.support.ClassPathXmlApplicationContext;
8 import java.util.Scanner;
9 public class Driver {
10
11 public static void main(String[] args) {
12
13 //fill the code
14
15 Scanner sc=new Scanner(System.in);
16 System.out.println("Enter the courier ID:");
17 int courierId = Integer.parseInt(sc.nextLine());
18 System.out.println("Enter the total weight of parcel:");
19 int weight = Integer.parseInt(sc.nextLine());
20 System.out.println("Enter the city:");
21 String city = sc.nextLine();
22
23 ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml");
24 CourierService courierService=(CourierService)context.getBean("courierService");
25 //catching the unexpected exceptions using try catch block
26 try{
27 System.out.println("Total Courier Charge: " +
courierService.calculateCourierCharge(courierId,weight,city));
28 }
29 catch(InvalidParcelWeightException e){
30 System.out.println(e.getMessage());
31 }
32
33 }
34
35 }
GoGoParcelService/src/main/java/com/spring/model/Courier.java
1 package com.spring.model;
2
3 public class Courier {
4
5 private int courierId;
6 private int weight;
7 private float chargePerKg;
8 private ServiceChargeInfo serviceCharge;
9
10 public ServiceChargeInfo getServiceCharge() {
11 return serviceCharge;
12 }
13 public void setServiceCharge(ServiceChargeInfo serviceCharge) {
14 this.serviceCharge = serviceCharge;
15 }
16 public int getCourierId() {
17 return courierId;
18 }
19 public void setCourierId(int courierId) {
20 this.courierId = courierId;
21 }
22 public int getWeight() {
23 return weight;
24 }
25 public void setWeight(int weight) {
26 this.weight = weight;
27 }
28
29 public float getChargePerKg() {
30 return chargePerKg;
31 }
32 public void setChargePerKg(float chargePerKg) {
33 this.chargePerKg = chargePerKg;
34 }
35
36 }
37
GoGoParcelService/src/main/java/com/spring/model/ServiceChargeInfo.j
ava
1 package com.spring.model;
2
3 import java.util.Map;
4
5 public class ServiceChargeInfo {
6
7 private Map<String,Float> locationServiceCharge;
8
9 public Map<String, Float> getLocationServiceCharge() {
10 return locationServiceCharge;
11 }
12
13 public void setLocationServiceCharge(Map<String, Float> locationServiceCharge) {
14 this.locationServiceCharge = locationServiceCharge;
15 }
16 }
17
GoGoParcelService/src/main/java/com/spring/service/CourierService.java
1 //CourierService
2
3 package com.spring.service;
4
5 import com.spring.bo.CourierBO; //importing packages and subpackages required
6 import com.spring.exception.InvalidParcelWeightException;
7 import com.spring.model.Courier;
8 import org.springframework.context.ApplicationContext;
9 import org.springframework.context.support.ClassPathXmlApplicationContext;
10 public class CourierService {
11
12 private CourierBO cBoObj;
13
14 public CourierBO getcBoObj() {
15 return cBoObj;
16 }
17
18 public void setcBoObj(CourierBO cBoObj) {
19 this.cBoObj = cBoObj;
20 }
21
22 public double calculateCourierCharge(int courierId,int weight,String city)throws
InvalidParcelWeightException {
23
24 double courierCharge=0.0;
25 //fill your code
26 if(weight>0 && weight<1000)
27 {
28 ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml");
29 Courier cObj=(Courier)context.getBean("courier");
30 cObj.setCourierId(courierId);
31 cObj.setWeight(weight);
32 courierCharge = cBoObj.calculateCourierCharge(cObj, city);
33 }
34 else
35 {
36 throw new InvalidParcelWeightException("Invalid Parcel Weight");
37 }
38 return courierCharge;
39 }
40
41 }
42
43
GoGoParcelService/src/main/resources/beans.xml
1 <beans xmlns="http://www.springframework.org/schema/beans"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
3 xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
4 xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
5 xmlns:task="http://www.springframework.org/schema/task"
6 xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-
3.2.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-
3.2.xsd">
7 <context:property-placeholder location="classpath:charges.properties" />
8
9
10 <bean id="courierBoObj" class="com.spring.bo.CourierBO" />
11 <bean id="courierService" class="com.spring.service.CourierService">
12 <property name="cBoObj" ref="courierBoObj" />
13
14 </bean>
15
16
17
18 <bean id="courier" class="com.spring.model.Courier">
19 <property name="courierId" value="123"/>
20 <property name="weight" value="45"/>
21 <property name="chargePerKg" value="${chargePerKg}"></property>
22 <property name="serviceCharge">
23 <bean class="com.spring.model.ServiceChargeInfo">
24 <property name="locationServiceCharge">
25 <map>
26 <entry key="Coimbatore" value="200.0"/>
27 <entry key="Chennai" value="300.0"/>
28 <entry key="Madurai" value="150.0"/>
29 </map>
30 </property>
31 </bean>
32 </property>
33
34 </bean>
35
36
37
38
39 </beans>
GoGoParcelService/src/main/resources/charges.properties
1 chargePerKg=20.0
Grade
Reviewed on Wednesday, 10 February 2021, 1:41 AM by Automatic grade
Grade 100 / 100
Assessment report
[+]Grading and Feedback