Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎

2017-10-16 HW(LAB)

posted Oct 17, 2017, 10:19 AM by Konstantinovich Samuel
Yesterday
-Default constructor: 
When does java give it to you? 
What does java give you?

-Subclass constructor:
    How does it initialize the private variables of the parent class?
    When does it have an implicit call to super? (what does implicit mean?)
    
- A call to any other method will always call the overridden version of the method. This is a DESIREABLE behavior.


Today Lab:

    Rational Number class!
1. Read the methods in the class. 
2. Determine which methods you need to do first.
3. Create a set of tests for your methods, call this Driver.java
4. Comment out the ADVANCED tests until you have written the methods for the test.
5. When you have a full set of tests, start filling in the RationalNumber class.
public class RationalNumber
{
  private int numerator, denominator;

  /**Initialize the RationalNumber with the provided values
  *@param nume the numerator
  *@param deno the denominator
  */
  public RationalNumber(int nume, int deno){
    
  }

  /**
  *@return the numerator
  */
  public int getNumerator(){
    return 0;
  }
  /**
  *@return the denominator
  */
  public int getDenominator(){
    return 0;
  }
  /**
  *@return a new RationalNumber that has the same numerator
  *and denominator as this RationalNumber but reversed.
  */
  public RationalNumber reciprocal(){

  }
  /**
  *@return true when the RationalNumbers have the same numerators and denominators, false otherwise.
  */
  public boolean equals(RationalNumber other){

  }


  /**
  *@return the value expressed as "3/4" or "8/3"
  */
  public String toString(){
    return "0";
  }



  /**Calculate the GCD of two integers.
  *@param a the first integers
  *@param b the second integer
  *@return the value of the GCD
  */
  private static int gcd(int a, int b){
    /*use euclids method or a better one*/
  }



  /**
  *Divide the numerator and denominator by the GCD
  *This must be used to maintain that all RationalNumbers are
  *reduced after any operation you perform.
  */
  private void reduce(){

  }



  /******************Operations!!!!****************/


  /**
  *
  */
  public RationalNumber multiply(RationalNumber other){
    return null;
  }

  /**
  *
  */
  public RationalNumber divide(RationalNumber other){
    return null;
  }

  /**
  *
  */
  public RationalNumber add(RationalNumber other){
    return null;
  }
  /**
  *
  */
  public RationalNumber subtract(RationalNumber other){
    return null;
  }
}

Comments