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 2 of 2

Thread: Java Client Code Help?

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Java Client Code Help?

    Hi,

    So in my computer science class we are making a Rational Number class. After that we must create client code to test it out. I'm not exactly sure what he is asking us to do here.. If anyone could just explain to me what this is asking for?
    The instructions-

    • Create 3 instances of RationalNumber. Remember every time you say “new” you are creating an instance.
    o One of them should use the default constructor
    o One of them should use the constructor with one parameter
    o One of them should use the concstructor with two parameters.
    • Print out the int and double value of each Rational Number
    • Print out the sum (as a double) of all the numbers.
    • Print out the sum (as an int) of all the numbers.

    My rational number class.
    public class RationalNumber{ 
     
    private int numerator; 
    private int denominator; 
     
    public RationalNumber() 
    { 
    numerator =1; 
    denominator = 4; 
    } 
    public RationalNumber(int n) 
    { 
    numerator = n; 
     
    } 
    public RationalNumber(int n, int d) 
    { 
    numerator = n; 
    denominator = d; 
    } 
    public int getNumerator() 
    { 
    return numerator; 
    } 
    public int getdenominator() 
    { 
    return denominator; 
    } 
    public void setNumerator(int n) 
    { 
    numerator = n; 
    } 
    public void setDenomenator(int d) 
    { 
    denominator = d; 
    } 
     
    public double evaluateDouble() 
    { 
    return ((double)numerator)/denominator; 
     
    } 
    public int evaluate() 
    { 
    return numerator/denominator; 
    } 
    public String toString() 
    { 
    return numerator +"/" + denominator; 
    } 
    }

    If anyone could help it would be greatly appreciated!


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java Client Code Help?

    The instructions are pretty clear. Can you go through them one by one and tell us which ones you don't understand? Or if you don't understand what "client code" is, let us know that.

Similar Threads

  1. How to compile java code on server side and then send back result to client.
    By Sahil Arora in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 13th, 2013, 12:52 PM
  2. my encrypting simple client to server program unable to get the key from client
    By Paytheprice in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 3rd, 2013, 07:15 AM
  3. Replies: 0
    Last Post: May 31st, 2012, 05:35 PM
  4. what's wrong with my code ? " server client socket
    By Wish.. in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 27th, 2012, 01:33 PM
  5. How to write switch statement inside if statement?
    By Rezz in forum Loops & Control Statements
    Replies: 6
    Last Post: June 11th, 2008, 11:27 AM