Answer on Question #58833, Programming & Computer Science, Java, JSP, JSF
Condition
Within the method main, call each dataOut method using an appropriate list of arguments chosen from four variables that are declared in main:
A char variable named letter, assigned the value 'a'
A String variable named name, assigned the value "Hello"
An int variable named number, assigned the value 5
A double variable named value, assigned the value 6.25
Be sure to include comments and display the results to the user.
Code
public class Task {
public static void main(String[] args) {
// Creates variables and assigns value for them
char letterVar = 'a';
String nameVar = "Hello";
int numberVar = 5;
double valueVar = 6.25;
// Creates Task objects and calls different methods
// with parameters of those variables
new Task().dataOut(letterVar);
new Task().dataOut(nameVar);
new Task().dataOut(numberVar);
new Task().dataOut(valueVar);
}
// Method outputs char value
private void dataOut(char letter) {
// Prints char value
System.out.println("Char variable: " + letter);
}
// Method outputs String value
private void dataOut(String name) {
// Prints String value
System.out.println("String variable: " + name);
}
// Method outputs int value
private void dataOut(int number) {
// Prints int value
System.out.println("Integer variable: " + number);
}
// Method outputs double value
private void dataOut(double value) {
// Prints double value
System.out.println("Double variable: " + value);
}
}http://www.AssignmentExpert.com/
Output
Char variable: a
String variable: Hello
Integer variable: 5
Double variable: 6.25
Comments