Results 1 to 8 of 8
Thread: methods
- 07-14-2009, 05:52 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 8
- Rep Power
- 0
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 07:12 PM.
- 07-14-2009, 06:33 PM #2
- 07-14-2009, 07:01 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 8
- Rep Power
- 0
i need advice on how to do it.
- 07-14-2009, 07:14 PM #4
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
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());
}
}
- 07-14-2009, 07:42 PM #5
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
@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!
- 07-14-2009, 10:06 PM #6
Member
- Join Date
- Jul 2009
- Posts
- 8
- Rep Power
- 0
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");
}
}
- 07-19-2009, 07:07 PM #7
Member
- Join Date
- Jul 2009
- Posts
- 12
- Rep Power
- 0
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 07:15 PM.
- 07-22-2009, 06:37 PM #8
Member
- Join Date
- Jul 2009
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-16-2012, 11:00 PM -
How to get methods to see variables in other methods
By ejs7597 in forum New To JavaReplies: 4Last Post: 04-03-2009, 06:36 AM -
Get and Set Methods
By kian_hong2000 in forum New To JavaReplies: 10Last Post: 08-27-2008, 02:06 PM -
methods
By Zensai in forum New To JavaReplies: 10Last Post: 12-03-2007, 05:31 AM -
Methods
By Java Tip in forum Java TipReplies: 0Last Post: 12-01-2007, 08:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks