import java.awt.GridLayout
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.event.FocusAdapter
import java.awt.event.FocusEvent
import java.sql.Date
import java.util.Calendar
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JTextField
public class ZuJin extends JFrame {
/**
* (结束日期-开始日期)÷30×月租金+业务费用+其他费用=总费用
〔(结束日期-开始日期)÷30×月租金+业务费用+其他费用〕÷合租人员=平均费用
需要弹出一个租金计算器对话框 分为租金计算信息与租金计算结果两部分
*/
public ZuJin(){
Container c=getContentPane()
c.setLayout(new GridLayout(5, 4))
JLabel j1=new JLabel("开始日期")
c.add(j1)
JTextField jt1=new JTextField(10)
c.add(jt1)
JLabel j2=new JLabel("结束日期")
c.add(j2)
JTextField jt2=new JTextField("")
c.add(jt2)
JLabel j3=new JLabel("月租金(元)")
c.add(j3)
JTextField jt3=new JTextField(5)
c.add(jt3)
JLabel j4=new JLabel("业务费(元)")
c.add(j4)
JTextField jt4=new JTextField(5)
c.add(jt4)
JLabel j5=new JLabel("其他费用(元)")
c.add(j5)
JTextField jt5=new JTextField(5)
c.add(jt5)
JLabel j6=new JLabel("合租人员数量")
c.add(j6)
JTextField jt6=new JTextField(3)
c.add(jt6)
JLabel j7=new JLabel("总费用(元)")
c.add(j7)
JTextField jt7=new JTextField(5)
jt7.setEditable(false)
c.add(jt7)
JLabel j8=new JLabel("平均费用(元)")
c.add(j8)
JTextField jt8=new JTextField(5)
jt8.setEditable(false)
c.add(jt8)
JButton jb1=new JButton("计算")
c.add(jb1)
jt1.addFocusListener(new FocusAdapter()
{
@Override
public void focusGained(FocusEvent e)
{
if (jt1.getText().equals("格式为:0000-00-00")) {
jt1.setText("")
}
}
@Override
public void focusLost(FocusEvent e)
{
if (jt1.getText().equals("")) {
jt1.setText("格式为:0000-00-00")
}
}
})
jt2.addFocusListener(new FocusAdapter()
{
@Override
public void focusGained(FocusEvent e)
{
if (jt2.getText().equals("格式为:0000-00-00")) {
jt2.setText("")
}
}
@Override
public void focusLost(FocusEvent e)
{
if (jt2.getText().equals("")) {
jt2.setText("格式为:0000-00-00")
}
}
})
jb1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Date d1=Date.valueOf(jt1.getText())//开始日期
Date d2=Date.valueOf(jt2.getText())//结束日期
Calendar c1=Calendar.getInstance()
c1.setTime(d1)
Calendar c2=Calendar.getInstance()
c2.setTime(d2)
int day1=c1.get(Calendar.DAY_OF_YEAR)
int day2=c2.get(Calendar.DAY_OF_YEAR)
int days=day2-day1
double money1=Double.valueOf(jt3.getText())//月租金
double money2=Double.valueOf(jt4.getText())//业务费
double money3=Double.valueOf(jt5.getText())//其他费用
int man=Integer.valueOf(jt6.getText())//人数
double money4=days/30*money1+money2+money3
double money5=0.0
if (man!=0) {
money5=money4/man
}
else {
money5=money4
}
jt7.setText(String.valueOf(money4))
jt8.setText(String.valueOf(money5))
}
})
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
setBounds(400,400,500,300)
setVisible(true)
setTitle("租金计算器")
}
public static void main(String[] args) {
ZuJin zj=new ZuJin()
}
}
丑是丑了点 用还是可以用的。
车辆出租管理系统 一、项目功能:设计程序,可以管理各种出租汽车并计算其租金。说明:程序主要管理货车类Truck 、客车类 Bus、小车类Car三中车辆 二、UML图:main( )TestCar三、源码:abstract class Vehicle{ protected String number//车牌号 protected String type//车类型 protected double value//购车价格 protected double rentPrice//租车单价 protected double rentKilometers//租车里程数 protected double rent//租金 public Vehicle(String number,String type,double value,double rentPrice)//设置车牌号、类型、价格、租车单价 { this.number=number this.type=type this.value=value this.rentPrice=rentPrice } public void setRentKilometers(double rentKilometers)//设置租车里程数{ this.rentKilometers=rentKilometers} public double getRentKilometers()//返回租车里程数{return rentKilometers} public abstract void calcuRent()//计算租金 public double getRent()//返回租金{return rent} public void printBasicInfo()//返回车的基本信息{ System.out.println("车牌:"+number+"\t车类型:"+type+"\t车价:"+value+"万元"+"\t租车单价:"+rentPrice)} public void printOtherInfo()//返回租车的信息{ System.out.print("租车里程数:"+rentKilometers) System.out.print("\t租车单价:"+rentPrice) System.out.println("\t租金:"+rent) System.out.println() } }/*****************************************************************************/class Truck extends Vehicle{ private double tonnage//货车的吨位数 public Truck(String number,String type,double value,double rentPrice,double tonnage) { super(number,type,value,rentPrice)//调用父类的构造器方法 this.tonnage=tonnage//对自己的成员变量进行初始化 } public double getTonnage() { return tonnage } public void calcuRent()//计算租金 { if(tonnage<10) rent=rentPrice*rentKilometerselse rent=rentPrice*rentKilometers*1.5 } public void printOtherInfo()//返回租车的信息{ System.out.print("货车租吨位:"+tonnage) System.out.print("\t租车单价:"+rentPrice) System.out.println("\t租金:"+rent) System.out.println() }}/*****************************************************************************/class Bus extends Vehicle{ int seats//客车坐位数int rentHours//租车小时 public Bus(String number,String type,double value,double rentPrice,int seats) { super(number,type,value,rentPrice)//调用父类的构造器方法 this.seats=seats } public void setRentHours(int rentHours) { this.rentHours=rentHours } public int getRentHours() { return rentHours } public int getSeats() { return seats } public void calcuRent()/*覆盖父类的计算租金的方法,出租单价为每天出租价格*/ { rentPrice=rentPrice*rentHours } public void printOtherInfo()//返回租车的信息{ System.out.print("客车租车时间:"+rentHours) System.out.print("\t租车单价:"+rentPrice) System.out.println("\t租金:"+rent) System.out.println() }}/*****************************************************************************/class Car extends Vehicle{ private int rentDayspublic Car(String number,String type,double value,double rentPrice) { super(number,type,value,rentPrice)//调用父类的构造器方法 } public void setRentDays(int rentDays) { this.rentDays=rentDays } public int getRentDays() { return rentDays }public void calcuRent()/*覆盖父类的计算租金的方法,出租单价为每天出租价格*/ { rentPrice=rentPrice* rentDays }public void printOtherInfo()//返回租车的信息{ System.out.print("小车租车天数:"+rentDays) System.out.print("\t租车单价:"+rentPrice) System.out.println("\t租金:"+rent) System.out.println() }} /*****************************************************************************/ public class TestCar{ public static void main(String args[]) { Truck truck1=new Truck("粤B 30234","小车",16,200,15.0) Bus bus1=new Bus("粤B 30234","小车",16,200,50) Car car1=new Car("粤B 30234","小车",16,200) truck1.printBasicInfo() bus1.printBasicInfo() car1.printBasicInfo() }}四、运行结果
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)