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,

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.

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
The price is based on these factors:
Academic level
Number of pages
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!