rushdie

presentation Home Work - 2

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