Advertisement
Vendrick-Xander

pg 161 #64,67 HW

Jan 17th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. Code for the first program:
  2. package com.Suarez;
  3. /*
  4. Xander Fermier
  5. 1/17/19
  6. this program instantiates two points and reads their data.
  7. */
  8.  
  9. import java.util.*;
  10. import java.text.*;
  11.  
  12. public class PointClientHW {
  13. public static void main(String[]args)
  14. {
  15. Scanner pointDelcare = new Scanner(System.in);
  16. System.out.println("Give me your x value for the first point.");
  17. int x1 = pointDelcare.nextInt();
  18. System.out.println("Give me your y value for the first point.");
  19. int y1 = pointDelcare.nextInt();
  20. System.out.println("Give me your x value for the second point.");
  21. int x2 = pointDelcare.nextInt();
  22. System.out.println("Give me your y value for the second point.");
  23. int y2 = pointDelcare.nextInt();
  24.  
  25. Point p1 = new Point(x1,y1);
  26. Point p2 = new Point(x2,y2);
  27.  
  28. System.out.println("The first point is (" + p1.getX() + ", " + p1.getY()+ ")");
  29. System.out.println("The second point is (" + p2.getX() + ", " + p2.getY()+ ")");
  30. }
  31. }
  32.  
  33. The code for the second program:
  34. package com.Suarez;
  35. /*
  36. Xander Fermier
  37. 1/17/19
  38. This program decrypts the message that the user has input and then outputs the result
  39. */
  40.  
  41. import java.util.*;
  42.  
  43.  
  44. public class SentenceDecrypter {
  45. public static void main(String[]args)
  46. {
  47. Scanner sentence = new Scanner(System.in);
  48. System.out.println("Give me your encrypted message.");
  49. String userSentence = sentence.nextLine();
  50. // gets the char values from the user
  51. char first = userSentence.charAt(0);
  52. char second = userSentence.charAt(2);
  53. char third = userSentence.charAt(4);
  54. char fourth = userSentence.charAt(6);
  55. char fifth = userSentence.charAt(8);
  56. // assembles the char values into the message
  57. StringBuilder sb = new StringBuilder();
  58. sb.append(first);
  59. sb.append(second);
  60. sb.append(third);
  61. sb.append(fourth);
  62. sb.append(fifth);
  63. String message = sb.toString();
  64. System.out.println("The message is: " + message);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement