Spring Boot Framework Hands-on solution | TCS Fresco Play | TCS | MNC Answers
Disclaimer: The primary purpose of providing this solution is to assist and support anyone who are unable to complete these courses due to a technical issue or a lack of expertise. This website's information or data are solely for the purpose of knowledge and education.
Make an effort to understand these solutions and apply them to your Hands-On difficulties. (It is not advisable that copy and paste these solutions).
All Question of the MCQs Present Below for Ease Use Ctrl + F with the question name to find the Question. All the Best!
Spring Boot is a Java-Based Framework for building Microservices.
The Course Id is 55960.
1. Sorting list of Candidates
1.Employee.java
package com.example.demo.employee;
public class Employee implements Comparable<Employee> {
private String name;
private int age;
private int exp;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getExp() {
return exp;
}
public void setExp(int exp) {
this.exp = exp;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Employee(String name, int age, int exp) {
super();
this.name = name;
this.age = age;
this.exp = exp;
}
public Employee() {
}
@Override
public int compareTo(Employee emp) {
//replace your comparator here
return (this.getAge() - emp.getAge());
}
2.EmployeeController
package com.example.demo.employee;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
@RestController
public class EmployeeController {
@Autowired
private EmployeeService emp;
//Put your code here
@RequestMapping("/")
public List<Employee> getEmpList(){
//Put your code here
List<Employee> e = emp.getEmployees();
Collections.sort(e);
return e;
}
}
3.EmployeeService.java
package com.example.demo.employee;
import java.util.Arrays;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.ArrayList;
@Service
public class EmployeeService {
public List<Employee> getEmployees() {
final List<Employee> demo = new ArrayList<>();
demo.add(new Employee("Sandhya",20,0));
demo.add(new Employee("Kemp",24,2));
demo.add(new Employee("Anil",22,3));
demo.add(new Employee("Kumar",30,6));
demo.add(new Employee("Tim",32,7));
return demo;
}
}
}
Spring Boot Framework MCQ Solution
2. Accessing Values from the application. properties.file
fresco-course = Spring Boot
Spring Boot Framework MCQ Solution
3) Print contents of the list along the sublist
ContentController.java
package com.example.demo.content;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class ContentController {
//Put your code here.
@Autowired
private ContentService cs;
@RequestMapping("/")
public List<Category> getContentList(){
List<Category> c = cs.getAllContent();
return c;
}
}
ContentService.java
package com.example.demo.content;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import org.springframework.stereotype.Service;
@Service
public class ContentService {
//put your code here.
public List<Category> categories = new ArrayList<>();
public List<Category> getAllContent() {
List<Course> courses = new ArrayList<>();
courses.add(new Course(1,"Coursename",200,200,1001));
courses.add(new Course(2,"Coursename",200,200,1001));
courses.add(new Course(3,"Coursename",200,200,1001));
List<Category> categories = new ArrayList<>();
categories.add(new Category(1001,"Cloud Computing","network of remote servers hosted on the internet to store",courses));
categories.add(new Category(1002,"Software","network of remote servers hosted on the internet to store",courses));
categories.add(new Category(1003,"Networking","network of remote servers hosted on the internet to store",courses));
return categories;
}
}
Post a Comment