



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Gries; Class: Introduction to Computing Using Java; Subject: Computer Science; University: Cornell University; Term: Spring 2009;
Typology: Assignments
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Markus Hanhisalo of Helsinki University of Technology defines a computer virus as: “a program, a block of executable code, [that] attaches itself to overwrite or otherwise replace another program in order to reproduce itself without [the] knowledge of a PC user.” (reference: http://www.tml.tkk.fi/Opinnot/Tik-110.501/1997/viruses.html) Computer viruses are often designed to maliciously corrupt or steal data from individuals. Sometimes, they cause computers to stop working all together. Computer viruses are different from computer worms. A virus attaches itself to other programs, while a worm is a self-contained program that spreads copies of itself to other computers without attaching itself to other programs. Some viruses and worms that come as attachments in an email appear to be jpg files —for example, MerryChristmas.jpg! But if your computer properly displayed file extensions/suffixes, you would see that this is really a file named MerryChristmas.jpg.exe, and clicking on it would cause it to execute, firmly embedding itself on your computer. Fix your operating systems preferences so that extensions/suffixes always show! The first computer worm of any consequence was set loose by a Cornell computer science grad student. In Nov. 1988, Robert Morris wrote a worm —not to cause damage but to get an estimate of the size of the internet. He made a big mistake. When the worm reached another computer, it did not check to see whether it was already on that computer but just invaded the computer and sent itself on to other computers. So it spread much much faster than he thought it would. Anywhere from 6,000 to 60,000 computers were infected, and the internet was brought to its knees. Damage was estimated at $10M to $100M. Morris was convicted of violating the 1986 computer fraud and abuse act. He ended up on probation and owed a hefty fine plus community service. You can read more on Wikipedia. David Gries and Juris Hartmanis, of the Cornell CS Department, were on a Cornell commission that investigated the Morris worm. You can read about it in this article. Because viruses and worms are so dangerous, people often wish to monitor them in order to help curtail their growth and spreading. Your task in this assignment is to develop a Java class Virus to maintain information about a virus, plus a JUnit class VirusTester to maintain a suite of testcases for Virus. This assignment will help illustrate how Java’s classes and objects can be used to maintain data about a collection of things –like computer viruses. Read the whole assignment before starting. Follow the instructions given below in order to complete the assignment as quickly and as efficiently as possible. HELP If you don't know where to start, if you don't understand testing, if you are lost, SEE SOMEONE IMMEDIATELY —the course instructors, a TA, a consultant. Do not wait. A little one-on-one help can do wonders. Class Virus An instance of class Virus represents a single computer virus. It has several fields that one might use to describe a computer virus, as well as methods that operate on these fields. Here is a description of the
fields, all of which should be private (you can choose the names of these fields). name (a String) target, meaning the kind of computer the virus can infect (a char: 'W' for windows, 'M' for Mac, and 'L' for the rare Linux virus) month of discovery (an int) year of discovery (an int) id number (an int: a number used to reference this Virus in a database under development) predecessor (a Virus —the name on the tab of the folder of the Virus object from which this one “evolved”) number of variations (an int: the number of known viruses that directly evolved from this one) Here are some details about these fields. The name is a string of characters.Two viruses may have the same name. This could happen due to analyst error. The month of discovery is in the range 1..12, representing a month of the year. The year of discovery is something like 1997 or 2005. Do not worry about invalid dates. That is, do not write code that checks whether dates are valid: assume they are valid. The id number is an index into a database. Assume all tags given are unique. Do not write code to check whether a virus with a given id number already exists. If a virus hasn’t been assigned an id number yet, this field should contain -1. The predecessor is the name of a Virus object (manilla folder) on which this virus was based or from which it evolved. It is not a String but (the name of) another Virus object. (Someone might have gotten a copy of an old virus and changed it a bit, so it looks like a new virus but it's easy to see that it was generated from another one. Also, a computer virus might evolve on its own.). The predecessor is null if either the predecessor is not known or this is an original virus. The class invariant. Accompanying your declarations of these fields should be comments that describe what each field means and what constraints hold on the field. For example, on the declaration of the field target, state in a comment that the field represents what kinds of computers the virus infects, 'W' for Windows, etc. The collection of the comments on these fields is called the class invariant. The class invariant describes all legal values for all the fields. Whenever you write a method (see below), look through the class invariant and convince yourself that its exection leaves the class invariant true. The Wurmark-D worm (Jan 05) travels as an email attachment. It pretends to be amusing, but it installs itself on your computer and forwards itself to others. The MCaffee website us.mcafee.com/virusInfo/default.asp contains information about recent threats by worms and viruses and trojan horses. Have a look at it. Some emails go around the internet warning you about other emails that contain "virtual cards for you" -- click on them, it says, and you will destroy your hard disk. Some of these warnings are real, others are hoaxes. Virus Methods Class Virus has the following methods. Pay close attention to the parameters and return values of each method. The descriptions, while informal, are complete and precise. Constructor Description
isOlder(Virus v1, Virus v2) Static method. = "v1 and v2 are not null, and v1 is older than v2 —i.e. v1 was discovered before v2". (a boolean) The names of your methods must match those listed above exactly, including capitalization. The number of parameters and their order must also match. The best way to ensure this is to copy and paste from this handout! Our testing will expect those method names, so any mismatch will fail during our testing. You are free to use any parameter names that you want. Read page 371 of the text for conventions on parameter names. Each method MUST be preceded by an appropriate specification, or "spec", as a Javadoc comment. The best way to ensure this is to copy and paste. After you have pasted, be sure to do any necessary editing. For example, the spec of a function does not have to say that the function yields a boolean or int or anything else, because that is known from the header of the method. A precondition should not be tested by the method; it is the responsibility of the caller to ensure that the precondition is met. For example, it is a mistake to call method setPredecessor with null for the predecessor argument. However, in function isOlder, the tests for v1 and v2 not null MUST be made; it is not a precondition but part of what must be tested. It is possible for virus v1 to be v2's predecessor and visa versa, at the same time. We do not check for such strange occurrences. In writing setPredecessor, be careful! If P is becoming the predecessor of this Virus, then P has one more variation, and the field of P that contains its number of variations has to be updated accordingly. Do not use if-statements. Use conditional expressions (...? ... : ...) only in function toString. Function toString We illustrate the required format of the output of toString with an example and then make some comments. Here is an example of output from function toString: "W computer virus Superfun. Id 34. Discovered 6/2005. Has 2 variations." Here are some points about this output.
the different results that can arise when other methods are called before and after this method, and so on. Important point: If an argument of a method can be null, there should be a test case that has null for that argument. Important point: Every part of a method should be tested by at least one test case. Therefore, a method with a conditional expression (b? e1 : e2) requires at least two test cases, one for when b is false and one for when it is true. Test each method (or group of methods) carefully before moving on to the rest of the assignment. How to do this assignment First, remember that if-statements are not allowed. If your assignments has if-statements, you will be asked to revise the assignment and resubmit. Second, you should develop and test the class in a methodologically sound way, which we outline below. If we detect that you did not develop it this way, we may ask you to start from scratch and write some other assignment. First, start a new folder on your hard drive that will contain the files for this project. Start every new project in its own folder. Second, write a class Virus using DrJava. In it, declare the fields in class Virus, compiling often as you proceed. Write comments that specify what these fields mean. Third, start a new JUnit class, calling it VirusTester. Fourth, this assignment should properly be done in several parts. For each part, write the methods, write one test procedure in class VirusTester and add test cases to it for all the methods you wrote, and then test the methods thoroughly. Do not go on to the next group of methods until the ones you are working on are correct. If we determine that you did not follow this way of doing things —for example, you wrote all methods and then tried to test, we may ask you to set this assignment aside and do another instead. Here are the groups of methods. (1) The first constructor and all the getter methods of class Virus. (2) The second constructor. (3) Function toString. (4) The setter methods. (5) The two comparison methods. At each step, make sure all methods are correct before proceeding to the next step. When adding a new method, cut and paste the comment and the header from the assignment handout and then edit the comment. It must have suitable javadoc specifications as well as suitable comments on the field declarations. The assignment will not be accepted for testing until it does. Other hints and directions Do not use if statements. Remember that a string literal is enclosed in double quotation marks and a char literal is enclosed in single quotation marks. Be sure to create the javadoc specification and look at it carefully, to be sure that the methods are specified thoroughly and clearly. Procedure for submission You may submit the assignment whenever you wish. We will look at it in several steps.