博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第二本书 (课后题)懒得写了 准备都写这一个里面了- -、
阅读量:5086 次
发布时间:2019-06-13

本文共 6573 字,大约阅读时间需要 21 分钟。

1、类图 随意写个类 然后new model 选个model新建 然后直接把写好的类拖进model 自动生成类图

2、领养宠物并输出宠物信息

package com.opp.unit3.demo8; /**  * Created by 渣渣飞 on 2018/6/11 20:12  * 星期一  * FDF  */ public class Dog {
public String name; public int age; public String brand; public String getName() {
return name; } public void setName(String name) {
this.name = name; } public int getAge() {
return age; } public void setAge(int age) {
this.age = age; } public String getBrand() {
return brand; } public void setBrand(String brand) {
this.brand = brand; } public Dog() {
name="狗"; age=2; brand="傻狗"; } public void showInfo() {
System.out.println("名字" + name +"年龄"+age+"种类"+brand); } }
package com.opp.unit3.demo8; /**  * Created by 渣渣飞 on 2018/6/11 20:12  * 星期一  * FDF  */ public class Test {
public static void main(String[] args) {
Dog dog=null; dog=new Dog(); dog.showInfo(); } }
package com.opp.unit3.pratice; /**  * Created by 渣渣飞 on 2018/6/11 20:52  * 星期一  * FDF  */ public class Student {
private String name; private int age; private String grender; public String getName() {
return name; } public void setName(String name) {
this.name = name; } public int getAge() {
return age; } public void setAge(int age) {
if (age > 16) {
this.age = age; } else {
System.out.println("输入错误!"); } } public String getGrender() {
return grender; } public void setGrender(String grender) {
this.grender = grender; } public void show() {
System.out.println("姓名:" + name + "年龄" + age + "性别" + grender); } }
package com.opp.unit3.pratice; import java.util.Scanner; /**  * Created by 渣渣飞 on 2018/6/11 21:03  * 星期一  * FDF  */ public class Test {
public static void main(String[] args) {
Student stu=null; stu=new Student(); Scanner scanner=new Scanner(System.in); System.out.println("请输入姓名:"); String name=scanner.next(); stu.setName(name); System.out.println("请输入年龄:"); int age=scanner.nextInt(); stu.setAge(age); System.out.println("请输入性别:"); String grender=scanner.next(); stu.setGrender(grender); stu.show(); } }
package com.opp.unit4.demo1; /**  * Created by 渣渣飞 on 2018/6/12 21:09  * 星期二  * FDF  */ public abstract class Car {
/** * 无参方法赋值! */ protected static String number; protected static String brade; public Car() {
number = "AU8769"; brade = "大奔"; } /** * 带参方法 * * @param number * @param brade */ public Car(String number, String brade) {
this.number = number; this.brade = brade; } public double pay(int days,int type){
return 0; } }
package com.opp.unit4.demo1; import java.util.Random; import java.util.Scanner; /**  * Created by 渣渣飞 on 2018/6/12 21:07  * 星期二  * FDF  */ public class MyMain {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); SaloonCar saloonCar= new SaloonCar(); PassengerCar passengerCar = new PassengerCar(); Random random = new Random(); int randomNum=random.nextInt(1000); System.out.println("欢迎来到汽车租赁"); /** * 天数 * 类型 * */ System.out.println("请输入您要租赁的天数"); int day=scanner.nextInt(); System.out.println("请输入要租赁的汽车类型(1,轿车 2,客车)"); int che = scanner.nextInt(); if (che == 1) {
System.out.println("请输入要租赁汽车品牌(1,宝马 2,别克)"); int xin = scanner.nextInt(); if (xin == 1) {
System.out.println("请输入轿车的型号(1,商务舱GL8 2,林荫大道)"); int xinhao = scanner.nextInt(); System.out.println("您好,分配给您的汽车牌号是:京KU" + randomNum); double money = saloonCar.pay(day, che); // 得到费用 System.out.println("顾客你好!你需要支付的租赁金额为:" + money); } if (xin == 2) {
System.out.println("请输入轿车的型号(1,商务舱GL8 2,林荫大道)"); int xinhao = scanner.nextInt(); System.out.println("您好,分配给您的汽车牌号是:鲁LD" + randomNum); double money = saloonCar.pay(day, che); // 得到费用 System.out.println("顾客你好!你需要支付的租赁金额为:" + money); } } if (che == 2) {
System.out.println("请输入要租赁客车的品牌(1.金杯 2.金龙)"); int pin = scanner.nextInt(); System.out.println("请输入客车的座位数"); int ke = scanner.nextInt(); System.out.println("您好,分配给您的汽车牌号是:京KU" + randomNum); double money = passengerCar.pay(day, che); // 得到费用 System.out.println("顾客你好!你需要支付的租赁金额为:" + money); } } }
package com.opp.unit4.demo1; /**  * Created by 渣渣飞 on 2018/6/12 21:09  * 星期二  * FDF  */ public class PassengerCar extends Car {
private int seatCount; /** * 无参的构造 */ public PassengerCar() {
seatCount = 23; } public PassengerCar(int seatCount) {
super(number, brade); this.seatCount = seatCount; } public int gettype() {
return seatCount; } public double pay(int days, int type) {
double money = 0; if (type > 16) {
money = days * 1000; } else {
money = days * 500; } return money; } }
package com.opp.unit4.demo1; /**  * Created by 渣渣飞 on 2018/6/12 21:10  * 星期二  * FDF  */ public class SaloonCar extends Car {
private String type; /** * 无参构造 */ public SaloonCar() {
type = "商务舱"; } public SaloonCar(String type) {
super(number, brade); this.type = type; } public String getType() {
return type; } /** * 租金 */ public double pay(int days, int type) {
double money = 0; switch (type) {
case 1: money = days * 500; break; case 2: money = days * 600; break; case 3: money = days * 300; break; default: System.out.println("输入错误"); } return money; } }
 

转载于:https://www.cnblogs.com/yunfeioliver/p/9169348.html

你可能感兴趣的文章
asp.net 下OnClientClick的妙用
查看>>
实现最大索引堆
查看>>
Java equals和hashcode 的区别
查看>>
Redis 笔记与总结1 安装部署
查看>>
Web前端面试题集锦
查看>>
Android 通过AIDL在两个APP之间Service通信
查看>>
关于笔试题输入输出的小问题
查看>>
HTTP 错误 404.2 - Not Found
查看>>
对象指针:
查看>>
mako的模板继承语法
查看>>
sublime添加书签
查看>>
打造自己的图表控件3
查看>>
mysql innodb引擎模式的表在服务重启后自动字段值重置为最大自增字段值的问题...
查看>>
18周监考
查看>>
页面打印
查看>>
POJ 1896
查看>>
数组al[0,mid-1] 和 al[mid,num-1],都分别有序。将其merge成有序数组al[0,num-1],要求空间复杂度O(1)...
查看>>
test
查看>>
B. Color the Fence
查看>>
与pandas初相识
查看>>