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

  Simulate a scenario with two server windows

Simulate a scenario with two server windows and two queues. When a group of customers arrive each individual in the group will choose the same queue.

  Does the language include an arraylist structure

Does the language include an ArrayList structure? If so, how does it differ from ArrayLists in other languages, such as C#?

  Display the program output of the collision results

According to my lecturer, I need the tutor to display the 'program output' of the collision results implemented by BirthdayAttack.java in a output.txt file. Can the tutor do this?

  Which of the following compile

Which of the following can fill in the blank in this code to make it compile?

  Write a program to generate prime numbers

Write a program to generate prime numbers. Specifically, prompt the user for how many prime numbers to find and generate that many prime numbers.

  Write a javascript program that will print prime numbers

Write a JavaScript program that will print all the prime numbers between 1 and 100. You will need to use looping and functions.

  Java data structures

Project is to create a German-English, English-German, French-English, English-French dictionary. You will be responsible for entering a total of twenty-five words in German, the part of speech each word represents and its English meaning. Please use..

  Create a class named integerset.

"The fourth array set is named fourthArrayName and was created by calling Method intersectionOfSets on the first two sets. It represents this set of numbers: { value1, value2, value3, valuen }." (Again note: that each number of the array is follow..

  Create an array of objects and fill it from a file

CS1110- create an array of objects and fill it from a file or the user input. All manufacturers have the same basic elements in the televisions they produce as well as many options.

  A complete java program called stringreverse

Create, using NetBeans, a complete Java program called StringReverse that prompts the user at the command line for one 3-character string, then prompts the user for another 3-character string, prints out the two input strings with a space between the..

  Use java or c++ to create a program for making the pizza

Make the Pizza example abstract, so that there are three kinds of factories under one AbstractPizzaFactory You can use Java or C++

  If the number on two of the players'' four cards

If the number on two of the players' four cards is the same and the number on the remaining two cards is also the same yet the number on all four cards in not the same then the player gets their bet back and in addition wins 22 chips for each chip th..

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