初学者急需两道简单的java代码

菜鸟急需两道简单的java代码
1. 编写一个程序,要求在运行时,输入一个数字n,程序运行后,直接输出n!的结果
2. 定义一个抽象类shape,它有两个抽象方法 area() 和 perimeter(), 定义一个圆和一个正方形,分别集成shape, 定义一个主类,在其中计算圆和正方形的面积与周长。
还要运行结果的截图,有哪位高手可以帮忙一下,感激不尽

------解决方案--------------------
Java code


import java.util.Scanner;

/**
 * 求n的阶乘
 * @author jileniao.net
 *
 */
public class NJieCheng {

    public static void main(String[] args) {
        System.out.println("input a number");
        
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();

        int result = 1;
        
        for (int i = 1 ; i <= n; i++) {
            result *= i;
        }
        System.out.println(n + "! = " + result);
    }
}

------解决方案--------------------
Java code

package com.zf;

/**
 * 定义形状类
 * @author Administrator
 *
 */
abstract class Shape{
    public abstract double area();            
    public abstract double perimeter();
}

/**
 * 定义圆形类
 * @author Administrator
 *
 */
class Circle extends Shape{
    private double r ;        //半径
    
    @Override
    public double area() {
        // 实现计算面积的方法
        return Math.PI * r * r;
    }

    @Override
    public    double perimeter() {
        // 实现计算周长的方法
        return Math.PI * r * 2;
    }

    public double getR() {
        return r;
    }

    public void setR(double r) {
        this.r = r;
    }
}

/**
 * 定义正方形类
 * @author Administrator
 *
 */
class Square extends Shape{
    private double width ;        //边长
    
    @Override
    public double area() {
        // 实现计算面积的方法
        return width * width;
    }
    
    @Override
    public    double perimeter() {
        // 实现计算周长的方法
        return width * 4;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }
}

/**
 * 测试类
 * @author Administrator
 *
 */
public class Test2 {
    public static void main(String[] args) {
        Circle c = new Circle();    //实例化一个圆形类
        Square s = new Square();    //实例化一个正方形类
        c.setR(4);    //设置圆形的半径
        s.setWidth(5);    //设置正方形的边长
        System.out.println("半径为" + c.getR() + "的圆的面积为:" + c.area());
        System.out.println("半径为" + c.getR() + "的圆的周长为:" + c.perimeter());
        System.out.println("边长为" + s.getWidth() + "的正方形的面积为:" + s.area());
        System.out.println("边长为" + s.getWidth() + "的正方形的周长为:" + s.perimeter());
    }
    
}

------解决方案--------------------
Java code

package com.zf;

import java.util.Scanner;

public class Test1 {
    /**
     * 计算阶乘
     * @param n
     * @return
     */
    public static int calcJc(int n){
        if(n > 1){
            return n * calcJc(n -1); 
        }else{
            return 1;
        }
    }
    
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println(Test1.calcJc(input.nextInt()));
    }
}