Results 1 to 9 of 9

Thread: Math Program

  1. #1
    stlboi is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default Math Program

    Any idea how to do this? I'm going to need a java file plus a java tester file as well, right?


    Write a program that prompts the user for two numbers, then prints
    The sum
    The difference
    The product
    The average
    The distance (absolute value of the difference)
    The maximum (the larger of the two)
    The minimum (the smaller of the two)

    To do so, implement a class
    public class Pair
    {
    /**
    Constructs a pair.
    @param aFirst the first value of the pair
    @param aSecond the second value of the pair
    */
    public Pair(double aFirst, double aSecond) { . . . }

    /**
    Computes the sum of the values of this pair.
    @return the sum of the first and second values
    */
    public double getSum() { . . . }
    . . .
    }

    Then implement a class PairTester that constructs a Pair object, invokes its methods, and prin

  2. #2
    mcfrog's Avatar
    mcfrog is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    32
    Rep Power
    0

    Default

    Hi,

    yes it seems really easy: 2 classes: Pair and PairTester, anyway IMHO a main method in the class Pair would suffice. Well, move on with your homework ;)

    edit:
    oh yes: don't forget to format your double values appropriate, because nobody likes doubles like 0.100000000000000893473
    Last edited by mcfrog; 04-02-2009 at 09:26 PM. Reason: i forgot something about the format
    Cheers / beste Gre / lepo pozdravje
    8=:(=)D . o O ( Save the Giraffes )

  3. #3
    stlboi is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    Now if I only knew where to start lol. My teacher spends about 90% of the class talking about the old days. Sucks.

  4. #4
    mcfrog's Avatar
    mcfrog is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    32
    Rep Power
    0

    Default

    well that's easy, but I don't know what knowledge you already have, so here's the long version:

    * you create two files named after the classes and
    * create the constructor given by your teacher
    Java Code:
    public Pair(double aFirst, double aSecond) { . . . }
    * to have values to work with you need also to member variables of the same type, double, ... um... make them private members to keep nosy classes away :D
    * create the mentioned methods and let your mathematical genius roll and return the values in the fashion of
    Java Code:
    /** your javadoc here */ public double getSum() { return this.firstValue + this.secondValue; }
    This really would suffice for sum. Anything clear?

    so long
    Cheers / beste Gre / lepo pozdravje
    8=:(=)D . o O ( Save the Giraffes )

  5. #5
    stlboi is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    Ah, I think I see now. I will let you all know. Thanks bud!

  6. #6
    mcfrog's Avatar
    mcfrog is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    32
    Rep Power
    0

    Default

    no prob, you're welcome. :) Anyway, consider to set the RESOLVED-marker for this thread soon.

    But if you intend to get deeper into Java it maybe is a good idea to buy a good book and have Java programmers around you in order to shortcut the back-in-the-days-where-we-had-punchcards if your teacher doesn't teach you very well.
    Last edited by mcfrog; 04-02-2009 at 09:57 PM.
    Cheers / beste Gre / lepo pozdravje
    8=:(=)D . o O ( Save the Giraffes )

  7. #7
    stlboi is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    Funny you mention punch cards cuz he brings that up a lot.

  8. #8
    mcfrog's Avatar
    mcfrog is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    32
    Rep Power
    0

    Default

    every teacher comes up with that story. Personally I think all these punchcard-talk is urban myth. There never have been punchcards. it's a created diversion in order not to see the real problems: the lack of good teaching :)
    Cheers / beste Gre / lepo pozdravje
    8=:(=)D . o O ( Save the Giraffes )

  9. #9
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    when problem is solved, please mark it using the thread toolbars at the top of this page (under the ads). thx
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Math Class
    By ritwik07 in forum New To Java
    Replies: 2
    Last Post: 09-14-2009, 05:06 PM
  2. Anyone good at math?
    By iWonder in forum Forum Lobby
    Replies: 12
    Last Post: 01-11-2009, 05:12 PM
  3. need help with math for a new program
    By gotenks05 in forum New To Java
    Replies: 13
    Last Post: 09-26-2008, 08:32 AM
  4. Math.Random
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-23-2007, 03:09 PM
  5. Help with math in java
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 07:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •