In this HW, you will begin to practice good modular decomposition and class design. No longer should a program all reside in main(). Instead, you should create different classes in each program, where each class provides one important function. For this assignment in particular, you'll gain practice using conditional statements and you'll create a simple, interactive graphical application for some initial experience with event handling.
On the last two assignments, you began to learn about javadoc, but comments simply focused on class headers. In this assignment, you'll learn about documenting class member variables and methods.
In your class, you should precede each member variable with a javadoc comment that describes how that variable is used by the class. The variables name and completedPasses are examples below. Next, start each method with a comment that tells what that method does, just like you did for the class. Javadoc also recognizes special commands called tags that denote important information for the web page being generated. Two of those tags will be used in method comments.
@param paramName description @return returnValue descriptionFor example, consider the following code:
// Quarterback.java
// Brett Favre (gtg600m)
// Collaboration: I worked on this myself.
import java.util.Random;
/**
* <Description for the whole class>
* @author Brett Favre
* @version 1.0
*/
public class Quarterback {
/** <Description of this member variable> */
private String name;
/** <Description of this member variable> */
private int completedPasses;
/**
* <Description of what this method does>
* @param howFar <Description of first parameter>
* @param numSpirals <Description of second parameter>
* @return <Description of the return value>
*/
public double interception (double howFar, int numSpirals) {
return howFar/completedPasses * numSpirals;
}
}
When doing inventory management, a concern is always that product information be entered correctly. When products have identifiers that are long lists of numbers, this is an especially important concern. One way to better insure that a correct ID is entered is to perform some kind of validation or checking of the ID. The checksum technique tests whether the digits of an ID follow some particular property.
One ID that you are likely familiar with is the Universal Product Code (UPC) that most manufactured items now have. A sample UPC symbol is shown below.
A UPC is a 12-digit value that meets the following criteria:
A special case occurs when r is 10 and the last digit is a zero. You should consider this a match and a valid UPC.
For example, consider the UPC above. Here m = 9 + 1 + 5 + 9 + 0 = 24, n = 7 + 0 + 4 + 1 + 7 + 4 = 23, and r = 10 - ((24 + 69) mod 10) = 10 - (93 mod 10) = 10 -3 = 7. Because r is the same as the 12th (last) digit, then this is a valid code.Your objective is to write a program that prompts the user to enter a numeric value, and then you determine whether that value is a valid UPC number or not. You should print out a string with your decision. You can assume that the user will enter a positive integer, but you should think about many different ways that the value will not be a UPC number. Make sure to decompose your program into different classes in order to help break the problem into manageable pieces, ie, following the principles of encapsulation and modular decomposition. Note that this is a command-line program, not a GUI.
Requirement: Call your class in which execution begins in main() UPCchecker.
Hint: What's the largest valid java int value?
In this assignment you will build a simple GUI application that calculates which day of the year a particular date is. For example, for the date 12 29 2005, the correct day of the year is 363.
You should build a GUI application that has a type-in text field for the user to enter a date. Correct dates are entered as month (1-12), day (1-31, depending on what month it is), and year, with the three fields separated by whitespace, e.g., 8 28 1961 or 7 4 1776. The GUI then should also have a text label that displays what the day of the year is (1-366).
To calculate the day of the year, you need to figure out how many days are in each month. For most months that is easy, but February is a little tricky, however. February typically has 28 days except for leap years when it has 29. All years evenly divisible by 4 are leap years, except for years evenly divisible by 100 that are not also evenly divisible by 400. So 2004 is a leap year and so is 2000, but not 1900.
You can assume that the input to you from the text field will be reasonable, that is, you can assume that it will be three integers. But obviously you still need to do a little error checking as the user may enter 13 as the month, for example. But you need not worry about the user entering letters or floating point values or anything like that.
Requirement: Call your top-level class (one with main()) DateFinder.
Hint: Examine the programs at the end of Chapter 4 for assistance with the GUI aspects of this assignment.
After you have finished the above assignments, turn them via Webwork You will be submitting multiple files. Please make sure they are named as shown below: