Design a class from a problem description

Assignment Help Software Engineering
Reference no: EM133535545

Object-Oriented Programming Fundamentals

Java Programming Assignment

You will, using object-oriented principles, design a class from a problem description and implement it as a working Java program.

Specifically, you are tasked with implementing a class that will convert numbers to and from base-26 (Hexaicosadecimal).

The Problem

You'll all be familiar with our normal base-10 (decimal) number system:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

You should also be familiar with base-2 (binary), in which there are only two values:

0, 1

There are several other number systems that are important to computer scientists, including base-8 (octal):

0,1,2,3, 4,5, 6,7

And base-16(hexadecimal):

0,1,2, 3,4,5, 6,7,8,9,a,b,c, d,e,f

I've got a typewriter on which, unfortunately, all the number keys are broken. But I still wantto do maths! Luckily, all the letter keys work, so I've got a handy set of 26 symbols laying around.SoI'm in luck:All I have to do is write out my numbers in base-26(hexaicosadecimal)!

Part I: Create your "test harness"
We'll get to maths in a minute. First, you should create the main() function that you can use to test your program. Create a new class called HexiacosadecimalNumber. Within that class, create your main() function. The main function should behave as follows:

First, it should ask the user to indicate what mode it should be in. If the user types ‘h' or ‘H', the program should ask them to input a hexaicosadecimal number (that is, a String). The program shouldthenreadthat numberinto a variable,andprintitbackto thecommandline(for now). If the user types ‘d' or ‘D', the program should ask them to input a decimal number (that is, a double). The program should then read that number into a variable, and print it back to the command line (for now). If the user types ‘q' or ‘Q', the program should exit. If the user types anything else, the program should display the message "INVALID INPUT", and then prompt the user again. The program should then ask the user again what mode it should be in, and repeat the process until the user types ‘q' or ‘Q' at the prompt.

To accomplish this, you will need to use a Scanner object in combination with a loop containing an if-else block.

PartII: Add your attributes and methods
Your HexaicosadecimalNumberclass should know how to express a number in both hexaicosadecimal and decimal. To do this, it should have two attributes: stringRepresentationand doubleRepresentation. (What types should these variables be, and what should their access modifiers be?)

Your HexaicosadecimalNumberclass should have two constructors, both of which will populate the two attributes appropriately. One will take as input a String (representing a number in hexaicosadecimal), and the other will take as input a double. Both methods have to populate both attributes.

You might now be thinking, "How do I populate both attributes when I only have one representation as input to the constructor?" You will need two helper functions: hexaicosadecimalStringToDouble(String in) and doubleToHexaicosadecimalString(double in). You should call these functions in your constructors as needed.

You should also override the toString() method of HexaicosadecimalNumber. This is a special method that belongs to Java's Object() class, from which all other classes - including HexaicosadecimalNumber- are derived. The signature of the toString() method is

Now, I've gotten pretty good at thinking in hexaicosadecimal, but I keep getting bad grades in maths because nobody else can understand it! Your job is to help me out by writing a Java program that can convert numbers from base-10 to base-26 and vice versa.

public String toString()

As you can see from the method signature, this function is public, takes no arguments, and returns a String. This function is called automatically when an object of that class is printed, for example by System.out.println().The string should be in the following format:

stringRepresentation (doubleRepresentation)

That is, if your hexaicosadecimal number object is named temp and contains the value abcde
(for which the equivalent decimal representation is 19010.0; check this later!), the result of

calling System.out.println(temp) should be
abcde (19010.0)

For the two "helper" functions - hexaicosadecimalStringToDouble(String in) and doubleToHexaicosadecimalString(double in) - just have them return "dummy" values for now. (I.e. return 0.0 from the first function, and "NOT IMPLEMENTED" from the second.) At this point, you should have a complete working program (that doesn't do much). Compile and run your program. If you encounter errors, fix them before continuing.

Part III: Convert from a natural hexaicosadecimal number to a double
Your next step is to convert a "natural" (that is, whole and zero or positive) hexaicosadecimal number to its equivalent decimal representation. (Where should this code go? Hint: You shouldn't create any more methods than you already have.) We'll start with just natural numbers for now to keep things simple, but eventually we'll be dealing with hexaicosadecimal numbers that are floating point - like floating.point - and/or negative - like -negative.

The algorithm for doing this might look something like:

accumulator = 0
for each character in the input String from left to right
baseValue = the integer equivalent of the current character
accumulator += baseValue * 26length of the whole String - (index of the current character + 1)
return accumulator

This is relatively straightforward using appropriate methods from the String class and the Math class, but computing "the integer equivalent of a character" can be a little bit tricky if you've never seen it before.

One thing to note is that characters in Java use the Unicode standard, which in turn contains the ASCII standard (a table of ASCII characters can be found here:

Another thing to note is that characters in Java are equivalent to their character code. (That is,
char c = ‘a'; is exactly the same as char c = 97.)

A third thing to note is that the characters in ASCII are arranged in order. (That is, a = 97, b = 98, c = 99...z = 122).

A fourth thing to note is that while ‘a' (97) and ‘A' (65) have different character codes, you already know a convenient function that can ensure that your hexaicosadecimal string is all lowercase (or all uppercase, if you prefer), regardless of how it was typed in.

If you take all these points together, you should be able to extract a single character from the input string and convert it to its equivalent hexaicosadecimal value (That is, a/A = 0, b/B = 1, c/C= 2, ... z/Z = 25) simply. (By "simply" I mean one or two short lines of code; if you find yourself wanting to use more than this, perhaps go back to the drawing board.)

Part IV: Convert from a floating point hexaicosadecimal number to a double (20 marks)
The next step is to expand our hexaicosadecimal converter to take not just natural numbers, but floating point (a/k/a rational) numbers. The good news is that you're already halfway done, with your work from the previous section!

What you need to do is wrap your code from the previous section in an if-else block. IF (the input string does not contain a decimal point), do exactly what you did before. IF (the input string DOES contain a decimal point), do what you did before, except where your code had "the length of the whole string", you'll instead need "the length of the part of the string that comes before the decimal point." That will get you the whole number part of the number. Then you'll need a second loop that looks just at the part of the string that is to the right of the decimal point, and adds those values into the accumulator. (Hint: Negative exponents correspond to dividing instead of multiplying. That is, 10-1 = 0.1 and 26-1 = 0.03846, 10-2 = 0.01 and 26-1 = 0.001479, and so on.)

Part V: Convert from a NEGATIVE WHOLE NUMBER OR FLOATING POINT hexaicosadecimal number to a double
Extend your solution from Part VI to enable conversion of NEGATIVE (that is, beginning with "-") hexaicosadecimal numbers to doubles.

Part VI: Convert from a double WITHOUT A FRACTIONAL PART to a hexaicosadecimal string
Much like we did with the other method, we're going to start by solving this problem for the situation of a double that does not have a fractional part - that is, with nothing to the right of the decimal point - and get that working first. Only then (in the next section) will we proceed to solve the general problem of doubles with a fractional part.

The algorithm for doing this might look something like:

temp = the input double converted to an integer type stringAccumulator = ""
while (temp > 0)
currValue = the remainder when temp is divided by 26
c = currValue converted to the corresponding ASCII value put c at the beginning of stringAccumulator
temp = the quotient when temp is divided by 26 return stringAccumulator

(NOTE: doubles can contain much bigger values than integer types like int or even long. For the purposes of Part V, you can assume that the value of your double safely fits within the integer type you are using.)

you can use the equivalent class. For example, there is a class Integer that provides convenience methods for working with ints, a class Double for working with doubles, a class Long for working with longs, and so on.

Part VII: Convert from a double WITH OR WITHOUT A FRACTIONAL PART to a hexaicosadecimal string
Again, we're building on our solution from Part VI, in which we solved for a double that did not have a fractional part. We're about to relax that restriction, so now our input doubles can have a fractional part as well as a whole number part.

First, we have to get the fractional part. In Part VI, we got the whole number part by converting the double to an integer type. To get the fractional part, all we have to do is subtract the integer from the double.

If the fractional part is zero, the solution is the same as in Part VI. If the fractional part is NON- zero, things get a bit trickier. There are multiple ways to solve this problem, but the easiest one is to essentially use the same method we did in Part V. However, before we can use that same algorithm, we have to convert the fractional part to a corresponding integer type value. (For example, if the fractional part was 0.25, the corresponding integer type value would be 25; if the fractional part was 0.12345, the corresponding integer type value would be 12345. In short, you need to move the decimal point to the right end of the number.) If we could do that, we'd be set; we'd just be able to run the algorithm from Part V once on the whole number part, put a "." in the middle, and then run it again on the corresponding integer for the fractional part.

I'm leaving the rest to you. There are a number of ways to generate the corresponding integer values for a fractional part. You have all the tools you need already; it can be done in a handful of lines with just a loop and basic Java mathematical operations. (But a more elegant solution might be found if you look into other Java classes, such as the BigDecimal class...)

Part VIII: Convert from a NEGATIVE double WITH OR WITHOUT A FRACTIONAL PART to a hexaicosadecimal string

Extend your solution from Part VII to enable conversion of negative doubles to hexaicosadecimal strings.You will, using object-oriented principles, design a class from a problem description and implement it as a working Java program.

Specifically, you are tasked with implementing a class that will convert numbers to and from base-26 (Hexaicosadecimal).

Attachment:- Programming Assignment.rar

Reference no: EM133535545

Questions Cloud

What population was the test designed for : PSY 625- What does the test measure (include scales)? What does the test predict? What population was the test designed for (e.g., age, type of person)?
Discuss the application of the fraud triangle or similar : The application of the fraud triangle or similar model In an article found on the Wall Street Journal, the U.S. Department of Homeland Security discovered three
Create a survey naturalistic observation or experiment : Create a survey, naturalistic observation, or experiment that will test your hypothesis. Write the method section of your research study.
Explain how, as activity increases, the cost function change : briefly describe variable, fixed, and mixed costs and explain how, as activity increases, the cost function changes for each type of cost.
Design a class from a problem description : CSE1OOF Object-Oriented Programming Fundamentals, La Trobe University, Java Programming Assignment - design a class from a problem description and implement
Why did author select binary logistic regression in research : Why did the authors select binary logistic regression in the research? Do you think this test was the most appropriate choice? Why or why not?
Identify treatment programs in your community for persons : Identify treatment programs in your community for persons with coexisting disorders and discuss ways programs provide seamless co-occurring treatment practices.
Why research important based on defined purpose of research : What you have learned from the first three chapters. In other words, why is research important based on the defined purpose of research?
Summarize the topic highlighting the key points on the video : Summarize the topic highlighting the key points on the video. Explained at least one point you have learned or had a different understanding.

Reviews

Write a Review

Software Engineering Questions & Answers

  Importance of udp and the relationship to tcp

Discuss and explain what the UDP does and its relationship to TCP in what ways is it similar and different, and why would we use UDP, and why can not a user program access IP directly?

  What is a logical data flow diagram

Why do we need to document an Information System?- What is a physical data flow diagram (DFD)?- What is a logical data flow diagram (DFD)?

  Explain how protection techniques can help defend

Explain how protection techniques can help defend an organisation from security threats.

  Describe the overall architecture of your application

you will identify the requirements for the project you selected in the first week. You will also perform a requirements analysis to help solidify the requirements and prepare the path for the design of the software. Describe the overall architectu..

  Critical success factors for retail e business startups

Question 1: Most businesses should engage in e-commerce on the Internet. Do you agree or disagree with this statement? Explain your position. Question 2: What are the critical success factors for retail e-Business startups?

  CMT656 Delivering User Experience Assignment

CMT656 Delivering User Experience Assignment Help and Solution, Cardiff School of Computer Science and Informatics - Assessment Writing Service

  List functional requirements and non-functional requirements

List two functional requirements (FRs). List two non-functional requirements (NFRs). List the actors of the WebApp. Draw a use case diagram for the

  Describe system and software standards that could be used

Describe system and software standards that could be used for the description of control constructs in C, C#, or Java.

  Design requires and the provide interfaces of two components

Design the Requires and the Provides interfaces of at least two components that might be used in a system in an emergency control room for a call-logging component that records calls made.

  Describe the benefits of compliance certification??

Explain the need for additional training and additional areas of certification. Describe the benefits of compliance certification??.

  Create software architecture drawings of automation program

Please Create and Embed "Software Architecture Drawings" of the Invoice Automation Program into a Microsoft Word document and describe the drawings.

  Design a class named clock

Design a class named clock. It has data for second, minute, hour and time. Define appropriate accessor and mutators methods for above mentioned data

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