Java基础⿊马程序员教材案例4-5..图形的⾯积与周长计算程序、案例4-7经理与
员⼯⼯资代码
⼀、 4-5图形的⾯积与周长计算程序
import Scanner;
import*;
public class areaCount {
public void menu (){
System.out.println ("输⼊1计算圆的周长、⾯积");
System.out.println ("输⼊2计算长⽅形的周长、⾯积");
Scanner scanner =new Scanner (System.in);
int choice = Int ();
if(choice ==1){
yuan yuan =new yuan ();
System.out.println ("输⼊圆的周长");
double r = Double ();
yuan.areaCount ( r);
yuan.zhouchangCount (r);
}else if(choice ==2){
changfangxing changfangxing =new changfangxing ();
System.out.println ("依次输⼊长⽅形的长和宽");
double Double ();
double Double ();
changfangxing.areaCount (length,width);
changfangxing.zhouchangCount (length,width);
}
程序员一般工资多少钱一个月}
public static void main (String[] args){
areaCount areaCount=new areaCount ();
}
abstract class graph {
double area =0;
double zhouchang =0;
}
class yuan extends graph {
double r =0;
public void areaCount (double r){
area =3.14*(r * r);
System.out.print ("⾯积是:");
System.out.println (area);
}
public void zhouchangCount (double r){
zhouchang =2*3.14* r;
System.out.print ("周长是:");
System.out.println (zhouchang);
}
}
class changfangxing extends graph {
double length =0;
double width =0;
public void areaCount (double length,double width){
area = length * width;
System.out.print ("⾯积是:");
System.out.println (area);
}
public void zhouchangCount (double length,double width){ zhouchang =(length + width)*2;
System.out.print ("周长是:");
System.out.println (zhouchang);
}
}
}
⼆、案例4-7经理与员⼯⼯资代码
public class salary {
public static void main (String[] args){
jingli guan=new jingli ();
guan.salary=10000000;
normal zjw=new normal ();
zjw.salary=100000000;
guan.work ();
zjw.work ();
System.out.println ("经理⼯资"+guan.salary);
System.out.println ("普通员⼯⼯资"+zjw.salary);
}
}
class Person{
String name;
String address;
int id;
int salary;
int age;
public void work(){
}
}
class jingli extends Person{
@Override
public void work(){
salary+=0.2*salary;
}
}
class normal extends Person{
@Override
public void work(){
salary+=0.1*salary;
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论