程序代写代做代考 Java case study Section A

Section A
Question 1
Write a static method that displays all numbers from 1 to 1000 inclusive, that are divisible by 4 and 5, excludes multiples of 40 (40, 80, 120…), and starts a new line after every multiple of 100 (100, 200, 300…).
The output of the method should be:
20 60 100
140 180
220 260 300
340 380
420 460 500
540 580
620 660 700
740 780
820 860 900
940 980
Question 2
Write 3 classes Product, Book and Software as described below. Class Product has 2 attributes code in String and price in double.
Class Product has a constructor that receives 2 parameters and sets attributes code and price to the given values. It has another constructor that receives 1 parameter, sets attribute code to the given value, and sets attribute price to 2. The second constructor must call the first constructor.
Class Product overrides method toString() and returns the value of attribute code concatenating with the value of attribute price.
Class Book derives from class Product. It has another attribute author in String. It has a constructor that receives 3 parameters and sets its parent¡¯s attributes and attribute author to the given values. The constructor must call its parent¡¯s constructor.
Class Software derives from class Product. It has another attribute version in String. It has a constructor that receives 3 parameters and sets its parent¡¯s attributes and attribute version to the given values. The constructor must call its parent¡¯s constructor.
Class Software also overrides method toString() and returns the value from its parent¡¯s toString() method, concatenating with the value of attribute version. This method must call its parent¡¯s toString() method.

Question 3
The partial snippet for class Student is as follows:
class Student {
String matricNo; // Matriculation number String name;
String address;
double CAP;
public Student() { }
// Getters and
Setters }
Given a set of matriculation numbers, write a static method to retrieve a list of the respective Student objects from a map that stores matriculation numbers as keys and Student objects as values.
For any given matriculation number that is not found in the map, ignore and do not put any respective Student object into the result list.
Question 4
Write a method that uses only Java stream¡¯s methods to count the number of occurrences of
the second largest number in an array of integer numbers. For example, if the given array includes
then the method should return 3, because the second largest number is 4 and it occurs 3 times. You can assume that the second largest number always exists in the given array.
Question 5
Design and implement a class TwoElement so that running the following code
1, 2, 5, 4, 3, 5, 4, 2, 4

public static void main(String[] args) {
TwoElement i1 = new TwoElement<>(3, 4); System.out.println(i1.getElement1() + ” and ” + i1.getElement2());
TwoElement i2 = new TwoElement<>(4, 3); System.out.println(i2.getElement1() + ” and ” + i2.getElement2());
TwoElement i3 = new TwoElement<>(2.2, 1.1); System.out.println(i3.getElement1() + ” and ” + i3.getElement2());
TwoElement i4 = new TwoElement<>(1.1, 2.2); System.out.println(i4.getElement1() + ” and ” + i4.getElement2());
TwoElement i5 = new TwoElement<>(“aa”, “bb”); System.out.println(i5.getElement1() + ” and ” + i5.getElement2());
TwoElement i6 = new TwoElement<>(“bb”, “aa”);
System.out.println(i6.getElement1() + ” and ” + i6.getElement2()); }
will produce the following output
3 and 4
3 and 4
1.1 and 2.2
1.1 and 2.2
aa and bb aa
and bb
~~~~~~~~ End of Section A ~~~~~~~~

Section B
Question 6
Answer the following questions using Spring Data Framework and Java Persistence API. While, answering, consider the initial class diagram discussed in the case study:
a) Is the class diagram complete? One of the detailed requirements states that when a room is booked by a particular a customer or staff, the hotel booking system must calculate rental payment based on per day rental for the selected room, calculate a 10% GST and also capture payment. How will you redesign RoomBooking.java? Do you need additional classes? How will you design the relationship? If you are asked to add three more attributes, what would be your suggestion? Code the improved class or Draw the class diagram for RentalBooking class.
b) Complete the entity mapping for your proposed model classes Staff, Customer, HotelRooms, RoomBooking and your new classes if any.
c) Write Queries using either query finder methods or using @Query for the following situations as deemed necessary by the application detailed in appendix A:
a. Find all the bookings made by a particular customer.
b. Find all bookings made on a particular day for a selected floor.
c. Find the various booking a particular Staff has initiated in a particular date range. The
query takes staff id and the date range as inputs.
d. List the rooms that are available for booking and their respective rental prices on any
given day.
e. Calculate the room rental amount based on a selected booking made.

Question 7
Answer the following questions using Spring MVC Framework and Application Transaction API. While, answering, consider the code fragments discussed in the case study:
a) Refer to the HBS case study described in Appendix A, developed using the Spring framework.
The scenario to create a rental booking is presented diagrammatically in figure below. Controller class HBSController.java (partial code is shown) validates the data in the form bookingform.html (shown overleaf) and inserts a rental booking record using the addBooking(…) method from HbsServiceImpl.java (shown in case study).
Complete the controller¡¯s relevant addBooking(. . .) method and showFormForAdd(. . .) method with relevant annotations, and use proper validation logic. The create method can choose to use validator annotations on the model class if needed. If the date range overlaps with existing booking, the controller directs to error message page called bookingdateerror.html.

b)
Propose and code the HTML page with Thymeleaf template engine for the below view:
booking-form.html
c)
Consider the scenario where a new customer walks in to book a room. First a new customer record is created by the staff and then a room booking is created. Both the transactions must be complete for a successful booking. In case either of them fails the entire transaction must be aborted as well. Craft a method (createCustomerAndAddBooking(. . .) called) inside the existing HbsServiceImpl.java class for the same.

Question 8
Answer the following questions using Spring Reactive and advanced concepts taught in class regards to application layering:
a) Thus far, HBS only uses block communication model using the Spring Framework¡¯s core Model-View-Controller (MVC) architecture (as illustrated in diagram below), where controllers, service layer and repository layers encapsulate the server side processing logic for minimal viable product of HBS. As a first step towards non-blocking controllers design, how will you change existing controller? Enumerate one key shortcoming of your proposed design and suggest how you will improve or fix the identified design shortcomings.
b) In which use case can we use Spring¡¯s Reactive Component Mono in HBS application? Elaborate why your choice with sample code and explain how it will improve performance.
~~~~~~~~ End of Section B ~~~~~~~~ ~~~~~~~~ End of Paper 4 ~~~~~~~~