JAVA学习homework的Car、Bus、motoVehicle
MotoVehicle
package com.mashibing.homework;/*** @author: 马士兵教育* @create: 2019-08-31 15:33*/
public abstract class MotoVehicle {private int no;private String brand;public MotoVehicle(){}public MotoVehicle(int no,String brand){this.no = no;this.brand = brand;}public int getNo() {return no;}public void setNo(int no) {this.no = no;}public String getBrand() {return brand;}public void setBrand(String brand) {this.brand = brand;}public abstract int calcRent(int day);
}
Bus
package com.mashibing.homework;/*** @author: 马士兵教育* @create: 2019-08-31 15:34*/
public class Bus extends MotoVehicle {private int seatcount;public Bus(){}public Bus(int no,String brand,int seatcount){super(no,brand);this.seatcount = seatcount;}public int getSeatcount() {return seatcount;}public void setSeatcount(int seatcount) {this.seatcount = seatcount;}@Overridepublic int calcRent(int day) {if(seatcount>16){return 1500*day;}else{return 800*day;}}
}
Car
package com.mashibing.homework;/*** @author: 马士兵教育* @create: 2019-08-31 15:34*/
public class Car extends MotoVehicle{private String type;public Car(){}public Car(String type) {this.type = type;}public Car(int no,String brand,String type){super(no,brand);this.type= type;}public String getType() {return type;}public void setType(String type) {this.type = type;}@Overridepublic int calcRent(int day) {if(type.equals("0")){return 600*day;}else if(type.equals("1")){return 500*day;}else if(type.equals("2")){return 300*day;}else{System.out.println("类型不匹配");return 0;}}
}
TestMotoVehicle
package com.mashibing.homework;/*** @author: 马士兵教育* @create: 2019-08-31 15:44*/
public class TestMotoVehicle {public static void main(String[] args) {// MotoVehicle moto = new MotoVehicle();
// Car car = new Car(1,"宝马","1");
// System.out.println("租金是:"+car.calcRent(5));
// Bus bus = new Bus(2,"金龙",20);
// System.out.println("租金是:"+bus.calcRent(5));MotoVehicle[] moto = new MotoVehicle[5];moto[0] = new Car(1,"宝马","1");moto[1] = new Car(1,"宝马","1");moto[2] = new Car(2,"别克","2");moto[3] = new Bus(3,"金龙",34);moto[4] = new Track(4,"解放",50);int totalMoney = calcTotal(moto);System.out.println("总租金是:"+totalMoney);}public static int calcTotal(MotoVehicle[] moto){int totalMoney = 0;for(int i = 0;i<moto.length;i++){totalMoney+=moto[i].calcRent(5);}return totalMoney;}
}
Track
package com.mashibing.homework;/*** @author: 马士兵教育* @create: 2019-08-31 16:50*/
public class Track extends MotoVehicle {private int weight;public Track(){}public Track(int no,String brand,int weight){super(no,brand);this.weight = weight;}@Overridepublic int calcRent(int day) {return 50*day*weight;}
}
JAVA学习homework的Car、Bus、motoVehicle相关推荐
- Java入门1.2.3—一个老鸟的Java学习心得
Java入门1.2.3-一个老鸟的Java学习心得 基本信息 作者: 臧萌 出版社:清华大学出版社 ISBN:9787302217831 上架时间:2010-3-30 出版日期:2010 年3月 ...
- Java学习笔记系列-入门篇-计算机基础
Java学习笔记 Java学习笔记是一个持续更新的系列,工作多年,抽个空对自身知识做一个梳理和总结归纳,温故而知新,同时也希望能帮助到更多正在学习Java 的同学们. 本系列目录: 入门篇 计算机基础 ...
- Java学习记录_1:MOOC《零基础学Java语言》课后习题解
Hey,我是寒水,一名大二学生,电子商务专业在读,正在学习Java中.我试图将在Java学习中遇到的一些困惑和最终的解答发在这个账号上,希望以此来激励我不要放弃学习! 在学习记录这个专题中,我收藏一些 ...
- 【最新版】Java学习路线(含B站口碑推荐视频链接)
文章目录 关于如何自学 一.计算机网络 二.数据结构与算法 三.操作系统 四.计算机组成原理 五.编译原理 六.设计模式 七.MySQL 八.实操工具 九.JAVA并发与JVM 十.Redis 十一. ...
- java学习基础联系题 使用if··else if ···else循环语句设计公交车刷卡程序
java学习基础联系题 使用if··else if ···else循环语句设计公交车刷卡程序 import java.util.Scanner; public class Bus{public sta ...
- Java学习路线图,如何学习Java事半功倍?
作为一个初学者想掌握Java并不是很容易,Java本身是具有一定难度的,虽然说兴趣这东西可以让我们学习不累,但是有多少人学习是因为兴趣,或者有多少人知道自己的兴趣在哪?所以我很明确的告诉你学习这事本来 ...
- Java学习必不可少的网站,快收藏起来
java技术在IT互联网行业的发展前景一直在提升,越来越多的人都在学习java技术,今天小编来给大家提供一些学习Java的网站集合,希望能够帮助到正在学习java技术的同学. Java学习必不可少的网 ...
- 分享五款java学习辅助工具,总有你用的上的~
想要学好java技术,除了自身的努力,辅助工具也不缺少,辅助工具可以帮助大家在今后的工作中可以提高工作效率,下面小编就来分享五款java学习辅助工具,总有你用的上的~ 五款java学习辅助工具: 1. ...
- Java学习从入门到精通的学习建议
想要学好java技术,首先打好基础很重要,不论学什么基础都是重中之重,学习Java更是如此.如:基础语法.核心类库.面向对象编程.异常.集合.IO流等基础如果学不好,那么后边更深入的语法也不容易学会. ...
- java学习笔记11--Annotation
java学习笔记11--Annotation Annotation:在JDK1.5之后增加的一个新特性,这种特性被称为元数据特性,在JDK1.5之后称为注释,即:使用注释的方式加入一些程序的信息. j ...
最新文章
- 计算机及网络应用基础思维导图_计算机基础/算法/面试题 PDF+思维导图下载
- tcp前4字节消息长度_RocketMQ的消息存储格式
- nyoj-491--幸运三角形--简单深搜枚举(TLE)
- 解决SwipeRefreshLayout与Banner滑动冲突
- 【LeetCode】【HOT】148. 排序链表(归并排序)
- vivo X Fold跑分曝光:搭载骁龙8+12GB内存
- Myeclipse学习总结(1)——Myeclipse优化配置
- 什么是低信噪比图像及处理方法
- Atitit 把项目外包的面临的风险attilax总结
- 如何改变报表在页面显示的大小和位置?
- Redis -- 数据库常用命令大全
- xmr-stak-cpu 安装及使用
- java pdf 转图片
- 计算机组装后要干什么,电脑组装完后还有哪些事需要干?
- 1386. Cinema Seat Allocation
- 谈谈新加坡的教育和学区房
- 0行代码,实现植物大战僵尸脚本
- WAF应用防火墙的功能
- java中什么是空指针异常以及为什么会产生空指针异常
- Jupyter notebook 绘图时,如何生成高清图片?
热门文章
- 基于PHP和MySQL的奶茶网站,基于PHP和MySQL的网站设计与实现
- 今天,我们求知若渴、虚心若愚(附技术PPT)
- cpu第几代计算机,怎么看cpu是几代的,来看看你的CPU是几代的?
- Grain Timers and Reminders
- IgA | 对抗病原菌,帮助共生菌定植的“重要开关”
- 我在上海奋斗五年 从月薪3500到700万
- Notion笔记软件简介
- 二、Win10如何解决svchost一直占用网速和内存?
- CVPR21Look Closer to Segment Better: Boundary Patch Refinement for Instance Segmentation
- Codeforces 106C Buns 【0-1背包】