Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Day09A {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- double num1, num2;
- String op;
- System.out.println("Enter the math operation(+ - * /):");
- op = sc.nextLine();
- System.out.print("Enter 1st Number: ");
- num1 = sc.nextDouble();
- System.out.print("Enter 2nd Number: ");
- num2 = sc.nextDouble();
- if (op.equals("+")) {
- System.out.println(num1 + "+" + num2 + "=" + (num1+num2));
- } else if (op.equals("-")) {
- System.out.println(num1 + "-" + num2 + "=" + (num1-num2));
- }
- // else if (op.equals("_")) {
- // System.out.println(num1 + "_" + num2 + "=" + (num1_num2));
- // }
- else {
- System.out.println("Operator not found");
- }
- }
- }
- //-------------------------------
- public class Day09B {
- public static void main(String[] args) {
- //gagawa ng reference/object
- // ClassName varName = new ClassName();
- Day09B callMe = new Day09B();
- callMe.print1();
- callMe.print1();
- callMe.print2();
- callMe.printCombo();
- }
- void print1() {
- System.out.println("I am print one");
- }
- void print2() {
- System.out.println("Speedy 2");
- }
- void printCombo() {
- System.out.println("Calling other methods");
- print1();
- print2();
- }
- }
- //-------------------------------
- import java.util.Scanner;
- public class Day09C {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Day09C callMe = new Day09C();
- double length, width;
- System.out.print("Enter rectangle length: ");
- length = sc.nextDouble();
- System.out.print("Enter rectangle width: ");
- width = sc.nextDouble();
- callMe.computePerimeter(length, width);
- callMe.computeArea(length, width);
- }
- void computePerimeter(double length, double width){
- double perimeter = 2 * (length + width);
- System.out.print("perimeter: ");
- System.out.println(perimeter);
- }
- void computeArea(double length, double width){
- double area = length * width;
- System.out.print("area: ");
- System.out.println(area);
- }
- }
- //-------------------------------
- import java.util.Scanner;
- public class Day09D {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Day09D callMe = new Day09D();
- double length = 0, width = 0, height = 0, result = 0;
- int opt;
- String label = "";
- System.out.println("What to compute?");
- System.out.println("1 - Rectangle Area");
- System.out.println("2 - Rectangular Prism Volume");
- System.out.println("3 - Rectangular Prism Surface Area");
- System.out.print(">> ");
- opt = sc.nextInt();
- if (opt >= 1 && opt <= 3) {
- System.out.print("Enter rectangle length: ");
- length = sc.nextDouble();
- System.out.print("Enter rectangle width: ");
- width = sc.nextDouble();
- if (opt > 1) {
- System.out.print("Enter rectangle height: ");
- height = sc.nextDouble();
- }
- }
- switch (opt) {
- case 1:
- label = "area";
- result = callMe.computeArea(length, width);
- break;
- case 2:
- label = "volume";
- result = callMe.computeVolume(length, width, height);
- break;
- case 3:
- label = "surface area";
- result = callMe.computeSurfaceArea(length, width, height);
- break;
- }
- System.out.println(label + " : " + result);
- }
- double computeArea(double length, double width){
- double area = length * width;
- return area;
- }
- double computeVolume(double length, double width, double height){
- double volume = length * width * height;
- return volume;
- }
- double computeSurfaceArea(double length, double width, double height){
- double sArea = 0;
- return sArea;
- }
- }
Advertisement