Your first Java programming assignment is to write an application that uses a class. The goal is to start by giving you some practice with Java syntax and making sure that you understand the class concept.
Before starting this assignment, you should should become familiar with the Java programming environment on sirah.
You may also use Java compilers on other systems if your prefer, or a programming environment such as J++ or Cafe'. But if you use a programming environment, do not use it to generate code for you. Also see the tutorial materials for links to download an editor such as JavaEdit or TextPad for use on a PC.
Writing the programs
Choose one of the following two sets of programs to write.
Choice 1: Writing and Testing a class Candy
Design and implement a class to represent pieces of candy. There will be three instance variables to represent properties of the candy:
Write a constructor method that takes three arguments that are used as values to initialize the instance variables.
You should also write the following public methods.
You must also write a test program for this class:
Design an application that prompts the user to type in the shape, color, and flavor of at least two pieces of candy. Create an instance of the Candy class for each one. Combine the two pieces to get a third piece of candy and either use the "get" methods or the "toString" method to print out a description of the result.
Show a couple of runs of the program. Be sure to demonstrate a case of successfully combining candies and also one which doesn't because the combine gives an Exception.
Choice 2: Writing and Testing a class DataSets
Design and implement a class to represent a set of data, that is a number of experimental numbers representing some value. You will need an instance variable to keep the data:
Write a constructor method that takes two arguments: an int n that is used to create the data array to be of length n, and an array of doubles of length n. After creating the data array, the constructor should copy the argument array to the data array to initialize it.
You should also write the following public methods.
You must also write a test program for this class.
Design an application that prompts the user to type in at least two sets of double values. Create an instance of the DataSet class for each one. Compute the mean and standard deviation of each dataset and print the results. Then combine the two DataSets to get a third one and print out its mean and standard deviation.
Show a couple of runs of the program. In a case where you refuse to combine some datasets, be sure to demonstrate that part.
What to put on the homework page as the submission of your homework
Submit your assignment by linking the description of your program, a link to the Java source code and a small file showing sample output run (like my .run files) to your homework page.
For how to write a description of your homework and document your program, and other information, please see these homework guidelines.
Grading
For this assignment, there will be a total of 15 points. These will be separated into partial points of 5 and 10 as follows: