Advertisement
rushdie

Presentation - 2 Exercise

Nov 20th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.83 KB | None | 0 0
  1. package test;
  2. import java.util.Scanner;
  3. public class Exercise1 {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7. Scanner s = new Scanner(System.in);
  8.  
  9. // Define variables
  10. int NumOfRooms;
  11. int NumofDays;
  12. double Price;
  13. boolean IsDuplex = false;
  14. char Duplex;
  15.  
  16.  
  17. //Set the input from user - number of rooms and if its 5 rooms then ask weather its a duplex or regular
  18.  
  19. System.out.println("Please enter the number of Rooms you wish? ");
  20. NumOfRooms = s.nextInt();
  21.  
  22. System.out.println("Please enter the number of Days you wish? ");
  23. NumofDays = s.nextInt();
  24.  
  25.  
  26. //if number of rooms < 5 then check if its 3 bedrooms price = $120 else its 4 bedrooms price = $150
  27. switch(NumOfRooms)
  28. {
  29. case 3:
  30. System.out.println("Total cost is "+NumofDays*120);
  31. break;
  32. case 4:
  33. System.out.println("Total cost is "+NumofDays*150);
  34. break;
  35. case 5:
  36. System.out.println("Would like Regular Rooms Yes or Duplex No? Y or N");
  37. Duplex = s.next().charAt(0);
  38. if(Duplex == 'Y' || Duplex == 'y')
  39. {
  40. IsDuplex = true;
  41. }
  42. if(IsDuplex)
  43. {
  44. System.out.println("Total cost is "+NumofDays*200);
  45. }
  46. else
  47. {
  48. System.out.println("your cost is "+NumofDays*180);
  49. }
  50. break;
  51. }
  52.  
  53. }
  54. }
  55.  
  56. package test;
  57. import java.util.Scanner;
  58.  
  59. public class Exercise2 {
  60.  
  61. public static void main(String[] args) {
  62. // TODO Auto-generated method stub
  63. Scanner s = new Scanner(System.in);
  64. // Define Variables
  65. double CostSale1;
  66. double CostSale2;
  67. double TotalPaid;
  68. int NumOfItems;
  69.  
  70. // Input from User TotalPaid and number of Articles he/she wishes to purchase
  71.  
  72. System.out.println("Enter the total cost of your Purchase! ");
  73. TotalPaid = s.nextDouble();
  74. System.out.println("Enter the total number of Articles in your Purchase! ");
  75. NumOfItems = s.nextInt();
  76.  
  77. // Calculate cost going by Sale price 1 and Sale price 2 depend on Articles bought
  78.  
  79. if(NumOfItems < 3 && TotalPaid >=300)
  80. {
  81. TotalPaid = TotalPaid - 50;
  82. System.out.println("Your total cost after the sale is: $"+TotalPaid);
  83. System.out.println("Sorry, We must use this option - You bought Less than 3 Articles");
  84. }
  85. if(TotalPaid >= 300 && NumOfItems >=3)
  86. {
  87. CostSale1 = TotalPaid - 50;
  88. CostSale2 = TotalPaid * 0.8;
  89. //Compare After Discount of Sale1 and sale 2 and Notify user with results
  90.  
  91. if(CostSale1 < CostSale2)
  92.  
  93. {
  94. System.out.println("Your total cost after sale 1 is: $"+CostSale1);
  95. System.out.println("Sorry, We must use this option - You bought Less than 3 Articles");
  96.  
  97. }
  98. else
  99. {
  100. System.out.println("Your total cost after sale 2 is: $"+CostSale2);
  101. System.out.println("We gladly used this option - You bought 3 or More Articles");
  102. }
  103.  
  104. }
  105.  
  106. }
  107. }
  108. package test;
  109. import java.util.Scanner;
  110.  
  111. public class Exercise3 {
  112.  
  113. /**
  114. * @param args
  115. */
  116. public static void main(String[] args) {
  117. // TODO Auto-generated method stub
  118. Scanner s = new Scanner(System.in);
  119.  
  120. double FinalGrade;
  121. double TempGrade;
  122. int MidGrade;
  123. int HomeWorkGr;
  124. int ClassAttend;
  125. int ExamGrade;
  126.  
  127. //Get from the user the percentage of their attendance in class
  128. System.out.println("Enter the Percentage of Student Attendence! ");
  129. ClassAttend = s.nextInt();
  130.  
  131. if(ClassAttend < 80)
  132. {
  133. FinalGrade = 0;
  134. System.out.println("Your final Grade is :"+FinalGrade);
  135.  
  136. }
  137. else
  138. {
  139. //Input Student Test Grade if its = 60 or greater than 60 input Mid grade and Home Work grade
  140. System.out.println("Enter Student Test Grade! ");
  141. ExamGrade = s.nextInt();
  142. if (ExamGrade >= 60)
  143. {
  144. System.out.println("Enter Student Mid Grade! ");
  145. MidGrade = s.nextInt();
  146. System.out.println("Enter Student Home Work Grade! ");
  147. HomeWorkGr = s.nextInt();
  148.  
  149. if(MidGrade > ExamGrade)
  150. {
  151. TempGrade =(0.8 * ExamGrade) + (0.2 * MidGrade);
  152. }
  153. else
  154. {
  155. TempGrade = ExamGrade;
  156. }
  157.  
  158. FinalGrade = (0.1 * HomeWorkGr)+(0.9 * TempGrade);
  159. }
  160.  
  161. else
  162. {
  163. FinalGrade = ExamGrade;
  164. }
  165.  
  166. }
  167. System.out.println(" Your Final Grade is: "+FinalGrade);
  168. }
  169. }package test;
  170. import java.util.Scanner;
  171.  
  172. public class Exercise4 {
  173.  
  174. public static void main(String[] args) {
  175. // TODO Auto-generated method stub
  176. Scanner s = new Scanner(System.in);
  177.  
  178. double Salary;
  179. double IncomeTax;
  180. int NumKids;
  181. double TaxReturn;
  182. boolean Adult=false;
  183. char isAdult;
  184. boolean LocationGolibar = false;
  185. char Liveby;
  186.  
  187. //Get from the user Salaryand the number of Kids and if they live next to Grandparents
  188. System.out.println("Enter your Income! ");
  189. Salary = s.nextDouble();
  190.  
  191. System.out.println("Enter the number of your kids! ");
  192. NumKids = s.nextInt();
  193.  
  194.  
  195. // To figure out the Income tax rate
  196. if (Salary < 5000)
  197. {
  198. IncomeTax = 0;
  199.  
  200. }
  201. else if (Salary >= 5000 && Salary <= 10000)
  202. {
  203. IncomeTax = 0.1 * Salary;
  204. }
  205. else if( Salary >= 10000 && Salary <= 15000)
  206. {
  207. IncomeTax = 0.35 * Salary;
  208.  
  209. }
  210. else
  211. {
  212. IncomeTax = .5 * Salary;
  213. }
  214. // to figure out if elgible for Discount and in what percentage of Discount
  215. System.out.println("Do you live close to your Gilibart! Y for yes or N for NO");
  216. Liveby = s.next().charAt(0);
  217.  
  218. if(Liveby == 'y' || Liveby == 'Y')
  219. {
  220. LocationGolibar = true;
  221. }
  222. System.out.println("Are you an Adult over 18 years Old! Y for yes or N for NO");
  223. isAdult = s.next().charAt(0);
  224.  
  225. if(isAdult == 'y' || isAdult == 'Y')
  226. {
  227. Adult = true;
  228. }
  229. if(Adult)
  230. {
  231. if(LocationGolibar && Salary < 10000 )
  232. {
  233. IncomeTax = IncomeTax - 400;
  234. }
  235. if (NumKids > 3)
  236. {
  237. IncomeTax = IncomeTax - 900;
  238. }
  239. else
  240. {
  241. IncomeTax = IncomeTax - (NumKids * 300);
  242. }
  243. }
  244. else
  245. {
  246. IncomeTax = IncomeTax - (IncomeTax * 0.5);
  247. }
  248. System.out.println( "Your Income Tax is :"+IncomeTax);
  249.  
  250.  
  251. }
  252.  
  253. }package test;
  254. import java.util.Scanner;
  255.  
  256. public class Exercise5 {
  257.  
  258. public static void main(String[] args) {
  259. // TODO Auto-generated method stub
  260. Scanner s = new Scanner(System.in);
  261. double XTestScore;
  262. double NHomeWork;
  263. double YHomeworkAvg;
  264.  
  265. // get the input from student
  266. System.out.println("Enter the Test Score! ");
  267. XTestScore = s.nextInt();
  268.  
  269. System.out.println("Enter the number of home Work you Submited! ");
  270. NHomeWork = s.nextInt();
  271.  
  272. System.out.println("Enter your Averge Grade for Homeworks! ");
  273. YHomeworkAvg = s.nextDouble();
  274.  
  275.  
  276. // case Student's number of home works is less than or equal 4 - test
  277. // score is final
  278.  
  279. if (NHomeWork <= 4 )
  280. {
  281. System.out.println("Your Total Score is :" + XTestScore);
  282.  
  283. }
  284. // case2 Student's number of home works is less than or equal 7 - Check
  285. // test score >= 60
  286. // and test score < 60 calculate score by getting Percentage on home
  287. // works and score
  288. else if ((NHomeWork > 4 && NHomeWork < 8 )&& (XTestScore >= 60))
  289. {
  290. XTestScore = 0.8 * XTestScore + 0.2 * YHomeworkAvg;
  291. System.out.println("Your Total Score is :" + XTestScore);
  292.  
  293. } else if ((NHomeWork > 4 && NHomeWork < 8 ) && (XTestScore < 60)) {
  294. XTestScore = 0.9 * XTestScore + 0.1 * YHomeworkAvg;
  295. System.out.println("Your Total Score is :" + XTestScore);
  296. }
  297. // case Student's number of home works is bigger than or equal 8 - Check
  298. // test score >= 60
  299. // and test score < 60 calculate score by getting Percentage on home
  300. // works and score
  301.  
  302. if (NHomeWork >= 8 && XTestScore >= 60)
  303. {
  304. XTestScore = 0.7 * XTestScore + 0.3 * YHomeworkAvg;
  305. System.out.println("Your Total Score is :" + XTestScore);
  306. } else
  307. if (NHomeWork >= 8 && XTestScore < 60)
  308. {
  309. XTestScore = 0.6 * XTestScore + 0.4 * YHomeworkAvg;
  310. System.out.println("Your Total Score is :" + XTestScore);
  311.  
  312. }
  313.  
  314. }
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement