public interface ShapeArea(){
public double area();
}
public class MyRectangle(){
public static double area(double x,double y){
return xy;
}
public class MyTriangle(){
public static double area(double x,double y,double z){
double s=x+y+z;
returnMathsqrt(s(s-x)(s-y)(s-z));
}
public class Test(){
public static void mian(String[] args){
Systemoutprintln(MyRectanglearea(5,10));
Systemoutprintln(MyTrianglearea(3,4,5));
}
}
}
下面是BankAccount类的代码:
public class BankAccount {
private String name;
private double balance;
private int year;
private double rate = 001d;
public String getName() {
return name;
}
public void setName(String name) {
thisname = name;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
thisrate = rate;
}
public double getBalance() {
return balance;
}
public BankAccount() {
thisbalance = 10d;
thisyear = 1;
}
public BankAccount(double balance, int year) {
thisbalance = balance;
thisyear = year;
}
public void save(double balance, int year) {
thisbalance = thisbalance + balance;
thisyear = year;
}
public void fetch(double balance) {
thisbalance = thisbalance - balance;
thisyear = 0;
}
public double calcTotal() {
return thisbalance thisrate thisyear + thisbalance;
}
}
下面是BankTest类的代码:
public class BankTest {
public static void main(String[] args) {
BankAccount account = new BankAccount(1000d, 3);
accountsetName("Tom");
accountsave(2000d, 3);
Systemoutprintln("该账户的姓名:" + accountgetName());
Systemoutprintln("该账户的存款额:" + accountgetBalance());
Systemoutprintln("该账户的总金额:" + accountcalcTotal());
}
}
下面是运行结果:
麻烦您看一下,是否能够满足要求。
class Circle
{
double radius;
double diameter;
double area;
public Circle()
{
radius=1;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
thisradius = radius;
}
//下面这个方法用于计算机圆的直径
public double computeDiameter()
{
return 2radius;
}
public double computeArea()
{
return MathPIradiusradius;
}
}
public class TestCircle {
public static void main(String args[])
{
Circle c1=new Circle();
Circle c2=new Circle();
Circle c3=new Circle();
c2setRadius(5);
c3setRadius(10);
Systemoutprint("第一个圆的直径为:"+c1computeDiameter());
Systemoutprintln(" 面积为:"+c1computeArea());
Systemoutprint("第二个圆的直径为:"+c2computeDiameter());
Systemoutprintln(" 面积为:"+c2computeArea());
Systemoutprint("第三个圆的直径为:"+c3computeDiameter());
Systemoutprintln(" 面积为:"+c3computeArea());
}
}
//人接口
public interface Human {
void speak();
}
//教师类
public class Teacher implements Human {
public void speak() {
Systemoutprintln("speak");
}
public void teach() {
Systemoutprintln("teach");
}
}
//学生类
public class Student implements Human {
public void speak() {
Systemoutprintln("speak");
}
public void learn() {
Systemoutprintln("learn");
}
}
//测试类
class HumanTest {
@Test
void test() {
Teacher teacher=new Teacher();
Student stu=new Student();
teacherteach();
teacherspeak();
stulearn();
stuspeak();
}
}
运行结果:
teach
speak
learn
speak
以上就是关于java语言程序设计题全部的内容,包括:java语言程序设计题、java程序设计、java 程序设计题目解答等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)