Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, attached below I've pasted a very simple and straight forward starter code (Java). Within the code, you will find comments that will walk you

Hello, attached below I've pasted a very simple and straight forward starter code (Java). Within the code, you will find comments that will walk you through the process step by step with detailed instructions to complete the code. (Then, attached below that, you will find pasted test code in order to test the program for completion.) If you have any questions, please let me know. Thank you so much in advance! ********************************************************************************************** package practiceOOP; import java.io.*; import java.io.IOException; import java.nio.file.*; import java.util.*; /** A class that represents a University */ public class University { // Instance variables private String name; // name of the university (like University of San Francisco) private List students; // list of students at this university /** * Constructor for class University. * Takes the name of university as a parameter * @param name name of university */ public University(String name) { // TODO: initialize instance variable name // TODO: Initialize ArrayList students } /** * Create a student a student with this name and id and * add the student to the list of students * @param studentName name of the student * @param studentId id of the student */ public void addStudent(String studentName, int studentId) { // TODO: create a student with this name and id } /** Return true if a person with the given name is a student at this university, * and false otherwise. * For the purpose of this exercise we assume that names are unique. * @param name name of the person * @return true if this person is a student at this university */ public boolean findStudent(String name) { // TODO: check if the student with this name is in the ArrayList return false; } /** * Return a string representation of the university * @return a string that contains the name of the university on the first line, and * then includes students, one on each line: * name, id */ public String toString() { // TODO: return a string representation of the university - see description above return null; // remember to change this } /** * Sorts the ArrayList of students by name in increasing order. */ public void sort() { // TODO: sort students. // No need to implementing sorting from scratch. You may use Collections.sort method // Note: implement compareTo method in class Student first for sorting to work } } 
**********************************************************************************************
 import org.junit.Assert; import org.junit.Test; import practiceOOP.University; public class UniversityTest { @Test public void testAddStudent() { University uni = new University("USF"); uni.addStudent("Elizabeth Lee", 527); uni.addStudent("Matthew Jordan", 252); String str = uni.toString(); Assert.assertEquals(str, "Elizabeth Lee, 527" + System.lineSeparator() + "Matthew Jordan, 252"); } @Test public void testFindStudent() { University uni = new University("USF"); uni.addStudent("Elizabeth Lee", 527); uni.addStudent("Matthew Jordan", 252); boolean foundSt1 = uni.findStudent("Elizabeth Lee"); Assert.assertTrue(foundSt1); boolean foundSt2 = uni.findStudent("Justin Meyers"); Assert.assertFalse(foundSt2); } @Test public void testSort() { University uni = new University("USF"); uni.addStudent("Elizabeth Lee", 527); uni.addStudent("Matthew Jordan", 252); uni.addStudent("Fatima Ghrahamani", 145); uni.sort(); String str = uni.toString(); Assert.assertEquals(str, "Elizabeth Lee, 527" + System.lineSeparator() + "Fatima Ghrahamani, 145" + System.lineSeparator() + "Matthew Jordan, 252"); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions