Skip to main content

Script Help

1 reply [Last post]
solovv
Offline
Joined: 2010-01-11

hi guys, Im new to JDK and java, just looking for some help on how to start simple projects.

Looking to write something to perform a sample greeting :

Need a class Greeter that contains a String field name, and the following public methods: (a) void askName() that asks the user for a name in an input dialog box and stores it in the field name (b) void greetDialog() that displays a personalized greeting (for example, “Hello there, Bob!”) for the current name in a message dialog box (c) void greetConsole() that works otherwise the same way as the previous method, but outputs the greeting to the console.

No idea where to start

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
yoss
Offline
Joined: 2010-01-25

Here is one way to do this. Method A and C works, but about method B, I don't know how do you want to show the result, in the TextField? If Yes, you should handle with it, if You have any problems, write :).
Regards

[code]
public class Greeter{

static String name;

public static String askName(){
name = JOptionPane.showInputDialog("Type name: ",null);
return name;
}

public String greetDialog(){
return name;
}

public static String greetConcole(){
return name;
}

public static void main(String[] args) {
askName();
System.out.print("Hello from: "+greetConcole());
}

}
[/code]

Message was edited by: yoss