Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Defining a rational class. Simple but i cant figure it out to save my life

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Defining a rational class. Simple but i cant figure it out to save my life

    Define 3 constructors and a toString method, setters, and getters
    Define arithmetic methods for add, subtract, multiply, divide, and negate. The negate method will return the negative of the calling Rational object return new Rational (-num,denom);
    Define logical methods for equals, notEquals, lessThan, lessThanOrEqual, greaterThan, and greaterThanOrEqual.

    All negative values should be represented with the negative sign in the numerator do this in the setDenom method and call it in the constructor.

    Extra Credit: add a greatestCommonDivisor method to reduce a Rational number to its lowest terms. If you write this method, add the reduced values to your output. For example:
    + = 10/8 reduced to 5/4

    Run three times with the following data: (read in the data then use one of the constructors or the setter methods to fill objects with data)

    Input 1: 1/2, 3/4 - entered as 1 2 3 4

    Input 2: 1/2, 5/10 entered as 1 2 5 10

    Input 3: 3/-5, 2 entered as 3 -5 2 1


    Output (using the first set of numbers):

    Rational 1 >1/2 reduced to _______
    Rational 2 -> 3/4 reduced to_______
    + ______ reduced to_______
    - ______ reduced to_______
    * ______ reduced to_______
    / ______ reduced to_______
    - ______ reduced to_______
    == ______ print true or false
    != ________ print true or false
    > ______ print true or false
    >= ______ print true or false
    < ______ print true or false
    <= ______ print true or false


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,262
    Thanks
    176
    Thanked 820 Times in 763 Posts
    Blog Entries
    5

    Default Re: Defining a rational class. Simple but i cant figure it out to save my life

    Dumping homework assignments is unproductive at best. Please see the link in my signature entitled getting help, as well as the following:
    How to Program (stuck on homework? READ THIS BEFORE POSTING)

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Defining a rational class. Simple but i cant figure it out to save my life

    im not dumping it. i literally have no idea what to do to get started

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,262
    Thanks
    176
    Thanked 820 Times in 763 Posts
    Blog Entries
    5

    Default Re: Defining a rational class. Simple but i cant figure it out to save my life

    Quote Originally Posted by spetillo3 View Post
    im not dumping it. i literally have no idea what to do to get started
    Did you read the links I provided? Without knowing any context - from whether you know how to make a hello world program to whether you know loops to whether you know object oriented programming - we will have a hard time pointing you in the right direction. Break the problem down, and concentrate on one requirement at a time...ask a specific question about that requirement.

Similar Threads

  1. The Rational Class Program [HOMEWORK HELP]
    By FCarlton24 in forum Object Oriented Programming
    Replies: 1
    Last Post: October 18th, 2011, 12:31 PM
  2. [SOLVED] Simple error that I can't figure out how to fix
    By javapenguin in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 11th, 2011, 07:27 AM
  3. [Homework] Rational Class
    By burger king in forum Object Oriented Programming
    Replies: 2
    Last Post: January 13th, 2011, 08:15 PM
  4. Simple error can't figure out.
    By n00bprogrammer in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 30th, 2010, 12:19 PM
  5. simple problem w/ appelets which i cant figure out
    By JavaGreg in forum Java Applets
    Replies: 7
    Last Post: August 15th, 2009, 07:22 PM