Create an exception class called charexception

Assignment Help JAVA Programming
Reference no: EM132080031

You need help to write this Java code.

Step 1: The Char type Create a complex type called Char that models the primitive type char. In your class, you are going to want to have the following constructors:

Char(): Default constructor that sets the data section of the class to null (binary 0)

Char(char c): Overload constructor that takes a primitive char as an argument. It should set the data section of the class to the argument.

Char(int c): Overload constructor that takes a primitive int as a parameter. The data section of the class should be set as a character from the argument.

Char(final Char c): Overload constructor that takes the complex Char type as a parameter. The data section of the class should be set with the data section of the argument.

Char(String c): Overload constructor that takes a string type as a parameter. The data section of the class should be set to the first character in the string.

The class should have the following mutators:

void equals(final Char c): sets the data section to the data section of the argument. void equals (char c): sets the data section to the primitive argument.

void equals(int c): Sets the data section of the class as a character from the int argument.

Finally, it should have the following accessor functions:

char toChar( ): Returns the data section of the class as a char.

int toint( ): Returns the data section of the class as an int.

String toString( ): Returns the data section of the class as a string.

String to HexString( ): Returns the data section of the class as a hexadecimal valued string.

String add(char c): Concatenates the data section of the class with the parameter and returns the two characters as a string.

String add(final Char c): Concatenates the data section of the class with the data section of the parameter and returns the two characters as a string.

Step 2: Big Decimal

In Step 1 you created a class called Char that would do a few things with a char primitive type. In this assignment we are going to use the Char class to create another class called BigDecimal. What this means is that you are going to store digit characters in your Char class and then add new instances of the Char class to create a BigDecimal.

The BigDecimal class is going to need a way to hold all of the Char classes that you add to it so you might want to consider using a vector. I realize that the vector class in Java is somewhat going away so if you are using Java you might want to consider using the ArrayList. From this point forward I will refer to ArrayList and vector as a container. This way I don't have to keep typing both.

Your BigDecimal class should have the following constructors

BigDecimal() - default constructor should simply set your contianer to three Char objects that contain the values '0' '.' '0'

BigDecimal(String value) - This constructor will parse the string taking each digit, putting it into a new Char and adding the Char to the container.

Your BigDecimal class should also contain the following mutators

void equals(char ch) - A char that contains a digit

void equals(String value) - This does the same as the overloaded constructor that takes a string BigDecimal add(BigDecimal) - Adds the values together and returns the result as a Big Decimal

BigDecimal sub(BigDecimal) - Subtracts the two values and returns the result as a BigDecimal

Accessors

double toDouble() - Returns the value stored in the container as a double

String toString() - Returns the value store in the container as a string

Char at(int index ) - Returns the value at the particular index as a Char

Caveat:

If you are using C++ your container must hold pointers to the Char type. This means when you push something back you need to do the following:

v.push_back(new Char('A'));

Java you will use references but the principle is the same. Simpy add a new Char to whatever container you are using.

al.add(new Char('A'));

Other requirement Before adding anything to your container you must determine if the value is actually a digit. If it is not then simply stop processing characters at that point. You are also to make sure that not more than one decimal is placed. Basically I am asking you to have a container that has a well formed number

Step 3: File IO

Make a change to your BigDecimal class to add the following functions (methods)

int wholeNumber() - Returns only the whole number portion of the decimal number as an int

double fraction() - Returns the fractional portion of the number as double

File IO:

Attched at this link is a text file called Numbers.txt (29.06367626098403, 42.77383737710885, 18.091887775083933, 26.00580851301579, 27.373385841524737, 22.950838262579364, 47.85003022494251, 16.75963522818282, 25.391047068576892, 41.621203024474184, 38.900829007904846, 14.965562131729882, 47.35966664937554, 34.6930055816334, 21.34083393290269, 24.625973137349234, 36.55015550385545, 28.61793131915871, 47.03503184700058, 22.547129989077735, 10.354255998374677, 40.52960355378197, 15.75798738892007, 41.98802541051023, 21.99447227641024, 12.71895402779139, 49.55661770604053, 26.943287240700332, 21.95282854310205, 17.761331235258112, 34.002798218501866, 47.84746733126361, 27.415554160228197, 46.11786972785617, 13.324341005546945, 23.120903887553567, 39.47614755169381, 49.79141807347378, 10.9731646951434, 30.860109966679794, 15.534548830877451, 43.62518709231083, 28.009830889595854, 21.108498174931487, 28.2754866585608, 40.090046809711126, 48.75388489987637, 11.526037728040004, 42.804356199727316, 13.91424071187037, 16.469792068115883, 27.909261045927728, 39.96432932482341, 39.667083736782445, 11.428556219500905, 15.895850033803791, 26.553672610564945, 18.416038099956552, 29.505409962862505, 21.320833577401142, 42.107587943537894, 48.8343505932619, 21.54430566771293, 34.07427119598432, 37.10419388483666, 23.64427640874803, 12.040217405085665, 13.943061062971594, 18.8995846758003, 44.038699943040534, 10.260600603046823, 46.80237313058899, 19.39219791843417, 22.731791971681012, 17.74766240052677, 35.654991664020585, 32.362062478869966, 30.547148289363765, 43.21339135470416, 13.399660410165598, 18.62578371032339, 11.959677922579303, 19.159640468250792, 32.842365048917856, 23.59345678949312, 11.76529688361792, 34.125837416351125, 44.347266133413854, 34.50899676465603, 18.060331516647715, 30.28722659860124, 12.65683182133535, 23.600692449266532, 15.97031384953457, 28.196863056514214, 31.793519156761526, 38.564105527709465, 22.0756827947849, 28.784868846667454, 10.588169721472148.

Read in each of these numbers and store them in your BigDecimal class. Basically you are going to need a BigDecimal class for each number that is in the file. Store each BigDecimal in some kind of container like a vector or an ArrayList.

Once you have all of the numbers loaded use a loop to write out all of the numbers into two separate text files. One file called wholeNumbers.txt will hold the whole number portion of the number. The other file call fraction.txt will hold the fractional portion of the number. Make sure you include the decimal point.

Open each of the files in Note Pad and make sure that you have one number per line.

Step 4: Exceptions

Create an exception class called CharException to be thrown in the equals function that takes an int as a parameter. You should check the range of the int to make sure it is a valid readable character. Basically if the parameter is less than 32 or greater than 127 you want to throw a CharException with the message "Invalid Character".

Java: Use inheritance to extend your class from Exception. Create a constructor that takes the message to be set. You are going to have to call the super constructor to make sure the message is set properly. Use the getMessage method to display the error message you set.

Finally:

Create a BigDecimalException class that is derived from the CharException class. You should throw this exception anytime that a character is being set that is not a valid character (a digit or a decimal). You should also throw this excpetion if more than one decimal is being set. Use inheritance.

Reference no: EM132080031

Questions Cloud

Write a verilog module for an odd parity generator circuit : Write a Verilog module for an odd parity generator circuit. The data message is 4 bits. Use Verilog bitwise operators. Do not use always blocks.
Prepare journal entries to record the transactions : Tin Inc completed sales transaction with a company, specifically on november 1 2007, Tin inc sold 60,000units of its november product.
Why might this be important to point out for descartes : Descartes mentions that he is concerned "not with acting, but only with knowledge." Why might this be important to point out for Descartes?
Organization external opportunities and threats : What are an organization's external opportunities and threats? What impact do these have on the organization's strategy?
Create an exception class called charexception : Create an exception class called CharException to be thrown in the equals function that takes an int as a parameter.
Compute ending inventory at cost : Net markdowns were $8,200; and sales revenue was $151,200. Compute ending inventory at cost using the conventional retail method
What is the inflation adjusted amount : A TIP was auctioned on April 1, 2017 at an interest rate of 0.450%, maturity April 1, 2027, face amount of $10,000,000. The semi-annual inflation rate.
Write an sql statement to display data for all of the column : Write an SQL statement to display data for SKU_Description and SKU. Write an SQL statement to Create A View to display data for unique WarehouseIDs.
Prepare a single-step income statement : Summary operating data for Eco-Windows Company during the current year ended June 30, 20Y6, Prepare a single-step income statement

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd