HarrJ

Day 09 recap

Nov 17th, 2023 (edited)
998
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.46 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Day09A {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.         double num1, num2;
  6.         String op;
  7.        
  8.         System.out.println("Enter the math operation(+ - * /):");
  9.         op = sc.nextLine();
  10.         System.out.print("Enter 1st Number: ");
  11.         num1 = sc.nextDouble();
  12.         System.out.print("Enter 2nd Number: ");
  13.         num2 = sc.nextDouble();
  14.        
  15.         if (op.equals("+")) {
  16.             System.out.println(num1 + "+" + num2 + "=" + (num1+num2));
  17.         } else if (op.equals("-")) {
  18.             System.out.println(num1 + "-" + num2 + "=" + (num1-num2));
  19.         }
  20. //        else if (op.equals("_")) {
  21. //            System.out.println(num1 + "_" + num2 + "=" + (num1_num2));
  22. //        }
  23.         else {
  24.             System.out.println("Operator not found");
  25.         }
  26.     }
  27. }
  28.  
  29. //-------------------------------
  30. public class Day09B {
  31.     public static void main(String[] args) {
  32.         //gagawa ng reference/object
  33.         // ClassName varName = new ClassName();
  34.         Day09B callMe = new Day09B();
  35.        
  36.         callMe.print1();
  37.         callMe.print1();
  38.         callMe.print2();
  39.         callMe.printCombo();
  40.     }
  41.    
  42.     void print1() {
  43.         System.out.println("I am print one");
  44.     }
  45.     void print2() {
  46.         System.out.println("Speedy 2");
  47.     }
  48.     void printCombo() {
  49.         System.out.println("Calling other methods");
  50.         print1();
  51.         print2();
  52.     }
  53. }
  54.  
  55.  
  56. //-------------------------------
  57.  
  58. import java.util.Scanner;
  59.  
  60. public class Day09C {
  61.     public static void main(String[] args) {
  62.         Scanner sc = new Scanner(System.in);
  63.         Day09C callMe = new Day09C();
  64.         double length, width;
  65.        
  66.         System.out.print("Enter rectangle length: ");
  67.         length = sc.nextDouble();
  68.         System.out.print("Enter rectangle width: ");
  69.         width = sc.nextDouble();
  70.        
  71.         callMe.computePerimeter(length, width);
  72.         callMe.computeArea(length, width);
  73.     }
  74.    
  75.     void computePerimeter(double length, double width){
  76.         double perimeter = 2 * (length + width);
  77.        
  78.         System.out.print("perimeter: ");
  79.         System.out.println(perimeter);
  80.     }
  81.    
  82.     void computeArea(double length, double width){
  83.         double area = length * width;
  84.        
  85.         System.out.print("area: ");
  86.         System.out.println(area);
  87.     }
  88. }
  89.  
  90.  
  91. //-------------------------------
  92.  
  93. import java.util.Scanner;
  94.  
  95. public class Day09D {
  96.     public static void main(String[] args) {
  97.         Scanner sc = new Scanner(System.in);
  98.         Day09D callMe = new Day09D();
  99.         double length = 0, width = 0, height = 0, result = 0;
  100.         int opt;
  101.         String label = "";
  102.        
  103.        
  104.         System.out.println("What to compute?");
  105.         System.out.println("1 - Rectangle Area");
  106.         System.out.println("2 - Rectangular Prism Volume");
  107.         System.out.println("3 - Rectangular Prism Surface Area");
  108.         System.out.print(">> ");
  109.         opt = sc.nextInt();
  110.        
  111.         if (opt >= 1 && opt <= 3) {
  112.             System.out.print("Enter rectangle length: ");
  113.             length = sc.nextDouble();
  114.             System.out.print("Enter rectangle width: ");
  115.             width = sc.nextDouble();
  116.             if (opt > 1) {
  117.                 System.out.print("Enter rectangle height: ");
  118.                 height = sc.nextDouble();
  119.             }
  120.         }
  121.        
  122.         switch (opt) {
  123.             case 1:
  124.                 label = "area";
  125.                 result = callMe.computeArea(length, width);
  126.                 break;
  127.             case 2:
  128.                 label = "volume";
  129.                 result = callMe.computeVolume(length, width, height);
  130.                 break;
  131.             case 3:
  132.                 label = "surface area";
  133.                 result = callMe.computeSurfaceArea(length, width, height);
  134.                 break;
  135.         }
  136.        
  137.         System.out.println(label + " : " +  result);
  138.     }
  139.        
  140.     double computeArea(double length, double width){
  141.         double area = length * width;
  142.        
  143.         return area;
  144.     }
  145.     double computeVolume(double length, double width, double height){
  146.         double volume = length * width * height;
  147.        
  148.         return volume;
  149.     }
  150.    
  151.     double computeSurfaceArea(double length, double width, double height){
  152.         double sArea =  0;
  153.        
  154.         return sArea;
  155.     }
  156. }
  157.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment