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

Thread: Method calculate 2 object using constructor with parameter

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Method calculate 2 object using constructor with parameter

    public class BillTest
    {
    public static void main (String[]arg)
    {
    Bill mum=new Bill(130,100); //object mum
    Bill sister=new Bill(200,50); //object sister
    Bill family=new Bill(0,0); // object family
    family=family.calculateTotal(mum,sister);
    System.out.println("Total bill:");
    family.calculateBill();
    }
    }
    public class Bill
    {
    int airtime;
    int totalSms;
    int total;
    public double callrate=0.25;
    public double smsrate=0.05;


    Bill(int a, int s)
    {
    airtime = a;
    totalSms= s;
    }

    public int calculateTotal(mum, sister)
    {


    return total;
    }

    public double calculateBill()
    {
    return (airtime * callrate+ totalSms * smsrate);
    }

    }
    What method i should write the calculateTotal(mum,sister)?
    calculate the total " airtime from mum and sister" and "totalSms from mum and sister" ...


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,550
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: Method calculate 2 object using constructor with parameter

    Are you sure you have the requirements correct? Do you really need a "family" Bill? I would think that the total Bill is simply mum's Bill + sister's Bill.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Method calculate 2 object using constructor with parameter

    class BillTest is given from question...
    what i have to do is complete the Bill class.
    what method can be use to calculatetotal of 2 object mum ans sis with 2 parameter?
    the calculatetotal() is calculate the total airtime of mum&sister , and totalsms of mum&sister.
    anyone can solve this? I'm going out of my mind....

Similar Threads

  1. Replies: 3
    Last Post: May 27th, 2012, 12:11 PM
  2. constructor with an arraylist parameter?
    By ronimacarroni in forum Object Oriented Programming
    Replies: 5
    Last Post: March 5th, 2012, 04:42 PM
  3. how can i pass objects into a parameter and display them in the method
    By em1980 in forum What's Wrong With My Code?
    Replies: 14
    Last Post: December 5th, 2011, 01:02 PM
  4. Object array with constructor
    By thedolphin13 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 8th, 2010, 12:02 PM
  5. Passing objects as a constructor parameter
    By derky in forum Object Oriented Programming
    Replies: 2
    Last Post: October 27th, 2009, 05:31 AM