Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. static Scanner in = new Scanner(System.in);
  5.  
  6. public static void main(String[] args) {
  7.  
  8. tar1();
  9. tar2();
  10. tar3();
  11. tar4();
  12. tar5();
  13. tar6();
  14. tar7();
  15. tar8();
  16.  
  17. }
  18.  
  19. public static void tar9() {
  20. //is in the word document
  21. }
  22.  
  23. public static void tar8() {
  24. int iBags,iSumBagsPlane = 0,iPrevBagsPlanes;
  25. int iPlaneMaxBags = 1,iPlaneMinBags = 1;
  26. boolean bTwoBags = true;
  27.  
  28. //finds which plane had the maximum amount of carry on and the min amount
  29. //finds if there were planes with at least Passenger who had less than 2 bags
  30. for (int i = 1; i <= 20; i++) {
  31.  
  32. iPrevBagsPlanes = iSumBagsPlane;
  33. iSumBagsPlane = 0;
  34.  
  35. for (int j = 1; j <= 250; j++) {
  36.  
  37. System.out.println("How many bags does passenger number " + j + " have as carry on");
  38. iBags = in.nextInt();
  39.  
  40. iSumBagsPlane += iBags;
  41.  
  42. if (iBags < 2)
  43. bTwoBags = false;
  44.  
  45. }
  46.  
  47. if (iSumBagsPlane > iPrevBagsPlanes)
  48. iPlaneMaxBags = i;
  49. if (iSumBagsPlane < iPrevBagsPlanes)
  50. iPlaneMinBags = i;
  51.  
  52.  
  53. }
  54. System.out.println("plane number " + iPlaneMaxBags + " had the maximum amount of bags");
  55. System.out.println("plane number " + iPlaneMinBags + " had the minimum amount of bags");
  56.  
  57. if (bTwoBags)
  58. System.out.println("all the planes had more than two bags");
  59. else
  60. System.out.println("There were planes with passengers who had less than 2 bags");
  61.  
  62. }
  63.  
  64. public static void tar7() {
  65. int iMark,iSumClass = 0;
  66. double iAverageClass = 0,iAverageGrade = 0;
  67.  
  68. //finds the average mark for a class and for the grade
  69. for (int i = 1; i <= 10; i++) {
  70.  
  71. for (int j = 1; j <= 30; j++) {
  72. System.out.println("How much did student number " + j + " get in the test");
  73. iMark = in.nextInt();
  74.  
  75. iSumClass += iMark;
  76. }
  77. iAverageClass = iSumClass/30.0;
  78. iAverageGrade += iAverageClass;
  79.  
  80. System.out.println("The average mark for class number " + i + " is: " + iAverageClass);
  81. iSumClass = 0;
  82. }
  83. iAverageGrade = iAverageGrade/10.0;
  84. System.out.println("The average mark for the grade is: " + iAverageGrade);
  85. }
  86.  
  87. public static void tar6() {
  88. int iNum,iNum1,iSum = 0;
  89.  
  90. //receives an input the a list then finds difference between input and list
  91. for (int i = 1; i <= 5; i++) {
  92. System.out.println("Enter a number");
  93. iNum = in.nextInt();
  94.  
  95. System.out.println("Enter another number");
  96. iNum1 = in.nextInt();
  97. iSum += iNum1;
  98.  
  99. while (iNum1 != 0) {
  100. System.out.println("Enter another number");
  101. iNum1 = in.nextInt();
  102. iSum += iNum1;
  103. }
  104. System.out.println("The difference between the two numbers is: " + (iNum-iSum));
  105. iSum = 0;
  106.  
  107. }
  108. }
  109.  
  110. public static void tar5() {
  111. int iNum,iFactorial = 1;
  112.  
  113. System.out.println("Enter a number");
  114. iNum = in.nextInt();
  115.  
  116. //does factorial for an input by a user (ex:6! = 720)
  117. while (iNum >= 0)
  118. {
  119. for (int i = 1; i <= iNum; i++)
  120. iFactorial = iFactorial * i;
  121.  
  122. System.out.println(iNum + "!" + " = " + iFactorial);
  123. iFactorial = 1;
  124.  
  125. System.out.println("Enter a number");
  126. iNum = in.nextInt();
  127.  
  128. }
  129. }
  130.  
  131. public static void tar4() {
  132. int iMoney,iSumClass = 0,iSumSchool = 0,iStudents;
  133.  
  134. //finds how many students are in a class and how much each student donated
  135. //finds average for class and for school and prints to screen
  136. for (int i = 1; i <= 30; i++)
  137. {
  138. System.out.println("How many students are in class number " + i + "?");
  139. iStudents = in.nextInt();
  140. for (int j = 1; j <= iStudents; j++)
  141. {
  142. System.out.println("How much did student number " + j + " donate?");
  143. iMoney = in.nextInt();
  144. iSumClass += iMoney;
  145. iSumSchool += iMoney;
  146. }
  147. System.out.println("Class number " + i + " donated a total of " + iSumClass + " shekels!");
  148. iSumClass = 0;
  149. }
  150. System.out.println("The school donated " + iSumSchool + " shekels");
  151.  
  152. }
  153.  
  154. public static void tar3() {
  155. int iNum,iNum2;
  156.  
  157. //receives two pares of numbers and show the numbers from smallest to highest between the two
  158. for (int i = 1; i <= 20; i++)
  159. {
  160.  
  161. System.out.println("Enter a number");
  162. iNum = in.nextInt();
  163. System.out.println("Enter a second number");
  164. iNum2 = in.nextInt();
  165.  
  166. if(iNum2 < iNum)
  167. {
  168. for (int j = iNum2; j <= iNum ; j++)
  169. System.out.println(j);
  170. }
  171.  
  172. else if(iNum2 > iNum)
  173. {
  174. for (int j = iNum; j <= iNum2 ; j++)
  175. System.out.println(j);
  176. }
  177.  
  178. else
  179. System.out.println("The numbers your entered were equal");
  180.  
  181. }
  182.  
  183.  
  184. }
  185.  
  186. public static void tar2() {
  187. int iGrade,iSum = 0;
  188.  
  189. //loops through 35 kids and finds average of all grades
  190. for (int i = 1; i <= 35; i++)
  191. {
  192. for (int j = 1; j <= 12 ; j++)
  193. {
  194. System.out.println("Enter your grades");
  195. iGrade = in.nextInt();
  196. iSum += iGrade;
  197. }
  198. System.out.println("The average of student number " + i + " is: " + (iSum/12.0));
  199. }
  200.  
  201. }
  202.  
  203. public static void tar1() {
  204.  
  205. int iNum;
  206. //loops through and printss out 1- the number you entered
  207. for (int i = 1; i <= 10; i++) {
  208. System.out.println("Enter a number");
  209. iNum = in.nextInt();
  210.  
  211. for (int j = 1; j <= iNum; j++)
  212. System.out.println(j);
  213.  
  214. }
  215. }
  216.  
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement