Results 1 to 8 of 8

Thread: methods

  1. #1
    lilac87 is offline Member
    Join Date
    Jul 2009
    Posts
    8
    Rep Power
    0

    Default methods

    Hi!
    I am trying to implement the following methods into the code below. The methods are: calcuateRetire() and display. I'm really new to java, so please give me some advice.

    import javax.swing.JOptionPane; public class calculate {public static void main (String [] args) {
    int age, retire;
    age = Integer.parseInt (JOptionPane.showInputDialog("Your age?"));
    retire = 65 - age;
    JOptionPane.showMessageDialog(null,"You are eligible to retire in: "+ retire + " years"); }}
    Last edited by lilac87; 07-14-2009 at 08:12 PM.

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

    Default

    so what's stopping you?
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    lilac87 is offline Member
    Join Date
    Jul 2009
    Posts
    8
    Rep Power
    0

    Default

    i need advice on how to do it.

  4. #4
    IEEE is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default

    hey , m new to java. i use eclipse in codin.while i create classes it gives debugging error.wat could b the problem??
    the code is here:

    class box {
    double length,breadth,height;
    double volume()
    {
    return length*breadth*height;
    }
    }
    class demobox{
    public static void main(String[] args)
    {
    box box1=new box();
    box box2=new box();



    box1.length=10;
    box1.breadth=12;
    box1.height=23;

    box2.length=13;
    box2.breadth=12;
    box2.height=44;



    System.out.println("the volume of box1 is"+box1.volume());
    System.out.println("the volume of box1 is"+box2.volume());



    }
    }

  5. #5
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    @IEEE please do not take peoples threads. Post your own thread for your own problems.

    @OP we're going to need some more description if we are going to help. I really have no idea what you are trying to do.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  6. #6
    lilac87 is offline Member
    Join Date
    Jul 2009
    Posts
    8
    Rep Power
    0

    Default errors

    I've implemented the methods, but it doesn't calculate the retiring age. I'm not sure how to fix it. I want it to calculate correctly, that's all. any advice?

    import javax.swing.JOptionPane;
    public class Lab2Solution
    {
    public static void main (String [] args)
    {
    age = enterAge(int age);
    calculateAge();
    display();
    }
    private static int enterAge()
    {
    int age;
    while (age <= 0 || age >= 65)
    age = Integer.parseInt (JOptionPane.showInputDialog ("Your Age?"));
    return age;
    }

    public static int calculateRetire()
    {
    int age=0, retire=0;
    retire = 65 - age;
    return retire;
    }

    public static void display()
    {
    int retire=0;
    calculateRetire();
    JOptionPane.showMessageDialog(null,"You are eligible to retire in: "+ retire + " years");
    }

    }

  7. #7
    Harpreet1111 is offline Member
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    Default

    Hello lilac87,

    your enterAge() method does not accept any arguments but you r passing...... correct code will be;

    code

    import javax.swing.JOptionPane;
    public class Lab2Solution
    {
    public static void main (String [] args)
    {
    int age = enterAge();
    int retire=calculateRetire(age);
    display(retire);
    }
    private static int enterAge()
    {
    int age;
    age = Integer.parseInt (JOptionPane.showInputDialog ("Your Age?"));


    return age;
    }

    public static int calculateRetire(int age)
    {
    int retire=0;
    retire = 65 - age;
    return retire;
    }

    public static void display(int retire)
    {
    JOptionPane.showMessageDialog(null,"You are eligible to retire in: "+ retire + " years");
    }

    }
    Last edited by Harpreet1111; 07-19-2009 at 08:15 PM.

  8. #8
    lilac87 is offline Member
    Join Date
    Jul 2009
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Replies: 8
    Last Post: 04-17-2012, 12:00 AM
  2. Replies: 4
    Last Post: 04-03-2009, 07:36 AM
  3. Get and Set Methods
    By kian_hong2000 in forum New To Java
    Replies: 10
    Last Post: 08-27-2008, 03:06 PM
  4. methods
    By Zensai in forum New To Java
    Replies: 10
    Last Post: 12-03-2007, 06:31 AM
  5. Methods
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-01-2007, 09:49 PM

Posting Permissions

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