Lab2_Solution
.pdf
keyboard_arrow_up
School
University of Toronto *
*We aren’t endorsed by this school
Course
350
Subject
Computer Science
Date
Dec 6, 2023
Type
Pages
6
Uploaded by MagistrateWorldChinchilla30
MIE 350 Lab 2 Answers
Question 1:
1. Open StudentController.java (the REST controller for the Student entities).
a.
Locate the function retrieveAllStudents()
i.
The function is annotated with @GetMapping that indicates a GET request
handler accessed through the URL “/students”. What is the CRUD operation that
is normally associated with a GET request?
Read. A GET request usually performs Read operation on the contents of the
database/repository.
ii.
What do you think the purpose of this function?
This function retrieves information of all students in our student Table.
iii.
Use the Insomnia client to send a GET request to http://localhost:8085/students
as in the following image. Press SEND. What did you get as a result for your
query (in the right side under “Preview”)
GET:
http://localhost:8085/students
In the preview we see a list of all students in the student table along with their
attributes, including the list of marks for each student. Within the list of marks,
each mark element includes the composite key (composed of student id and
course id), the student entity, the course entity and the mark value.
b.
Next, locate the function
createStudent(@RequestBody Student newStudent)
i.
What type of HTTP requests is this function handling? What CRUD operation is
associated with this type of HTTP requests?
Create.
ii.
What do you expect the function to do?
This function can be used to add a new student to the database.
iii.
Use the Insomnia client and send a request to create a student.
Note: as indicated by the function’s argument, the body of the request needs to
be a JSON representation of the Student entity. Following is an example JSON
for creating a student in the CMS and an image on how to send such request
using the Insomnia client.
{
"id": 9999,
"firstName": "myFirstName",
"lastName": "myLastName",
"email": "my@email.ca"
}
Follow instructions provided in the question. You can modify firstname, lastName
and email values to your choice.
POST:
http://localhost:8085/students
With JSON body
iv.
Run a similar GET request as in 1(a). Did the result change?
GET:
http://localhost:8085/students
Ensure the body of the request is of "No BODY" type (since it is a GET request).
Yes the results show the new student added at the end of the preview list.
c.
Examine the function
@GetMapping("/students/{id}")
retrieveStudent(@PathVariable("id") Long studentId)
i.
The function retrieves the details of a single student based on their student ID
provided as part of the URL.
Note: as indicated by the function’s argument, the URL variable id will be mapped
to the argument studentId of type Long. For example, sending a GET request to
/students/5555 will run this function and map the value 5555 to the studentId
argument.
The @PathVariable annotation is used to extract the value of the template
variable “id” (mentioned in the URL of the request), and assign their value to a
method variable studentId of Long type.
ii.
Use the Insomnia client and retrieve the student details for the student with the
student ID 5555. What do you see?
GET:
http://localhost:8085/students/5555
Retrieves all information about the student with id 5555:
{
"id": 5555,
"firstName": "Jon",
"lastName": "Snow",
"email": "jon.snow@mail.univ.ca",
"marks": [
{
"markId": {
"studentId": 5555,
….
d.
Examine the rest of the code in StudentController.java:
i.
Locate the function that is responsible for updating the details of a student and
identify the type of HTTP request, the URL, and the parameters it takes. Then,
use the Insomnia client to update the name and email of one of the existing
students.
●
updateStudent
is the function that is used to update student.
●
PutMapping
HTTP request initiates the update of the student entity. It
expects a Student entity/object within the body of the request and the
student id specified in the URL of the request.
●
The URL used to call this function is:
PUT: http://localhost:8085/students/5555
JSON:
{
"Id": 5555,
"firstName": "Jonathan",
"lastName": "Smith",
"email": "jon.smith@mail.univ.ca"
}
Note: We change the firstName, lastName and email in the request.
ii.
Retrieve the student details of the student you just updated and see the student’s
information. Did both the name and email of the student update? If not, what field
has not been updated?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
In C Programming:
Write a function printCourseRow() which receives a course pointer and prints all its fields as a single row. Use proper formatting so that when we print 2 or more courses as rows, the same members align below each other. Test the function, but don’t include the testing code in your homework.Upload a screenshot of a sample output.
arrow_forward
WRITE 2 C FILE
In this assignment you are required to follow the Unix domain server and client example done in the classroom. After this point, you need to setup the server in a way that it will process the data sent by the client and send back the processed data. You must read at least two set of data, and send back at least a piece of information. For instance, client might send two numbers and the server will send the summation back. This is only an example, please do something a little more complicated. I do not want to see same operation over and over again in the assignments. You can use scanf and printf with dup2 to obtain numbers. Alternatively, you could read the text and use sscanf and sprintf. You could also perform text based operations. It is up to you.
You must perform all error checks.
arrow_forward
Appendix A. BTB entries with PC and Target PC. Please include only entries with content.Entry PC Target0 423000 425E407 42E01C 42E0288 423020 4230A811 42E02C 42B30C14 423038 425E40: : :: : :1018 422FE8 4230A8
arrow_forward
please code pythonWe’ve already looked at several examples of API integration from a Python perspective and this week we’re going to write a program that uses an open API to obtain data for the end user. Create a program which uses the Request library to make a GET request of the following API: Chuck Norris Jokes. The program will receive a JSON response which includes various pieces of data. You should parse the JSON data to obtain the “value” key. The data associated with the value key should be displayed for the user (i.e., the joke). Your program should allow the user to request a Chuck Norris joke as many times as they would like. You should make sure that your program does error checking at this point. If you ask the user to enter “Y” and they enter y, is that ok? Does it fail? If it fails, display a message for the user. There are other ways to handle this. Think about included string functions you might be able to call. Your program must include a header as in previous weeks.…
arrow_forward
Question R .Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this line
arrow_forward
Write a Program in C Language.
arrow_forward
*
Using the following access matrix tell if the asked operations is allowed or denied.
P1 which runs in D1 domain attempts to read F3
P1 which runs in D1 domain attempts to print using laser printer
P1 which runs in D1 domain attempts to execute F3
object
laser
F3
printer
D2
D3
D4
domain
read
read
switch
D2
print
switch switch
D3
read
execute
D4
read
write
read
write
switch
arrow_forward
Compliant/Noncompliant Solutions
The following code segment was provided in Secure Coding Guidelines for Java SE:
void readData() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream("file"))); // Read from the file String data = br.readLine();}
The code is presented as a noncompliant coding example. For this assignment, identify two compliant solutions that can be utilized to ensure the protection of sensitive data. Provide a detailed explanation of factors, which influence noncompliant code and specifically how your solutions are now compliant. Your explanation should be 2-3 pages in length.
Submit the following components:
Word document with appropriate program analysis for your compliant solutions and source code in the Word file.
Submit your .java source code file(s). If more than 1 file, submit a zip file.
arrow_forward
Bullet-point the boots' functions.
arrow_forward
Implement all the functions from the Question 2 and make a login and sign up module, all thedata will be stored in the files and as well as in the linked list, Program will have two modules1. login2. sign upSign Up:In this module the program will ask the user to enter username, password, address, city, phonenumber, gender and will store the data in the linked list. If the username already exists in thelinked list it will ask the user to change the username, all the data will also be stored in the textfile.Login:
In this module the user will enter its username and password, the program will check if the dataexists in the linked list, if yes then show “Welcome to home screen”, if not then ask the user toenter the username and password again.Work Flow:1. The program will start and all the data from the files will be loaded in the linked list.2. The login and sign up screen will pop up3. Apply proper checks, if the file exists or not (Hint: you can use try catch to handle theexceptions)…
arrow_forward
Python language
arrow_forward
Write a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file or the name of a directory. If the pathname refers to a file, its filepath is displayed, followed by its contents, like so:
File name: file_path Lorem ipsum dolor sit amet, consectetur adipiscing elit...
Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory, like so:
Directory name: directory_path File name: file_path1 Lorem ipsum dolor sit amet... File name: file_path2 Lorem ipsum dolor sit amet... ...
# Put your code here
import os #module used to interact with operating system
def displayFiles(pathname): #recursive function that takes a pathname as argument
if (os.path.isdir(pathname)): #checks if specified path (argument) is an existing directory
#for item in os.listdir(pathname):
for content in os.listdir(pathname): #gets the list of all files and directories in the directory and…
arrow_forward
Write a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file or the name of a directory. If the pathname refers to a file, its filepath is displayed, followed by its contents, like so:
File name: file_path Lorem ipsum dolor sit amet, consectetur adipiscing elit...
Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory, like so:
Directory name: directory_path File name: file_path1 Lorem ipsum dolor sit amet... File name: file_path2 Lorem ipsum dolor sit amet... ...
arrow_forward
Which example uses the SOLID SRP principle correctly and does not violate it? (A or B)
A.
public class DatabaseParser {
ParseDirectoryMapFile(); // parse directory map fileParsePasswordFile(); // parse user fileParseReviewDataFile(); // parse review data fileParseTeamFile(); // parse team
CalculateGrade();
CalulateRelativeGrade();
}
B
public class DatabaseParser {
ParseDirectoryMapFile(); // parse directory map fileParsePasswordFile(); // parse user fileParseReviewDataFile(); // parse review data fileParseTeamFile(); // parse team file}
// seperately with the following:
public class Calculator{
CalculateGrade();
CalulateRelativeGrade();
}
arrow_forward
Computer Science
Write the code for a book managing system that will record books in a SQLite database in Android Studio using Java. The user need to register on the app by entering name, age, address, reading interest (e.g. fiction/nonfiction). The user will be provided with a user name/email ID, which will be used to maintain the record of each unique user. The app should ask a user to log in with a user name and password. Once the user is logged in, the app should display three options “Add a book, update a Book and Borrow a Book.
If a user chooses add a book option, new activity should open asking for book details (title, author, publisher and publication year). If a user chooses update a book option, new activity should open showing a particular book details and should give the option to update the book’s information including status. The book status needs to be updated if the book is borrowed by others.
If the user selects Borrow a Book option the app should ask the user to…
arrow_forward
Answer the qust in the Java Script and use the opps concepts while answering the questions
arrow_forward
What would be the missing code
arrow_forward
Assignment 1 University Library SystemIn this assignment you are going to implement your own version of university library system,The system will have two different sides , the first one is to help the librarian to do his job and the other side for admin to manage every one permissions in the system , so You should provide the following features in your system: Admin viewo Add/remove Studentso Add/remove librariano Add/remove other admins Librarian viewo Add/Delete bookso Issue/Return bookso View bookso View Issued bookso Log in /log outo Search for the book(id/name) Simple backend for your system , You could use a file each row should represent item o Books File should be something like:Id , Book Name, Author Name, Available quantity, Issued Quantity 1,Oliver Twist, Charles Dickens,98,2In the previous the first row was the name of each column , you can do that orhandle it in your code , id =1 , Book Name =Oliver Twist ..Etc. Tables neededo Books Id Book Name Author Name…
arrow_forward
Project in Java programming language :
Choose an enterprise and do a business description of it. 1-2 pages.
Create all classes for entities.
All classes must have at least a constructor, get and set methods for all private
variables and a toString method.
Create classes also for connection entities (e.g. orders, reservations, etc.)
All information should be saved in files. When opening the program, all information from
files must be loaded in array lists. Use an array list for every class.
The program must have at least one menu where the user can choose the operations to
work.
You should at least have one class that inherits from another class. You should have at
least one interface that is extended by at least 2 classes. You must use the interface
methods in your program.
You are allowed to use the GUI for this project. If not use JOptionPane
You are allowed to use databases, instead of files.
arrow_forward
GDB and Getopt Class Activity
activity [-r] -b bval value
Required
Modify the activity program from last week with the usage shown. The value for bval is required to be an integer as is the value at the end. In addition, there should only be one value.
Since everything on the command line is read in as a string, these now need to be converted to numbers.
You can use the function atoi() to do that conversion.
You can do the conversion in the switch or you can do it at the end of the program.
The number coming in as bval and the value should be added together to get a total.
That should be the only value printed out at the end. Total = x should be the only output from the program upon success. Remove all the other print statements after testing is complete.
Take a screenshot of the output to paste into a Word document and submit.
Practice
Compile the program with the -g option to load the symbol table.
Run the program using gdb and use watch on the result so the program stops when the…
arrow_forward
Mutual Exclusion: Select all of the following statements that are true.
The Peterson Algorithm does not rely on the mechanism of busy waiting.
The Peterson Algorithm is a purely software-based solution to the mutual
exclusion problem.
The only way to guarantee the atomicity of operations is to disable interrupts.
Mutex Locks are an API offered by operating systems to protect critical sections.
In order to enter a critical section protected by Mutex Locks, the release()
operation must be executed first.
The test_and_set instruction is atomic.
arrow_forward
Explain the GetProcessHeap function.
arrow_forward
The question should be done in C++, please give explanation and running result.
1. For this question, we need to provide more information about where the mismatch of the text file is happening.
Write a recursive function called list_mismatched_lines that takes 2 filenames as input arguments and displays to the screen all mismatched lines in those files. This function should use hashing techniques and shall not compare strings to detect mismatch.
The signature of this function should be:
void list_mismatched_lines(std::string file1, std::string file2);
In file1.txt, it contains "My dear C++ class. I hope that you enjoy this assignment. "
In file2.txt, it contains "My dear C++ class. I hope that you like this assignment. "
Example: Running the following line of code, should print to the screen the mismatched lines only, from both files.
list_mismatched_lines(file1, file2);
The following output should be seen on the screen:
file1.txt: I hope that you enjoy this assignment.file2.txt:…
arrow_forward
The Challenge: You are dealing with a lot of unfamiliar code and want to walk through it step by step. You've reached a call to the function do_the_funny_bird and want to know what it does, but you're not sure where it's defined. How to efficiently browse the code in such circumstances.
arrow_forward
QUESTION 1
Evaluate the following Postfix expression to find the final value. Trace the evaluation using class PostfixEvaluator. Show
the operand stack each time it is modified. (Clearly show all steps)
2 3
9 7
Attach File
Browse My Computer
arrow_forward
You are required to propose FOUR functions to develop a complete student record management system. The function are insert, delete, search, update.
In addition, you need to use linked list to complete the system development.
Write a program by extending the code from the lab.
Think and implement 4 more functions in the program (compulsory function is sorting and searching)
Your must build on top of the following code.
//FileName: Student.cpp //This program illustrates attributes of class Student using simple data structure #include <iostream.h> class Student { private: struct Data { char Name[25]; char Course[30]; int Result; } stdata; public: void SetData(); void GetData(); };//class Student void Student::SetData() { cout <<”Enter student name:”; cin>> stdata.Name; cout<< “Enter student course: “; cin>> stdata.Course; cout<< “Enter student result:”; cin>> stdata.Result; };//method SetData void Student::GetData()
{ cout<< “\n…
arrow_forward
In python, rite a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file or the name of a directory. If the pathname refers to a file, its filepath is displayed, followed by its contents, like so:
File name: file_path Lorem ipsum dolor sit amet, consectetur adipiscing elit...
Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory, like so:
Directory name: directory_path File name: file_path1 Lorem ipsum dolor sit amet... File name: file_path2 Lorem ipsum dolor sit amet... ...
Test this function in a new program.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- In C Programming: Write a function printCourseRow() which receives a course pointer and prints all its fields as a single row. Use proper formatting so that when we print 2 or more courses as rows, the same members align below each other. Test the function, but don’t include the testing code in your homework.Upload a screenshot of a sample output.arrow_forwardWRITE 2 C FILE In this assignment you are required to follow the Unix domain server and client example done in the classroom. After this point, you need to setup the server in a way that it will process the data sent by the client and send back the processed data. You must read at least two set of data, and send back at least a piece of information. For instance, client might send two numbers and the server will send the summation back. This is only an example, please do something a little more complicated. I do not want to see same operation over and over again in the assignments. You can use scanf and printf with dup2 to obtain numbers. Alternatively, you could read the text and use sscanf and sprintf. You could also perform text based operations. It is up to you. You must perform all error checks.arrow_forwardAppendix A. BTB entries with PC and Target PC. Please include only entries with content.Entry PC Target0 423000 425E407 42E01C 42E0288 423020 4230A811 42E02C 42B30C14 423038 425E40: : :: : :1018 422FE8 4230A8arrow_forward
- please code pythonWe’ve already looked at several examples of API integration from a Python perspective and this week we’re going to write a program that uses an open API to obtain data for the end user. Create a program which uses the Request library to make a GET request of the following API: Chuck Norris Jokes. The program will receive a JSON response which includes various pieces of data. You should parse the JSON data to obtain the “value” key. The data associated with the value key should be displayed for the user (i.e., the joke). Your program should allow the user to request a Chuck Norris joke as many times as they would like. You should make sure that your program does error checking at this point. If you ask the user to enter “Y” and they enter y, is that ok? Does it fail? If it fails, display a message for the user. There are other ways to handle this. Think about included string functions you might be able to call. Your program must include a header as in previous weeks.…arrow_forwardQuestion R .Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardWrite a Program in C Language.arrow_forward
- * Using the following access matrix tell if the asked operations is allowed or denied. P1 which runs in D1 domain attempts to read F3 P1 which runs in D1 domain attempts to print using laser printer P1 which runs in D1 domain attempts to execute F3 object laser F3 printer D2 D3 D4 domain read read switch D2 print switch switch D3 read execute D4 read write read write switcharrow_forwardCompliant/Noncompliant Solutions The following code segment was provided in Secure Coding Guidelines for Java SE: void readData() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream("file"))); // Read from the file String data = br.readLine();} The code is presented as a noncompliant coding example. For this assignment, identify two compliant solutions that can be utilized to ensure the protection of sensitive data. Provide a detailed explanation of factors, which influence noncompliant code and specifically how your solutions are now compliant. Your explanation should be 2-3 pages in length. Submit the following components: Word document with appropriate program analysis for your compliant solutions and source code in the Word file. Submit your .java source code file(s). If more than 1 file, submit a zip file.arrow_forwardBullet-point the boots' functions.arrow_forward
- Implement all the functions from the Question 2 and make a login and sign up module, all thedata will be stored in the files and as well as in the linked list, Program will have two modules1. login2. sign upSign Up:In this module the program will ask the user to enter username, password, address, city, phonenumber, gender and will store the data in the linked list. If the username already exists in thelinked list it will ask the user to change the username, all the data will also be stored in the textfile.Login: In this module the user will enter its username and password, the program will check if the dataexists in the linked list, if yes then show “Welcome to home screen”, if not then ask the user toenter the username and password again.Work Flow:1. The program will start and all the data from the files will be loaded in the linked list.2. The login and sign up screen will pop up3. Apply proper checks, if the file exists or not (Hint: you can use try catch to handle theexceptions)…arrow_forwardPython languagearrow_forwardWrite a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file or the name of a directory. If the pathname refers to a file, its filepath is displayed, followed by its contents, like so: File name: file_path Lorem ipsum dolor sit amet, consectetur adipiscing elit... Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory, like so: Directory name: directory_path File name: file_path1 Lorem ipsum dolor sit amet... File name: file_path2 Lorem ipsum dolor sit amet... ... # Put your code here import os #module used to interact with operating system def displayFiles(pathname): #recursive function that takes a pathname as argument if (os.path.isdir(pathname)): #checks if specified path (argument) is an existing directory #for item in os.listdir(pathname): for content in os.listdir(pathname): #gets the list of all files and directories in the directory and…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education