fbpx

The King is pleased with your loyalty and service. To reward you, he shows you a bag of gemstones (pearls and opals) and tells you that you may have all the pearls or all the opals, if you can tell hi

The King is pleased with your loyalty and service. To reward you, he shows you a bag of gemstones (pearls and opals) and tells you that you may have all the pearls or all the opals, if you can tell him which is worth more. You are given this information:

1.   “gems.txt” is a file containing one line for each gem. The line says “opal” or “pearl” and the diameter of the gemstone, in millimeters (a double). There are a lot of lines in the file, with pearls and opals mixed in together. Sample input lines:

opal 2.35

pearl 3.7

2.    The static functions exp(double) and pow(double, double) are defined in java.lang.Math.

3.    The estimated value of a pearl is exp(diameter/2) − 1 (Really! that is what they sell for.)

4.    The estimated value of an opal is 8.33 ∗ diameter2

Write a Java program to find out which collection is worth more. Implement these classes:

1.    The Gem Class.

This is part of the model for the application. Implement the following members:

(a)    Data members for the type of gem, as a String (“pearl” or “opal”), its diameter (mil- limeters) and its estimated value, which you will compute.

(b)    A public constructor with two parameters (gem type and diameter). It will call one of the functions below and use the parameters and the answer to initialize the new object.

(c)    Private functions calcOpal() and calcPearl() that use the diameter to calculate the value of a gem. Return the value.

(d)    A toString() function that will neatly format the three data members of the gem. Format the dollar amounts to two decimal places.

(e)   Any get-functions (accessors) you need, but NO set-functions (mutators).

2.   The Treasure Class. This is the controller class for the application. You may put your main function here. In addition, implement the following members and anything ELSE that you need:

(a)    A Scanner for reading the input file, “gems.txt”.

(b)    An ArrayList for holding the pearls. A second ArrayList for storing the opals.

(c)    A function that reads the file, constructs Gem objects, and stores each object in one of the collections.

(d)    A printGems() function, whose parameter is one of your collections. It prints a list of the gems in the collection. Print the dollar amounts to two decimal places. Delegate the formatting to the Gem class. While calculating their total value. RETURN, don’t print, the value of the collection.

(e)   An evaluate() function that calls the printGems() function twice, First call it to print the pearls and print their total value. Then call it again to print the opals their total value. Finally, print a statement about which collection is the most valuable.

Exam 1 – Practical: February 14–18, 2014  CSCI 6617 Java Programming               2

3.    Submission.

Submitting your work properly is part of following instructions.

(a)    Capture your screen output and paste it into a text file in your project directory. DO NOT USE a .doc or .docx file

(b)    Zip or rar the entire project directory, with the output.

(c)    Email the zipped file to my home email address.

(d)    Save a copy on your own machine until you get the ”Got it!” message.

Assessing The King’s Gems.                                                                                                                                                                   (30)

The Exam 1 program will be graded on the following criteria:

1.    (12) Design Principles and Style

•   (2) The program implements the instructions fully, using reasonable techniques.

•   (2) All data members are private. There are no set functions.

•   (2) Each class has the appropriate parts, that is, parts that belong in class B are in class B not in class A.

•   (2) Constructors are written and used appropriately.

•   (2) Appropriate built-in Java classes and data structures are used.

•   (2) Indentation and blank lines are reasonable and consistent. Names are reasonable. There are comments in the program. They add to the clarity. They don’t clutter it or mislead the reader.

2.    (18) Functionality and Correctness

•   (2) The file is opened correctly and opening exceptions are handled properly.

•   (2) The file-read loop and end-of-file are handled correctly.

•   (2) The program will work for a data file with more or fewer gems in it.

•   (2) All gems appear in the output exactly once.

•   (2) The calculated value of each gem is correct and the total values and final answer are correct.

•   (2) The program runs to completion.  It does not go into an infinite loop or abort with an avoidable exception.

•   (2) Output is provided. The code is provided. Both are in a zipped file sent by email.

•   (2) The printGems() and evaluate functions output a list of gems with two neat columns.

•   (2) Money amounts that look line money, with two decimal places. Decimal points should be lined up.

"Looking for a Similar Assignment? Order now and Get a Discount!

"Looking for a Similar Assignment? Order now and Get a Discount!

Have a subject expert Write for You

Have a subject expert finish your paper for You

Edit My Paper For Me

Have an Expert Write Your Dissertation's Chapter

Scroll to Top