Tuesday, March 9, 2010

hug_dispenser.java

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!");
}
}
}

Monday, March 1, 2010

public static void main

I know it was a long time ago.

I was young, and naive. You weren't that old yourself, but you were sophisticated.

A friend of mine introduced me to you. Remember that day? Not a cloud in the sky - I looked out the window and checked...

You were my first. I've tried to love others but it never worked out. And now the time has come for me to re-evaluate our position. I've decided i'm going to make this work. Will you take me back?

Let's get together and make some sweet sweet code, Java.

I love you.