简单计算器与面积结合计算器
import java.util.Scanner;
public class Study2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入运算种类");
System.out.println("1、四则运算");
System.out.println("2、面积计算");
Scanner scanner3=new Scanner(System.in);
System.out.print("选择: ");
int number1=scanner3.nextInt();
if (number1==1)
{
System.out.println("1、减法运算");
System.out.println("2、加法运算");
System.out.println("3、乘法运算");
System.out.println("4、除法运算");
CatA cat1=new CatA();
Scanner scanner4=new Scanner(System.in);
System.out.print("选择: ");
int number2=scanner4.nextInt();
if (number2==1)
{
Scanner scanner1=new Scanner(System.in);
System.out.print("请输入第一个数: ");
cat1.a=scanner1.nextInt();
Scanner scanner2=new Scanner(System.in);
System.out.print("请输入第二个数: ");
cat1.b=scanner2.nextInt();
System.out.print("结果:"+cat1.a+"-"+cat1.b+"=");cat1.jianFa();
}
else if(number2==2)
{
Scanner scanner1=new Scanner(System.in);
System.out.print("请输入第一个数: ");
cat1.a=scanner1.nextInt();
Scanner scanner2=new Scanner(System.in);
System.out.print("请输入第二个数: ");
cat1.b=scanner2.nextInt();
System.out.print("结果:"+cat1.a+"+"+cat1.b+"=");cat1.jiaFa();
}
else if(number2==3)
{
Scanner scanner1=new Scanner(System.in);
System.out.print("请输入第一个数: ");
cat1.a=scanner1.nextInt();
Scanner scanner2=new Scanner(System.in);
System.out.print("请输入第二个数: ");
cat1.b=scanner2.nextInt();
System.out.print("结果:"+cat1.a+"*"+cat1.b+"=");cat1.chengFa();
}
else if(number2==4)
{
Scanner scanner1=new Scanner(System.in);
System.out.print("请输入第一个数: ");
cat1.a=scanner1.nextInt();
Scanner scanner2=new Scanner(System.in);
System.out.print("请输入第二个数: ");
cat1.b=scanner2.nextInt();
System.out.print("结果:"+cat1.a+"/"+cat1.b+"=");cat1.chuFa();
}
else {System.out.println("您输入的有误,请重新选择");}
}else if(number1==2) {
System.out.println("1、矩形面积计算");
System.out.println("2、三角形面积计算");
System.out.println("3、圆形面积计算");
Scanner scanner4=new Scanner(System.in);
System.out.print("选择: ");
int number2=scanner4.nextInt();
CatA cat1=new CatA();
if(number2==1)
{
Scanner scanner1=new Scanner(System.in);
System.out.print("请输入边长: ");
cat1.a=scanner1.nextInt();
Scanner scanner2=new Scanner(System.in);
System.out.print("请输入高: ");
cat1.b=scanner2.nextInt();
System.out.print("结果:"+cat1.a+"*"+cat1.b+"=");cat1.zhengFxmj();;
}
else if (number2==2)
{
Scanner scanner1=new Scanner(System.in);
System.out.print("请输入三角形的底: ");
cat1.a=scanner1.nextInt();
Scanner scanner2=new Scanner(System.in);
System.out.print("请输入三角形的高: ");
cat1.b=scanner2.nextInt();
System.out.print("结果:"+"("+cat1.a+"*"+cat1.b+")"+"/"+"2"+"=");cat1.sanJxmj();
}
else if(number2==3)
{
Scanner scanner1=new Scanner(System.in);
System.out.print("请输圆的半径: ");
cat1.a=scanner1.nextInt();
System.out.print("结果:"+"3.14"+"*"+cat1.a+"^"+"=");cat1.yuanXmj();
}else {System.out.println("您输入的有误,请重新选择");}
}else {System.out.println("您输入的有误,请重新选择");}
}
}
class CatA
{
int a;
int b;
public void jianFa() //减法函数
{
System.out.println(a-b);
}
public void jiaFa() //加法函数
{
System.out.println(a+b);
}
public void chengFa() //乘法函数
{
System.out.println(a*b);
}
public void chuFa() //除法函数
{
System.out.println((float)a/(float)b);
}
public void zhengFxmj() //矩形形面积
{
System.out.println(a*b);
}
public void sanJxmj() //三角形面积
{
System.out.println((a*b)/2);
}
public void yuanXmj() //圆形面积
{
a=(int)Math.pow(a, 2);
System.out.println(3.14*a);
}
}