Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.27 KB | None | 0 0
  1. // Use System Namespace
  2. using System;
  3.  
  4. // Begin CS5-Student Fee Class
  5. class CS5_Student_Fee
  6. {
  7. // Set Enrollment Rate constant = $20
  8. const int ENROLLMENT_RATE_Integer = 20;
  9. // Set Non-Resident Rate constant = $162
  10. const int NON_RESIDENT_RATE_Integer = 162;
  11. // Set Non-US Citizen Rate constant = $182
  12. const int NON_US_CITIZEN_RATE_Integer = 182;
  13. // Set Minimum Units constant = 0.5
  14. const decimal MINIMUM_UNITS_Decimal = 0.5M;
  15. // Set Maximum Units constant = 24
  16. const decimal MAXIMUM_UNITS_Decimal = 24.0M;
  17.  
  18.  
  19. // *************************************************************************
  20. // * Method : Main *
  21. // * Description : This method calls the Input Student Data and Display *
  22. // * Information methods. It displays an end of program *
  23. // * message when completed. *
  24. // *************************************************************************
  25.  
  26. // Begin Main ()
  27. static void Main()
  28. {
  29.  
  30. // Define Variables: Units, Resident Code, Answer
  31. decimal unitsDecimal; string residentCodeString, answerString;
  32.  
  33. // Do
  34. do
  35. {
  36. // Clear Screen
  37. Console.Clear();
  38. // Display Three Title Lines
  39. Console.WriteLine("-------------------------------");
  40. Console.WriteLine("**** Student Fee Program ****");
  41. Console.WriteLine("-------------------------------");
  42. // Display Blank Line
  43. Console.WriteLine();
  44. // Call Input Student Data (Out: Units, Resident Code)
  45. InputStudentData(out unitsDecimal, out residentCodeString);
  46. // Display Blank Line
  47. Console.WriteLine();
  48. // Display "Call Display Information"
  49. Console.WriteLine("Call Display Information");
  50. // Display Blank Line
  51. Console.WriteLine();
  52.  
  53. // Do
  54. do
  55. {
  56. // Display Enter More Fee Data Prompt
  57. Console.Write("Enter more fee data (Y/N) ? ");
  58. // Input Answer
  59. answerString = Console.ReadLine().ToUpper();
  60. // While ( Answer Not = "Y" And Answer Not = "N" )
  61. } while (answerString != "Y" && answerString != "N");
  62. // While ( Answer = "Y" )
  63. } while (answerString == "Y");
  64.  
  65. // Clear Screen
  66. Console.Clear();
  67. // Display End of Program Message
  68. Console.WriteLine("End of Student Fee Program!");
  69. // Display Blank Line
  70. Console.WriteLine();
  71. // Display Press any key Prompt
  72. Console.Write("Press any key to continue . . .");
  73. // Input Press Any Key
  74. Console.ReadKey();
  75.  
  76. } // End Main
  77.  
  78. // *************************************************************************
  79. // * Method : Input Student Data *
  80. // * Description : This method inputs the units and residents code from *
  81. // * the keyboard. It must validate the input data that it *
  82. // * is within the specified limits. It returns the units *
  83. // * and resident code as output parameters when *
  84. // * completed. *
  85. // *************************************************************************
  86.  
  87. // Begin Input Student Data ( Out: Units, Resident Code )
  88. static void InputStudentData ( out decimal unitsDecimal,
  89. out string residentCodeString )
  90. {
  91. // Define Variables: None
  92.  
  93. // Display Units Prompt
  94. Console.Write("Enter Units (" + MINIMUM_UNITS_Decimal + " to "
  95. + MAXIMUM_UNITS_Decimal + ") : ");
  96. // Input Units
  97. decimal.TryParse(Console.ReadLine(), out unitsDecimal);
  98. // Do While ( Units < Minimum Units constant Or Units > Maximum Units constant )
  99. while (unitsDecimal < MINIMUM_UNITS_Decimal || unitsDecimal > MAXIMUM_UNITS_Decimal)
  100. {
  101. // Display Units Error Message
  102. Console.Write("Units Error - Try Again : ");
  103. // Input Another Units
  104. decimal.TryParse(Console.ReadLine(), out unitsDecimal);
  105. }// End Do
  106.  
  107. // Display Blank Line
  108. Console.WriteLine();
  109. // Display Residency Codes (4 lines)
  110. Console.WriteLine("Residency Codes:");
  111. Console.WriteLine("R - Resident of California");
  112. Console.WriteLine("N - Non-California Resident");
  113. Console.WriteLine("F - Non-US Citizen");
  114. // Display Blank Line
  115. Console.WriteLine();
  116. // Display Resident Code Prompt
  117. Console.Write("Enter Residency (R,N,F) :");
  118. // Input Resident Code
  119. residentCodeString = Console.ReadLine().ToUpper();
  120.  
  121. // Do While ( Resident Code Not = "R" And Resident Code Not = "N" And Resident Code Not = "F" )
  122. while (residentCodeString != "R" && residentCodeString != "N" && residentCodeString != "F")
  123. {
  124. // Display Resident Code Error Message
  125. Console.Write("Code Error - Try Again :");
  126. // Input Another Resident Code
  127. residentCodeString = Console.ReadLine().ToUpper();
  128. } // End Do
  129.  
  130. } // End Input Student Data
  131.  
  132. // *****************************************************************************
  133. // * CS5-Student Fee *
  134. // *****************************************************************************
  135. // * *
  136. // * Programmer : Ziad Bogalia *
  137. // * Chapter : CS5 *
  138. // * Assignment : Example *
  139. // * Class Name : CS5-Student Fee *
  140. // * Date Created : 3/18/2019 *
  141. // * Description : This class determines a studen'ts enrollment fee. *
  142. // * *
  143. // *****************************************************************************
  144.  
  145. // Use System Namespace
  146. using System;
  147.  
  148. // Begin CS5-Student Fee Class
  149. class CS5_Student_Fee
  150. {
  151. // Set Enrollment Rate constant = $20
  152. const int ENROLLMENT_RATE_Integer = 20;
  153. // Set Non-Resident Rate constant = $162
  154. const int NON_RESIDENT_RATE_Integer = 162;
  155. // Set Non-US Citizen Rate constant = $182
  156. const int NON_US_CITIZEN_RATE_Integer = 182;
  157. // Set Minimum Units constant = 0.5
  158. const decimal MINIMUM_UNITS_Decimal = 0.5M;
  159. // Set Maximum Units constant = 24
  160. const decimal MAXIMUM_UNITS_Decimal = 24.0M;
  161.  
  162. // *************************************************************************
  163. // * Method : Main *
  164. // * Description : This method calls the Input Student Data and Display *
  165. // * Information methods. It displays an end of program *
  166. // * message when completed. *
  167. // *************************************************************************
  168.  
  169. // Begin Main ()
  170. static void Main()
  171. {
  172. // Define Variables: Units, Resident Code, Answer
  173. decimal unitsDecimal;
  174. string residentCodeString, answerString;
  175.  
  176. // Do
  177. do
  178. {
  179. // Clear Screen
  180. Console.Clear();
  181. // Display Three Title Lines
  182. Console.WriteLine("-------------------------------");
  183. Console.WriteLine("**** Student Fee Program ****");
  184. Console.WriteLine("-------------------------------");
  185. // Display Blank Line
  186. Console.WriteLine();
  187. // Call Input Student Data (Out: Units, Resident Code)
  188. InputStudentData(out unitsDecimal, out residentCodeString);
  189. // Display Blank Line
  190. Console.WriteLine();
  191. // Call Display Information ( In: Units, Resident Code)
  192. DisplayInformation(unitsDecimal, residentCodeString);
  193. // Display Blank Line
  194. Console.WriteLine();
  195.  
  196. // Do
  197. do
  198. {
  199. // Display Enter More Fee Data Prompt
  200. Console.Write("Enter more fee data (Y/N) ? ");
  201. // Input Answer
  202. answerString = Console.ReadLine().ToUpper();
  203. // While ( Answer Not = "Y" And Answer Not = "N" )
  204. } while (answerString != "Y" && answerString != "N");
  205.  
  206. // While ( Answer = "Y" )
  207. } while (answerString == "Y");
  208.  
  209. // Clear Screen
  210. Console.Clear();
  211. // Display End of Program Message
  212. Console.WriteLine("End of Student Fee Program!");
  213. // Display Blank Line
  214. Console.WriteLine();
  215. // Display Press any key Prompt
  216. Console.Write("Press any key to continue . . .");
  217. // Input Press Any Key
  218. Console.ReadKey();
  219.  
  220. } // End Main
  221.  
  222. // *************************************************************************
  223. // * Method : Input Student Data *
  224. // * Description : This method inputs the units and residents code from *
  225. // * the keyboard. It must validate the input data that it *
  226. // * is within the specified limits. It returns the units *
  227. // * and resident code as output parameters when *
  228. // * completed. *
  229. // *************************************************************************
  230.  
  231. // Begin Input Student Data ( Out: Units, Resident Code )
  232. static void InputStudentData(out decimal unitsDecimal, out string residentCodeString)
  233. {
  234. // Define Variables: None
  235.  
  236. // Display Units Prompt
  237. Console.Write("Enter Units (" + MINIMUM_UNITS_Decimal + " to "
  238. + MAXIMUM_UNITS_Decimal + ") : ");
  239. // Input Units
  240. decimal.TryParse(Console.ReadLine(), out unitsDecimal);
  241. // Do While ( Units < Minimum Units constant Or Units > Maximum Units constant )
  242. while (unitsDecimal < MINIMUM_UNITS_Decimal ||
  243. unitsDecimal > MAXIMUM_UNITS_Decimal)
  244. {
  245. // Display Units Error Message
  246. Console.Write("Units Error - Try Again : ");
  247. // Input Another Units
  248. decimal.TryParse(Console.ReadLine(), out unitsDecimal);
  249. } // End Do
  250.  
  251. // Display Blank Line
  252. Console.WriteLine();
  253. // Display Residency Codes (4 lines)
  254. Console.WriteLine("Residency Codes:");
  255. Console.WriteLine("R - Resident of California");
  256. Console.WriteLine("N - Non-California Resident");
  257. Console.WriteLine("F - Non-US Citizen");
  258. // Display Blank Line
  259. Console.WriteLine();
  260. // Display Resident Code Prompt
  261. Console.Write("Enter Residency (R,N,F) : ");
  262. // Input Resident Code
  263. residentCodeString = Console.ReadLine().ToUpper();
  264. // Do While ( Resident Code Not = "R" And Resident Code Not = "N" And Resident Code Not = "F" )
  265. while (residentCodeString != "R" && residentCodeString != "N" &&
  266. residentCodeString != "F")
  267. {
  268. // Display Resident Code Error Message
  269. Console.Write("Code Error - Try Again : ");
  270. // Input Another Resident Code
  271. residentCodeString = Console.ReadLine().ToUpper();
  272. } // End Do
  273.  
  274. } // End Input Student Data
  275.  
  276. // *************************************************************************
  277. // * Method : Display Information *
  278. // * Description : This module displays the student's units, rate and *
  279. // * enrollment fee. The fee is calculated by multiplying *
  280. // * the Units by the Unit Rate. The Unit Rate is obtained *
  281. // * by calling the Get Unit Rate module. It receives the *
  282. // * units and resident code as input arguements *
  283. // *************************************************************************
  284.  
  285. // Begin Display Information ( In: Units, Resident Code )
  286. static void DisplayInformation(decimal unitsDecimal,
  287. string residentCodeString)
  288. {
  289. // Define Variables: Fee
  290. decimal feeDecimal;
  291. // Display Units
  292. Console.WriteLine("Your Units are " + unitsDecimal);
  293. // Display Call Get Unit Rate (In: Resident Code)
  294. Console.WriteLine("Your Rate Per Unit is " +
  295. GetUnitRate(residentCodeString).ToString("C0"));
  296. // Display Blank Line
  297. Console.WriteLine();
  298. // Calculate Fee = Units * Call Get Unit Rate (In: Resident Code )
  299. feeDecimal = unitsDecimal * GetUnitRate(residentCodeString);
  300. // Display Fee
  301. Console.WriteLine("Your Enrollment Fee is " +
  302. feeDecimal.ToString("C2"));
  303.  
  304. } // End Display Information
  305.  
  306. // *************************************************************************
  307. // * Method : Get Unit Rate *
  308. // * Description : This value returning method determines a unit rate *
  309. // * based upon the resident code. All students pay the *
  310. // * enrollment fee. Non-Residents of California and *
  311. // * Non-US Citizens pay their respective rate plus the *
  312. // * enrollment rate. It receives the resident code as an *
  313. // * input argument and returns the rate as a whole number *
  314. // * value when completed. *
  315. // *************************************************************************
  316.  
  317. // Begin Get Unit Rate ( In: Resident Code ) As a Whole Number
  318. static int GetUnitRate(string residentCodeString)
  319. {
  320.  
  321. // Define Variables: Rate
  322. int rateInteger;
  323. // IF Resident Code = "R"
  324. if (residentCodeString == "R")
  325. // Rate = Enrollment Rate constant
  326. rateInteger = ENROLLMENT_RATE_Integer;
  327. // Else IF Resident Code = "N"
  328. else if (residentCodeString == "N")
  329. // Rate = Non-Resident Rate constant + Enrollment Rate constant
  330. rateInteger = NON_RESIDENT_RATE_Integer +
  331. ENROLLMENT_RATE_Integer;
  332. // Else
  333. else
  334. // Rate = Non-US Citizen Rate constant + Enrollment Rate constant
  335. rateInteger = NON_US_CITIZEN_RATE_Integer +
  336. ENROLLMENT_RATE_Integer;
  337. // End IF
  338.  
  339. // Return Rate
  340. return rateInteger;
  341.  
  342. } // End Get Unit Rate
  343.  
  344. } // End CS5-Student Fee Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement