Defining Diagram
Input | Processing | Output |
answer | prompts the user to input their answer to a question. gets the answer. dispenses a hug based on that answer. | a hug. |
Solution Algorithm
hug_dispenser
prompt user for answer to question “Would you like a hug?”
get answer
IF answer = yes THEN
dispense hug
ELSE
do nothing
ENDIF
END
Java Code
// Programmer: Heath Parkes
// File name: hug_dispenser.java
// Date: 9/3/10
/* Description:
A friendly hug dispenser.
*/
import javax.swing.*;
import java.util.*;
import java.io.*;
public class hug_dispenser
{
public static void main(String[] args)
{
Scanner scanner = new Scanner (System.in);
String answer;
char selection;
System.out.println("Hello! Would you like a hug? (y/n)");
answer = scanner.nextLine();
selection = answer.charAt(0);
if (selection == 'y')
{
System.out.println(" ");
System.out.println("(\\__/)");
System.out.println("(='.'=)");
System.out.println("(\")_(\")");
System.out.println(" ");
System.out.println("Have a hug!");
}
else
{
System.out.println("Fine! Be like that then!");
}
}
}
Java Code
// Programmer: Heath Parkes
// File name: hug_dispenser.java
// Date: 9/3/10
/* Description:
A friendly hug dispenser.
*/
import javax.swing.*;
import java.util.*;
import java.io.*;
public class hug_dispenser
{
public static void main(String[] args)
{
Scanner scanner = new Scanner (System.in);
String answer;
char selection;
System.out.println("Hello! Would you like a hug? (y/n)");
answer = scanner.nextLine();
selection = answer.charAt(0);
if (selection == 'y')
{
System.out.println(" ");
System.out.println("(\\__/)");
System.out.println("(='.'=)");
System.out.println("(\")_(\")");
System.out.println(" ");
System.out.println("Have a hug!");
}
else
{
System.out.println("Fine! Be like that then!");
}
}
}