Fines.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2018 Muhammad M. Imtiaz
  2. // This Work is subject to the terms of the Universal Permissive License,
  3. // Version 1.0. If a copy of the licence was not distributed with this Work,
  4. // you can obtain one at <https://oss.oracle.com/licenses/upl/>.
  5. /**
  6. * Muhammad M. Imtiaz
  7. * Friday 5 October 2018
  8. * Informs individuals about overdue books that have been checked out of a library.
  9. **/
  10. public class Fines {
  11. public static void main(String[] args) {
  12. String[] nameInfo;
  13. String title;
  14. String dateCheckedOut;
  15. int daysOverdue;
  16. double dailyFine;
  17. java.util.Scanner scanner = new java.util.Scanner(System.in);
  18. String name;
  19. String userId;
  20. double totalFine;
  21. System.out.print("Enter name (Last, First) and Social Security Number (###-##-####): ");
  22. nameInfo = scanner.nextLine().split(" ");
  23. name = nameInfo[0] + " " + nameInfo[1];
  24. userId = nameInfo[0].substring(0, Math.min(5, nameInfo[0].length() - (nameInfo[0].endsWith(",") ? 1 : 0))) +
  25. nameInfo[1].substring(0, Math.min(3, nameInfo[1].length())) +
  26. "-" +
  27. nameInfo[2].substring(7, 11);
  28. System.out.println();
  29. System.out.print("Enter the title of the book: ");
  30. title = scanner.nextLine();
  31. System.out.println();
  32. System.out.print("Enter the date checked out (mm/dd/yyyy): ");
  33. dateCheckedOut = scanner.nextLine();
  34. System.out.println();
  35. System.out.print("Days late: ");
  36. daysOverdue = scanner.nextInt();
  37. System.out.print("Daily fine: ");
  38. dailyFine = scanner.nextDouble();
  39. totalFine = daysOverdue * dailyFine;
  40. System.out.println();
  41. System.out.println();
  42. System.out.println("To: " + name + "\tAccount: " + userId);
  43. System.out.println("From: mona");
  44. System.out.println("Subject: Overdue Notice");
  45. System.out.println("============================================================");
  46. System.out.println(title + " was checked out on: " + dateCheckedOut);
  47. System.out.println("This book is currently " + daysOverdue + " days late.");
  48. System.out.println("Your fine has accumulated to: " + totalFine);
  49. }
  50. }