123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Write a description of class Hello here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.util.Scanner;
  8. public class Hello
  9. {
  10. // instance variables - replace the example below with your own
  11. Scanner scan = new Scanner(System.in);
  12. /**
  13. * Constructor for objects of class Hello
  14. */
  15. public Hello()
  16. {
  17. // initialise instance variables
  18. }
  19. /**
  20. * An example of a method - replace this comment with your own
  21. *
  22. * @param y a sample parameter for a method
  23. * @return the sum of x and y
  24. */
  25. public void greet()
  26. {
  27. System.out.println("What is your name?");
  28. String name = scan.next();
  29. while(!name.equalsIgnoreCase("Alice") ||
  30. !name.equalsIgnoreCase("Bob")) {
  31. if (name.equalsIgnoreCase("Alice")) {
  32. System.out.println("Hello Alice!!");
  33. } else if (name.equalsIgnoreCase("Bob")) {
  34. System.out.print("Hey Bob!");
  35. } else {
  36. System.out.println("Who is that? Man, I don't know you!");
  37. }
  38. }
  39. }
  40. }