HarrJ

Day 11

Sep 26th, 2023 (edited)
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. package week2;
  2. import java.util.Scanner;
  3. public class Day11A {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         String option;
  7.         double interestYearly = 0, interestMonthly = 0;
  8.  
  9.         System.out.println("Choose Conversion");
  10.         System.out.println("1 - yearly to monthly");
  11.         System.out.println("2 - monthly to yearly");
  12.         option = sc.nextLine();
  13.  
  14.         switch (option) {
  15.             case "1":
  16.                 System.out.print("Enter yearly interest: ");
  17.                 interestYearly = sc.nextDouble();
  18.                 //dahil static yung mga method, di na need gawan ng object
  19.                 interestMonthly = yearToMonth(interestYearly);
  20.                 break;
  21.             case "2":
  22.                 System.out.print("Enter monthly interest: ");
  23.                 interestMonthly = sc.nextDouble();
  24.                 interestYearly = monthToYear(interestMonthly);
  25.                 break;
  26.             default:
  27.                 System.out.println("not part of options");
  28.         }
  29.         System.out.println("yearly interest: " + interestYearly);
  30.         System.out.println("monthly interest: " + interestMonthly);
  31.     }
  32.  
  33.     public static double yearToMonth(double interestYearly){
  34.         double interestMonthly = 100 * (Math.pow(((1+interestYearly)/100), (1/12)) - 1);
  35.        
  36.         return interestMonthly;
  37.     }
  38.  
  39.     public static double monthToYear(double interestMonthly){
  40.         double interestYearly = 0;
  41.  
  42.         return interestYearly;
  43.     }
  44. }
  45.  
  46. //-----------------------------------------
  47.  
  48. package week2;
  49. import java.time.LocalDate;
  50. import java.time.LocalDateTime;
  51. import java.time.LocalTime;
  52. import java.util.Locale;
  53. import java.text.ParseException;
  54. import java.text.SimpleDateFormat;
  55. import java.util.Date;
  56.  
  57. public class Day11B {
  58.     public static void main(String[] args) {
  59.  
  60.         LocalDateTime dateTimeNow = LocalDateTime.now();
  61.         System.out.println(dateTimeNow);
  62.         LocalDate dateNow = dateTimeNow.toLocalDate();
  63.         System.out.println(dateNow);
  64.         LocalTime timeNow = dateTimeNow.toLocalTime();
  65.         System.out.println(timeNow);
  66.  
  67.         LocalDate dateOnly = LocalDate.parse("2023-09-15");
  68.         //pag parse iisang klase lang ng date na style ang tanggap nya
  69.         System.out.println(dateOnly);
  70.         System.out.println(dateOnly.getDayOfWeek());
  71.  
  72.         SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
  73.         String dateString = "10/19/2023";
  74.         try {
  75.             Date dateOnly2 = sdf.parse(dateString);
  76.             System.out.println(dateOnly2);
  77.         } catch (ParseException e) {
  78.         }
  79.        
  80.         System.out.println("from " + dateNow + " to " + dateOnly);
  81.         System.out.println(dateNow.compareTo(dateOnly));
  82.     }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment