” CSE 11程序设计 辅导、java留学生编程 写作CSE 11 Fall 2020 PA6 – Exposure NotificationsSystemDue date: Wednesday, Nov 18 @ 11:59PM PST(Thursday, Nov 19 @ 11:59PM PST w/ slip day. If you submit your assignment late, the autograder will automaticallyuse your slip day if you have any remaining.)Provided FilesSimulator.javasample.txtYou can find these two files on Canvas.Files to SubmitContactInfo.javaServer.javaStudent.javaGoalThis programming assignment will give you an introduction to Classes in Java and a peep of Object OrientedProgramming. In this assignment, you will create three new classes from scratch with several instance variables andmethods.Please read the entire write-up before getting started. Some of the specific implementation details wont makesense until you understand the overall structure of all the classes and what instance variables/methods each classcontains.Please frequently check the FAQ post on Piazza as we will address common questions thereSome BackgroundSince the break of COVID-19 pandemic, Google and Apple have been building an Exposure Notifications Systemthat can quickly notify registered users about their recent close contact with COVID-19 infected people.Lots of thoughts have been put into this system to protect users privacy, so this system will neither track location norshare users identity with any organization or other users. Instead, this system uses Bluetooth to exchange random IDsamong users. Roughly, the Exposure Notification System works as follow:Each registered smart phone will generate a random ID that will change every few minutes so that userslocation and Identity cannot be tracked.When two phones are close enough, they will exchange their random IDs via Bluetooth.When a user reports a positive COVID-19 case on their phone, all of their recently used random IDs will beuploaded to a server.Several times a day, each phone will download all the infected IDs from the server and compare them againstits local contact history. If one of the infected IDs shows up in the contact history, the phone will show theuser a notification saying they might have been in contact with COVID-19 and provide further guidance.While the system is still in its testing phase in California, UCSD is one of the organizations in the California COVIDNotify Pilot Program which gives all UCSD students early access to this system.Now, Chancellor Khosla wants some help from the CSE department to manage this system. You want to help but youneed to show Chancellor Khosla your capabilities by implementing a similar system using Java classes. In thisassignment, you will implement these classes.Some General NotesMake sure to read the autograder output after you submit to Gradescope. We cannot be lenient regardinginformation that you can see by reading that output.Match the Method signatures that we provide exactly, otherwise we cannot ensure that the autograder willfunction correctly.Do not use any static variables and do not use any extra instance variables that are not specified in this writeup.We cannot ensure that these do not get clobbered during grading. Any extra variables used should be local only( private Static final constants are fine).Do not add any extra import s other than java.util.Random and java.util.ArrayList .Do not specify a package for your files. This will cause them to fail to compile with the autograder.Do not add any extra classes to your files and do not write code in files that are not specified.Do not call helper methods except from the class where they are implemented, as we will be using our ownversion of classes during grading (which will only have the instance variables and methods specified in thiswriteup).For the surveys and AI form, make sure you are filling them out and specifying your email address as the onelinked with your Gradescope account. If you fill them out after submitting, you can either resubmit to updateyour score immediately or wait for us to rerun the autograder for everyone after the deadline.Any late submission will trigger a slip day usage for this assignment. There will be no more exceptions foraccidents, since we cannot determine if it is an actual accident.Part 0: ValidityIn the parts below, we will have multiple kinds of integer values including:idlocationtimedistanceRemember that all these values are considered valid if and only if they are non-negative (e.g. if a time is equal to-10 , its invalid; if a location is 0 , it is valid).Part 1: ContactInfo.javaWhen two phones exchange information via Bluetooth, in addition to random IDs, they will also store the distanceand time of that contact. We want to create a class ContactInfo , in the file ContactInfo.java , to hold all theinformation used for the exchange.TODO: Instance Variables for ContactInfoEach ContactInfo object will be able to store only one id , which means we will need to create two ContactInfoobject in one exchange. We will use this in Part 4.id stores the (random) ID that is sent (to the other student).distance stores the distance between the two students and should always be non-negative.time stores the time this contact happens.used stores Whether this contact information has been used to send out an exposure notification.1 public class ContactInfo {…}public class ContactInfo {…public int id;public int distance;public int time;public boolean used;…}TODO: Methods to Implement for ContactInfoThis ContactInfo class only has one constructor and one method. The constructor initializes the instance variablesand isValid() checks if the instance variables are valid. You can think of this as meaning that when information isexchanged, we call the constructor locally, but the information might be invalid because it was corrupted before itarrived.public ContactInfo(int id, int distance, int time)This is the constructor for ContactInfo .Initialize used to false and initialize all other instance variables with the values from parameters. Do not doany Validity checking here for this constructor.public boolean isValid()Check if all the values of the instance variables are valid as specified in Part 0.Return false if any of the instance variables is invalid. Return true if all the instance variables are valid. Here,used Can take either boolean value so it is always valid.public class ContactInfo {…public ContactInfo(int id, int distance, int time);public boolean isValid();…}Part 2: Server.javaYou will need to create a Server class, in the file Server.java , to represent the server that stores all recent IDs fromCOVID-19 positive users. The server will only support two operations: adding new IDs and getting all stored IDs.TODO: Instance Variable for ServerinfectedIds stores the IDs in the order that they are added to the server, with the first being at index 0 and thelatest being at the end of the list.TODO: Methods to Implement for Serverpublic Server()This is the no-arg constructor for Server .Initialize InfectedIds with a new (empty) ArrayList .public boolean addInfectedIds(ArrayListInteger ids)Add every ID from ids into infectedIds in the order they appear (first at index 0, last at the end) and returntrue to Indicate adding is successful.If ids is null , return false to indicate adding failed without modifying anything. Do not do anything specialfor null values inside ids .1 public class Server {…}public class Server {…public ArrayListInteger infectedIds;…}public class Server {…public Server();public boolean addInfectedIds(ArrayListInteger ids);public ArrayListInteger getInfectedIds();…}public ArrayListInteger getInfectedIds()Return a deep copy of infectedIds . This means that you should create a new ArrayList and fill it with theexact elements in infectedIds – this way, if someone modifies the returned list, the instance variable will not beaffected.Note: we can assume that infectedIds will never be null when this method is called. Also, we would usuallysee infectedIds as a private instance variable but we are leaving it as public for testing purposes.Part 3: Student.javaIdeally, we would create a class representing phones to handle ID exchanges and a class representing students tohandle movements and COVID-19 test status, but for the sake of simplicity, we will just create one Student class, inthe file Student.java , to handle both ID exchanges and student-related functionality in this PA.TODO: Instance Variables for Studentid stores the (random) current ID of the student.location stores the current location of the student.covidPositive Stores an indicator for if the student has tested positive.inQuarantine stores an indicator for if the student is in quarantine (and therefore cannot move).usedIds stores all of the random IDs that the student has used so far, in order, with the first ID at index 0 andthe most recent one (the one currently stored in id ) at the end of the list.contactHistory stores the ContactInfo objects that were sent to this student (in an exchange in Part 4) in theorder they were received, with the first received at index 0 and the most recent one at the end of the list.1 public class Student {…}public class Student {…public int id;public int location;public boolean covidPositive;public Boolean inQuarantine;public ArrayListInteger usedIds;public ArrayListContactInfo contactHistory;…}TODO: Methods to Implement for StudentWe will implement all of these instance methods for the Student class to facilitate updating each object and fordoing some computations based on the current state of each object. Each method should have the behavior that isspecified and all instance variables should be updated or left unmodified as necessary so that future method callsoperate on correct instance variables.public Student()This is the no-arg constructor for Student .Initialize all instance variables properly in this constructor.id and location should both be -1 . We intentionally set id and location to an invalid value to indicatethat the student is not ready for simulation.covidPostive and inQuarantine should be false , since we are assuming that all students are not infectedat the beginning of the simulation.usedIds and contactHistory should each be initialized with a new (empty) ArrayList .public boolean setLocation(int newLocation)If newLocation is valid and inQuarantine is false , update the instance variable location with the new valuefrom newLocation and return true .Otherwise, return false , without modifying the location instance variable, to indicate setting location failed.public void updateId()Update id With a new random integer within the range [0, Integer.MAX_VALUE ). The method should alsostore this new id in the usedIds list. You can read about how to generate a random number here.public class Student {…public Student();public boolean setLocation(int newLocation);public void updateId();public boolean addContactInfo(ContactInfo info);public boolean uploadAllUsedIds(Server server);public boolean testPositive(Server server);public ArrayListContactInfo getRecentPositiveContacts(Server server,int fromTime);public int riskCheck(Server server, int fromTime, boolean quarantineChoice);…}public boolean addContactInfo(ContactInfo info)If info is non- null and valid (as specified in Part 1), add info to the end of the contactHistory list and returntrue .Otherwise, return false to indicate that adding contact information failed.public boolean uploadAllUsedIds(Server server)If server is not null , add all IDs in this Student objects usedIds list into the server , by calling server saddInfectedIds() method, and return whether addInfectedIds() executed successfully.Otherwise (if server is null ), return false without doing anything, indicating that uploading failed.public Boolean testPositive(Server server)Update covidPositive and inQuarantine to be true (calling this method indicates that the student has testedpositive). This should be done even if server is null .Then, upload this Student s used ids to server by calling uploadAllUsedIds() and return whetheruploadAllUsedIds() executed successfully or not. If uploadAllUserIds() cannot be called, return false too.public ArrayListContactInfo getRecentPositiveContacts(Server server, int fromTime)Get all infected IDs from the server by calling getInfectedIds() in the Server class (make sure you are notdirectly accessing the instance variable), and check contactHistory against them. Return a sublist ofcontactHistory where each ContactInfo in the sublist satisfies the following conditions:its used is falseits id is in the infected ID listits time is greater than or equal to fromTimeThere are several invalid inputs or states. If any of these occurs, return null instead:server is nullfromTime is invalid (i.e., it is negative)getInfectedIds() returns nullpublic int riskCheck(Server server, int fromTime, boolean quarantineChoice)Assess the students risk of having COVID-19 and simulate notifiying the student by letting them choose to selfquarantine.Do so following these steps:1. Get all recent contacts with positive cases by calling getRecentPositiveContacts() with the appropriatearguments. If getRecentPositiveContacts() returns null , return -1 without proceeding.2. Analyze this students risk of having COVID-19 based on the recent positive contacts. Any ContactInfothat results in this student being assessed as high-risk should be marked as used (the used instancevariable should be set to true ). A student is in high-risk if at least one of the conditions below is true:the student has at least one recent contact who tested positive and this contact had distance lessthan or equal to 1 . Any ContactInfo satisfying this should be marked as used.the student has three or more recent contacts who tested positive (regardless of distances). If thiscondition is Satisfied, all ContactInfo s should be marked as used.3. If the student is assessed as high-risk, update inQuarantine to true if quarantineChoice is true andthen return 1 regardless of quarantineChoice . If the student is not assessed as high-risk, return 0instead.Part 4: Simulator.javaFinally, we will need a Simulator class to simulate student interactions using the Exposure Notification System wejust built. Fortunately, we have written a Simulator for you in Simulator.java . Even though you dont need toimplement the Simulator, you still need to read through the Simulator class carefully and answer READMEquestions about the Simulator class on Gradescope.Simulator will read data from an input file where each line contains some integers separated by comma. All the linesin the file have the same length, which represents the number of students in this simulation. For example, an input filemight have the following content:Since each line has five numbers, we will have five students for this simulation. Each column contains all the data forone specific student.The first line shows each students choice of whether going into a quarantine when they are notified of being incontact with COVID positive cases.The second line and the third line are the data for the first day. The second line shows the locations for each student.The third line shows whether a student is tested positive or not ( 1 means positive).The fourth line and the fifth line similarly are the data for the second day. Similarly, any further days will be two morelines each.In summary, this example input file means:0,0,0,0,1 — Five students and their choices for quarantine1,1,1,4,4 — locations for day 0 (e.g. the first student is at 1)0,0,0,0,0 — infection status for day 0 (no one is infected in this cae)2,0,3,4,5 — locations for day 1 (e.g. the first student now is at 2)1,0,0,0,0 — infection status for day 1 (the first student is tested positive)Methods and Instance Variables for Simulatorpublic Class Simulator {…public ArrayListStudent students;public Server server;public Simulator(int num);public void updateIds();public boolean updateLocations(ArrayListInteger locations);public boolean updateInfectionStatus(ArrayListInteger infections);public int riskCheckAll(ArrayListInteger quarantineChoices, int fromTime);public boolean exchangeInfo(Student student1, Student student2, int currentTime);public int simulateOneDay(ArrayListInteger locations, ArrayListInteger infections, ArrayListIntegerquarantineChoices, int time);public static void main() throws IOException;…}TipsThis PA is relatively complex and many methods depend on other methods, so debugging the whole programwould be hard. We highly recommend writing a main method or a test class for each class to test each methodindividually. You will either need to delete the main method when turning in your assignment or ensure thatyour main method follows the style guide (except the magic number rule).When we test your code, we will unit test each method individually so you can safely use all other methods. Forexample, you need to call getRecentPositiveContacts() in riskCheck() . When we test your riskCheck() , wewill use our correct version of getRecentPositiveContacts() .You can Use the provided Simulator.java as an example of how methods you implemented in other classes(especially Student class) will be used.All files (all .java files and the sample.txt ) should be in the same directory.To run the simulator, you need to compile all .java files (having their .class files) and run java Simulator .Feel free to create your own testing classes to try out the simulator or any other classes.Feel free to modify the content in the input file to test your code.StyleCoding style is an important part of ensuring readability and maintainability of your code. We will grade your codestyle in all submitted code files according to the style guidelines. Namely, there are a few things you must have ineach file/class/method:1. File headers2. Class headers3. Method headers4. Inline comments5. Proper indentation (do not intermingle spaces and tabs for indentation)6. Descriptive variable names7. No magic numbers (exception: main() for testing purposes)8. Reasonably short methods (if you have implemented each method according to specification in this write-up,youre fine)9. Lines shorter than 80 characters (note, tabs will be counted as 4 characters toward this limit. It is a good idea toset your tab width/size to be 4)10. Javadoc conventions (@param, @return tags, /** header comments */, etc.)A full style guide can be found here. In addition, an example of a properly styled Java file has been posted on Piazza.If you need any clarifications, feel free to ask on Piazza.READMEAll the questions for the README portion of this assignment can be found on Gradescope. Note that this portion ofthe assignment cannot be submitted late.For this PA, README questions are about the Simulator class that we provide you, so you should read throughSimulator.java carefully before answering the README questions.SurveyPlease fill out this survey, worth 1 point to your PA grade, to help us improve the experience of this class!Weekly Reflection 6.SubmissionTurning in your codeSubmit all Of the following files to Gradescope by Wednesday, Nov 18 @ 11:59PM PST (Thursday, Nov 19 @11:59PM PST w/ slip day):ContactInfo.javaServer.javaStudent.javaWhen submitting, please wait until the autograder finishes running and read the output. Your code must compile inthe autograder in order to receive proper partial credit.Evaluation1. Correctness (80 points) You will earn points based on the autograder tests that your code passes. If theautograder tests are not able to run (e.g., your code does not compile or it does not match the specifications inthis writeup), you may Not earn credit.2. Coding Style (10 points)3. README (9 points)4. Weekly Reflection Survey (1 point)如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。