First Java Assignment

Public

Program with 5-Option Menu

Get raw version
javascript
  1. package Part2;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6.  
  7. public class Programs {
  8.  
  9.  
  10. public static void main(String[]args)throws IOException{
  11. Scanner sc = new Scanner(System.in);
  12. int input=0;
  13. do{
  14. System.out.println("Choose an Option");
  15. System.out.println("1 Product no Negatives");
  16. System.out.println("2 Find Twelve");
  17. System.out.println("3 Max Min Average");
  18. System.out.println("4 Letter Grade");
  19. System.out.println("5 Exit");
  20. input=sc.nextInt();
  21.  
  22.  
  23.  
  24.  
  25. if(input==1){double product =1;
  26. double input1;
  27.  
  28.  
  29. System.out.println("Enter numbers to find the product of:");
  30.  
  31. do
  32. {
  33. input1 = sc.nextDouble();
  34. if(input1>0)
  35. {
  36. product *= input1;
  37. //product = product * input;
  38. }
  39.  
  40. if(input1<0)
  41. {
  42. System.out.println("Number Skipped:");
  43. }
  44.  
  45. }
  46. while (input1!=0);
  47. System.out.println("Total:"+product);
  48.  
  49.  
  50. }
  51.  
  52. if (input==2){ int input2, first, last,count,num;
  53. input2=first=last=count=num=0;
  54. //input will hold the value coming into the program
  55. //first will hold the index of the first instance of the number 12
  56. //last will hold the index for the last instance of the number 12
  57. //count will hold the index for the the input being evaluated.
  58. //num will hold the number of 12's in the string.
  59.  
  60. System.out.println("");
  61. System.out.println("");
  62. System.out.println("Enter a string of whole numbers.");
  63. System.out.println("I will tell you how many times you entered the number \"12\".");
  64. System.out.println("I will also tell you where the location of the first and last index of \"12\".");
  65.  
  66. BufferedReader br;
  67. br = new BufferedReader( new InputStreamReader( System.in ) );
  68. String line = br.readLine();
  69. StringTokenizer st = new StringTokenizer( line );
  70. while(st.hasMoreTokens() )
  71. {
  72. input2 = Integer.parseInt(st.nextToken());
  73. count++;
  74. if(first==0)
  75. {
  76. if(input2 == 12)
  77. {
  78. first = count;
  79. last = count;
  80. num++;
  81.  
  82. }
  83. }
  84. else
  85. {
  86. if(input2==12)
  87. {
  88. num++;
  89. last=count;
  90. }
  91. }
  92. }
  93. System.out.println("The first instance of the number 12 is located at index " + first);
  94. if(first !=0)
  95. {
  96. System.out.println("You entered " + num + " \"12's\"");
  97. System.out.println("The last instance of the number 12 is located at index " + last);
  98. System.out.println("Have a great day!");
  99. }
  100.  
  101.  
  102. }
  103. if(input==3){
  104. BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  105.  
  106. int counter=0;
  107. int total=0;
  108. int min = Integer.MAX_VALUE;
  109. int max = Integer.MIN_VALUE;
  110. String temp;
  111.  
  112. System.out.println("Enter as many numbers as you like");
  113. String input3 = bf.readLine();
  114. StringTokenizer st = new StringTokenizer(input3);
  115.  
  116. while (st.hasMoreTokens()){
  117. int Num = Integer.parseInt(st.nextToken());
  118. if (Num>max){
  119. max = Num;}
  120. if (Num<min){
  121. min = Num;}
  122.  
  123. counter++;
  124. total += Num;
  125.  
  126.  
  127. }
  128. float average = (float)total/counter;
  129.  
  130. System.out.println("The Average value is: " + average);
  131. System.out.println("Maximum: " + max);
  132. System.out.println("Minimum: " + min);
  133.  
  134.  
  135.  
  136. }
  137. if(input==4){
  138. int sumA=0;
  139. int sumB=0;
  140. int sumC=0;
  141. int sumD=0;
  142. int sumF=0;
  143.  
  144.  
  145. BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  146. System.out.println("Enter Exam Scores");
  147. String input4 = bf.readLine();
  148. StringTokenizer st = new StringTokenizer(input4);
  149.  
  150.  
  151. while (st.hasMoreTokens()){
  152. int Num = Integer.parseInt(st.nextToken());
  153.  
  154.  
  155.  
  156. if(Num>=90)
  157. {
  158. sumA++;
  159. System.out.println(Num + " A");
  160. }
  161. else if(Num >= 70)
  162. {
  163. sumB++;
  164. System.out.println(Num+ " B");
  165. }
  166. else if(Num >= 50)
  167. {
  168. sumC++;
  169. System.out.println(Num+ " C");
  170. }
  171. else if(Num >= 35)
  172. {
  173. sumD++;
  174. System.out.println(Num + " D");
  175. }
  176. else
  177. {
  178. sumF++;
  179. System.out.println(Num + " F");}
  180.  
  181.  
  182.  
  183.  
  184. }
  185. System.out.println("The total number of A's is " + sumA );
  186. System.out.println("The total number of B's is " + sumB);
  187. System.out.println("The total number of C's is " + (sumC ));
  188. System.out.println("The total number of D's is " + (sumD ));
  189. System.out.println("The total number of F's is " + (sumF ));
  190.  
  191.  
  192. }
  193. if(input==5){
  194. System.exit(1);
  195.  
  196.  
  197. }
  198. }while (input!=-1);
  199. sc.close();
  200.  
  201.  
  202. }}