Rational
- int numerator
- int denominator
+
Rational(int numerator, int denominator)
+ Rational plus(Rational b)
//sum of this number and b
+ Rational minus(Rational b)
//difference of this number and b
+ Rational times(Rational b)
//product of this number and b
+ Rational over(Rational b)
//quotient of this number and b
+ String toString()
//string representation
+ boolean equals(Rational b)
//Equality comparison of Rationals
- int gcd(int p, int q)
//Greatest common denominator of a and b
- void reduce()
//Helper to reduce numerator and denominator to lowest terms
- static boolean testPlus()
//Unit test for sum
- static boolean testMinus()
//Unit test for difference
- static boolean testTimes()
//Unit test for product
- static boolean testOver()
//Unit test for quotient
- static boolean testToString()
//Unit test for toString
toString()
method should only output the denominator if it is
not one. Additionally, implement a main
method inside of the
class that executes all of the unit tests. Do not worry about testing
and protecting against integer overflow.
Rational.java
.java Rational
):
Element
for
entries in the Periodic Table of Elements. Include data type values for
element, atomic number, symbol, and atomic weight and accessor methods for
each of these values. Then, create a data type PeriodicTable
that reads values from a file to create an array of Element
objects, responds to queries from standard input so that a user can type a
molecular equation like "H 2 O", and prints the resulting molecular weight.
Develop APIs and implementations for each data type.
hasNextInt()
inside of Scanner.
Element.java
and
PeriodicTable.java
.java PeriodicTable
) user provides input:
Enter a molecular equation like "H 2 O":
C 2 H 6 O
Molecular weight is: 46.08
java PeriodicTable
) user provides input:
Enter a molecular equation like "H 2 O":
Cu Sn
Molecular weight is: 182.23
Quaternion.java
.java Quaternion
):