6回目のジョブ--staticキーワード、オブジェクト

8406 ワード

##テーマ1
##Computer
package Train.Method.TeachDemo.Thread.Fuction;

/**
 *  n      
 * @author  
 * @date 2019 9 18   1:19:34
 */
public class Computer {
    public int num;

    public Computer() {
    }

    public Computer(int num) {
        this.num = num;
    }

    public long counter() {
        long sum = 1;
        for (int i = 1; i <= num; i++) {
            sum = sum * i;
        }
        return sum;
    }
}

##Test
package Train.Method.TeachDemo.Thread.FuctionTest;
import Train.Method.TeachDemo.Thread.Fuction.Computer;

import java.util.Scanner;

import Train.Method.TeachDemo.Thread.Fuction.Computer;
/**
 * Test
 * @author  
 * @date 2019 9 18   8:08:53
 */
public class ComputerTest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("       :");
        int num = input.nextInt();
        
        Computer t = new Computer(num);
        System.out.println(t.counter());
    }
} 

##テーマ2
##MyPoint
/**
 *    
 * 
 * @author  
 * @date 2019 9 18   8:12:32
 */
public class MyPoint {
    private int x;
    private int y;

    public MyPoint() {

    }

    public MyPoint(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public static double distance(MyPoint p1, MyPoint p2) {
        int xside = Math.abs(p1.x - p2.x);
        int yside = Math.abs(p1.y - p2.y);
        double temp = Math.pow(xside, 2) + Math.pow(yside, 2);
        return (Math.sqrt(temp));
    }
}

##Test
import java.util.Scanner;

/**
 *       
 * @author  
 * @date 2019 9 18   3:53:51
 */
public class Test {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("   p1    ");
        int x1 = input.nextInt();
        int y1 = input.nextInt();
        System.out.println("   p2    ");
        int x2 = input.nextInt();
        int y2 = input.nextInt();
        
        MyPoint p1 = new MyPoint(x1, y1);
        MyPoint p2 = new MyPoint(x2, y2);
        System.out.println("        ;" + MyPoint.distance(p1, p2));
    }
}