Advertisement
Vendrick-Xander

pg 338 HW programs part 2

Jan 29th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. 61.
  2. package com.Suarez;
  3.  
  4. /*
  5. Xander Fermier
  6. 1/29/19
  7. this program takes in 10 values from the user and outputs the minimum, maximum, and average
  8. */
  9.  
  10. import java.util.*;
  11.  
  12. public class ExamGradeAverage {
  13. public static void main(String[]args)
  14. {
  15. Scanner scan = new Scanner(System.in);
  16. int startMin = 101;
  17. int startMax = -1;
  18. int examAvg=0;
  19. for(int i =0; i<10;i++)
  20. {
  21. System.out.println("Give me your next exam grade");
  22. int examRecieve = scan.nextInt();
  23. if (examRecieve > startMax)
  24. {
  25. startMax = examRecieve;
  26. }
  27. if (examRecieve < startMin)
  28. {
  29. startMin = examRecieve;
  30. }
  31. examAvg += examRecieve;
  32. }
  33. System.out.println("Your lowest grade was "+ startMin);
  34. System.out.println("Your highest grade was "+ startMax);
  35. System.out.println("Your average was" + examAvg/2);
  36. }
  37. }
  38. 63. package com.Suarez;
  39.  
  40. /*
  41. Xander Fermier
  42. 1/28/19
  43. this programs takes in a user id from the user and if it has two digits in it, then it says valid
  44. */
  45.  
  46. import java.util.*;
  47.  
  48. public class UserIDDigitCheck {
  49. public static void main(String []args)
  50. {
  51. Scanner scan = new Scanner(System.in);
  52. System.out.println("Give me your ID to check");
  53. String userInput = scan.nextLine();
  54. int inputLength = userInput.length();
  55. int digit = 0;
  56. for (int i=0; i<inputLength;i++)
  57. {
  58. char something = userInput.charAt(i);
  59. if (Character.isDigit(something));
  60. {
  61. digit++;
  62. }
  63. }
  64. if (digit == 2)
  65. {
  66. System.out.println("Valid User ID");
  67. }
  68. else
  69. {
  70. System.out.println("Invalid user ID.");
  71. }
  72. }
  73. }
  74. 65.
  75. package com.Suarez;
  76. /*
  77. Xander Fermier
  78. 1/28/19
  79. this program takes in a binary value from the user and ouputs the decimal equivalent
  80. */
  81.  
  82. import java.util.*;
  83.  
  84. public class UserBinaryToDecimal {
  85. public static void main(String[]args)
  86. {
  87. Scanner scan = new Scanner(System.in);
  88. System.out.println("Give me your binary to convert");
  89. String input = scan.nextLine();
  90. System.out.println(Integer.parseInt(input, 2));
  91. }
  92. }
  93. 67.
  94. package com.Suarez;
  95. /*
  96. Xander Fermier
  97. 1/28/19
  98. this program checks if the enter line is a palindrome
  99. */
  100. import java.util.*;
  101. public class PalindromeChecker {
  102. public static void main(String[]args)
  103. {
  104. Scanner scan = new Scanner(System.in);
  105. System.out.println("Give me a sentence to check");
  106. String input = scan.nextLine();
  107. String inputCheck = input.toUpperCase();
  108. int inputLength = input.length();
  109. char first;
  110. char last;
  111. int check =0;
  112. for (int i = 0; i < inputLength; i++)
  113. {
  114. first = inputCheck.charAt(i);
  115. last = inputCheck.charAt((inputLength-i)-1);
  116. if (first == last)
  117. {
  118. check++;
  119. }
  120. }
  121. if (check == inputLength)
  122. {
  123. System.out.println("The message is a palindrome.");
  124. }
  125. else
  126. {
  127. System.out.println("The message is not a palindrome.");
  128. }
  129. }
  130. }
  131. 69.(not sure if you wanted to answer this b/c it is not a program but I a doing it anyways.)
  132. logic errors made when coding loops could occur because the programmer might forget to change the variable that is part of the loop condition, or the loop condition might never not be true, etc. These kinds of errors can be really annoying to fix and also completely break your program. Your program might break in the sense that your desired will never be achieved, and the frustration that arises come from the fact that you don't know exactly where the error is coming from and often times it is a difference of just one character.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement