Question: Homework 1 Basic Objects Points badge Introduction This Assignment is meant to help refresh your memory about building objects with Java. You'll be implementing 2
Homework Basic Objects
Points badge
Introduction
This Assignment is meant to help refresh your memory about building objects with Java. You'll be implementing classes meant to be reusable for many purposes. The classes will be described in text and in UML. The two classes are called GridText and AlgebraicFraction. Before you begin, download the SelfAssessmentCSCHW excel file and fill out the first sheet as a preliminary self assessment. The file has additional sheets to fill out before each submission.
Goals
Creating a class from UML
Using an ArrayList of Strings to simulate a ragged D array of characters.
Using an ArrayList to hold lists of variables.
Understanding how ArrayLists can be used as the underlying data structure of a class.
GridText
The purpose of GridText is to have a character by character grid representation of any text file that can be indexed like a twodimensional array is indexed. This can be useful if you want to display the text in a graphical environment or if you wanted to keep track of a cursor that is over text in a text field in a graphical environment.
Class description
GridText an object for converting text a D Character array.
fields
gridText: an ArrayList that has one linerow of text at each index.
methods
GridTextsource delimiter: The source string should be split by the delimiter using the String split method and each string in the resulting array should be added to the gridText list in order.
GridTextsource numLines: The source Scanner should be read one line at a time a maximum of numLines times using the nextLine method and each line should be added to the gridText list in order. If there are fewer than numLines in the source Scanner, then the resulting GridText should have the number of lines retrieved from the scanner as its number of rows. If there are more than numLines in the source Scanner, then the resulting GridText should have numLines rows in the arraylist.
numRows : this method should return the number of strings in gridText.
lengthrow: this method should return the number of characters in the row at the index specified by row
atrowcol: this method should return the character at row,col or null if either the row or the col are out of bounds.
Algebraic Fraction
The perpose of AlgebraicFraction is to have an Object based version of a fraction so that you could represent Objects with a fractional relationship. An example would be
a
b
c
d
An algebraic fraction should be reduced during it's construction, so if the numerator were
a
b
c
and the denominator was
c
d
then the c in the numerator and the c in the denominator would cancel, and the fraction would become
a
b
d
Class description
AlgebraicFraction an object for holding abstract fractional representations.
fields
numerator: an ArrayList of each numerator component
denominator: an ArrayList of each denominator component
methods
AlgebraicFractionnum denom: The values of each cell of the num array should be put in to the numerator ArrayList and the values of each cell in the denom array should be put into the denominator ArrayList. Then the fraction should be reduced with the below Fraction reducing algorithm.
multiplyotherFraction should return a new AlgebraicFraction from the combination of the two fractions. See Fraction multiplication algorithm.
toString: this method should return a String representation of the reduced fraction. The parts of the numerator should be prefixed by a then separated by single spaces followed by and then the parts of the denominator should be separated by spaces and then ended with a
Fraction reducing algorithm
For each Object n in the num array passed into the constructor:
if n is in the numerator ArrayList and n is in the denominator ArrayList
remove n from the numerator array list
remove n from the denominatory array list
Fraction multiplication algorithm
to multiply fractions a and b
combine the numerators of fractions a and b
combine the denominators of fractions a and b
make a new fraction with the combined numerators and denominators
reduce
Fraction multiplication example
a b cd e f times d f ga e r
combined numerator: a b c d f g
combined denominator: d e f a e r
new fraction a b c d f gd e f a e r
reduced: b c ge e r
Requirements
the above classes GridText and AlgebraicFraction must have the specified fields and methods.
each file should have comments that include the author's name
all tests should pass
Write a short narrative of how much you learned by doing this assignment.
to assist with the narrative, use the SelfAssessmentCSCHW excel file before starting, and for each submission. Your narrative should reflect on the below concepts as well as overall learning goals for the course.
reading a UML diagram don't understand completeley understand
writing a s
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
