首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
CSE 11程序设计辅导、java留学生编程讲解、辅导program语言 解析R语言编程|辅导留学生 Statistics统计、回归、迭代
项目预算:
开发周期:
发布时间:
要求地区:
CSE 11 Fall 2020 PA6 - Exposure Notifications
System
Due 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 automatically
use your slip day if you have any remaining.)
Provided Files
Simulator.java
sample.txt
You can find these two files on Canvas.
Files to Submit
ContactInfo.java
Server.java
Student.java
Goal
This programming assignment will give you an introduction to Classes in Java and a peep of Object Oriented
Programming. In this assignment, you will create three new classes from scratch with several instance variables and
methods.
Please read the entire write-up before getting started. Some of the specific implementation details won't make
sense until you understand the overall structure of all the classes and what instance variables/methods each class
contains.
Please frequently check the FAQ post on Piazza as we will address common questions there
Some Background
Since the break of COVID-19 pandemic, Google and Apple have been building an Exposure Notifications System
that 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 nor
share user's identity with any organization or other users. Instead, this system uses Bluetooth to exchange random IDs
among 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 user's
location 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 be
uploaded to a server.
Several times a day, each phone will download all the "infected" IDs from the server and compare them against
its local contact history. If one of the "infected" IDs shows up in the contact history, the phone will show the
user 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 COVID
Notify 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 you
need to show Chancellor Khosla your capabilities by implementing a similar system using Java classes. In this
assignment, you will implement these classes.
Some General Notes
Make sure to read the autograder output after you submit to Gradescope. We cannot be lenient regarding
information that you can see by reading that output.
Match the method signatures that we provide exactly, otherwise we cannot ensure that the autograder will
function 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 own
version of classes during grading (which will only have the instance variables and methods specified in this
writeup).
For the surveys and AI form, make sure you are filling them out and specifying your email address as the one
linked with your Gradescope account. If you fill them out after submitting, you can either resubmit to update
your 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 for
"accidents," since we cannot determine if it is an actual accident.
Part 0: Validity
In the parts below, we will have multiple kinds of integer values including:
id
location
time
distance
Remember that all these values are considered valid if and only if they are non-negative (e.g. if a time is equal to
-10 , it's invalid; if a location is 0 , it is valid).
Part 1: ContactInfo.java
When two phones exchange information via Bluetooth, in addition to random IDs, they will also store the distance
and time of that contact. We want to create a class ContactInfo , in the file ContactInfo.java , to hold all the
information used for the exchange.
TODO: Instance Variables for ContactInfo
Each ContactInfo object will be able to store only one id , which means we will need to create two ContactInfo
object 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 ContactInfo
This ContactInfo class only has one constructor and one method. The constructor initializes the instance variables
and isValid() checks if the instance variables are valid. You can think of this as meaning that when information is
exchanged, we call the constructor locally, but the information might be invalid because it was corrupted before it
arrived.
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 do
any 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.java
You will need to create a Server class, in the file Server.java , to represent the server that stores all recent IDs from
COVID-19 positive users. The server will only support two operations: adding new IDs and getting all stored IDs.
TODO: Instance Variable for Server
infectedIds stores the IDs in the order that they are added to the server, with the first being at index 0 and the
latest being at the end of the list.
TODO: Methods to Implement for Server
public Server()
This is the no-arg constructor for Server .
Initialize infectedIds with a new (empty) ArrayList .
public boolean addInfectedIds(ArrayList
ids)
Add every ID from ids into infectedIds in the order they appear (first at index 0, last at the end) and return
true to indicate adding is successful.
If ids is null , return false to indicate adding failed without modifying anything. Do not do anything special
for null values inside ids .
1 public class Server {...}
public class Server {
...
public ArrayList
infectedIds;
...
}
public class Server {
...
public Server();
public boolean addInfectedIds(ArrayList
ids);
public ArrayList
getInfectedIds();
...
}
public ArrayList
getInfectedIds()
Return a deep copy of infectedIds . This means that you should create a new ArrayList and fill it with the
exact elements in infectedIds - this way, if someone modifies the returned list, the instance variable will not be
affected.
Note: we can assume that infectedIds will never be null when this method is called. Also, we would usually
see infectedIds as a private instance variable but we are leaving it as public for testing purposes.
Part 3: Student.java
Ideally, we would create a class representing phones to handle ID exchanges and a class representing students to
handle movements and COVID-19 test status, but for the sake of simplicity, we will just create one Student class, in
the file Student.java , to handle both ID exchanges and student-related functionality in this PA.
TODO: Instance Variables for Student
id 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 and
the 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 the
order 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 ArrayList
usedIds;
public ArrayList
contactHistory;
...
}
TODO: Methods to Implement for Student
We will implement all of these instance methods for the Student class to facilitate updating each object and for
doing some computations based on the current state of each object. Each method should have the behavior that is
specified and all instance variables should be updated or left unmodified as necessary so that future method calls
operate 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 indicate
that the student is not ready for simulation.
covidPostive and inQuarantine should be false , since we are assuming that all students are not infected
at 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 value
from 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 also
store 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 ArrayList
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 return
true .
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 object's usedIds list into the server , by calling server 's
addInfectedIds() 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 tested
positive). This should be done even if server is null .
Then, upload this Student 's used ids to server by calling uploadAllUsedIds() and return whether
uploadAllUsedIds() executed successfully or not. If uploadAllUserIds() cannot be called, return false too.
public ArrayList
getRecentPositiveContacts(Server server, int fromTime)
Get all "infected" IDs from the server by calling getInfectedIds() in the Server class (make sure you are not
directly accessing the instance variable), and check contactHistory against them. Return a sublist of
contactHistory where each ContactInfo in the sublist satisfies the following conditions:
its used is false
its id is in the "infected" ID list
its time is greater than or equal to fromTime
There are several invalid inputs or states. If any of these occurs, return null instead:
server is null
fromTime is invalid (i.e., it is negative)
getInfectedIds() returns null
public int riskCheck(Server server, int fromTime, boolean quarantineChoice)
Assess the student's 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 appropriate
arguments. If getRecentPositiveContacts() returns null , return -1 without proceeding.
2. Analyze this student's risk of having COVID-19 based on the recent positive contacts. Any ContactInfo
that results in this student being assessed as high-risk should be marked as "used" (the used instance
variable 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 less
than 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 this
condition 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 and
then return 1 regardless of quarantineChoice . If the student is not assessed as high-risk, return 0
instead.
Part 4: Simulator.java
Finally, we will need a Simulator class to simulate student interactions using the Exposure Notification System we
just built. Fortunately, we have written a Simulator for you in Simulator.java . Even though you don't need to
implement the Simulator, you still need to read through the Simulator class carefully and answer README
questions 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 lines
in the file have the same length, which represents the number of students in this simulation. For example, an input file
might have the following content:
Since each line has five numbers, we will have five students for this simulation. Each column contains all the data for
one specific student.
The first line shows each student's choice of whether going into a quarantine when they are notified of being in
contact 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 more
lines each.
In summary, this example input file means:
0,0,0,0,1 --> Five students and their choices for quarantine
1,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 Simulator
public class Simulator {
...
public ArrayList
students;
public Server server;
public Simulator(int num);
public void updateIds();
public boolean updateLocations(ArrayList
locations);
public boolean updateInfectionStatus(ArrayList
infections);
public int riskCheckAll(ArrayList
quarantineChoices, int fromTime);
public boolean exchangeInfo(Student student1, Student student2, int currentTime);
public int simulateOneDay(ArrayList
locations, ArrayList
infections, ArrayList
quarantineChoices, int time);
public static void main() throws IOException;
...
}
Tips
This PA is relatively complex and many methods depend on other methods, so debugging the whole program
would be hard. We highly recommend writing a main method or a test class for each class to test each method
individually. You will either need to delete the main method when turning in your assignment or ensure that
your 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. For
example, you need to call getRecentPositiveContacts() in riskCheck() . When we test your riskCheck() , we
will 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.
Style
Coding style is an important part of ensuring readability and maintainability of your code. We will grade your code
style in all submitted code files according to the style guidelines. Namely, there are a few things you must have in
each file/class/method:
1. File headers
2. Class headers
3. Method headers
4. Inline comments
5. Proper indentation (do not intermingle spaces and tabs for indentation)
6. Descriptive variable names
7. 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,
you’re fine)
9. Lines shorter than 80 characters (note, tabs will be counted as 4 characters toward this limit. It is a good idea to
set 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.
README
All the questions for the README portion of this assignment can be found on Gradescope. Note that this portion of
the assignment cannot be submitted late.
For this PA, README questions are about the Simulator class that we provide you, so you should read through
Simulator.java carefully before answering the README questions.
Survey
Please fill out this survey, worth 1 point to your PA grade, to help us improve the experience of this class!
Weekly Reflection 6.
Submission
Turning in your code
Submit all of the following files to Gradescope by Wednesday, Nov 18 @ 11:59PM PST (Thursday, Nov 19 @
11:59PM PST w/ slip day):
ContactInfo.java
Server.java
Student.java
When submitting, please wait until the autograder finishes running and read the output. Your code must compile in
the autograder in order to receive proper partial credit.
Evaluation
1. Correctness (80 points) You will earn points based on the autograder tests that your code passes. If the
autograder tests are not able to run (e.g., your code does not compile or it does not match the specifications in
this 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
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写 gr5280、代做 java/pytho...
2024-12-22
代写 data 编程、代做 python ...
2024-12-22
chc5049 代做、代写 sql 编程设...
2024-12-22
comp1038 代写、c++编程设计代...
2024-12-22
chc5028代做、代写c/c++设计编...
2024-12-21
代做program、代写sql程序设计
2024-12-21
itc228编程代写、代做java程序...
2024-12-21
代写comp 330 (fall 2024): as...
2024-12-21
代写busi2105 quantitative me...
2024-12-21
代做7ssgn110 environmental d...
2024-12-21
代做busi2105 quantitative me...
2024-12-21
代写csc 110 y1f fall 2024 qu...
2024-12-21
代做management accounting au...
2024-12-21
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!