JAVA编程 检测超速和超载程序 用户登陆

来源:百度知道 编辑:UC知道 时间:2024/06/02 23:08:29
实验一 检测超速和超载程序

要求: 新建两个类,Car和TestCar,并且他们都属于work1包
 Car类需要定义三个变量,number,speed, Capacity,并分别赋值。Car需要定义主函数,在主函数内调用TestCar类中的test方法。
 TestCar类需要定义test方法,该方法主要完成判断:①车上乘客是否超过10人。②行驶速度是否超过70。对于不同的情况给予不同的警告或表扬,并显示车牌号。

实验二 用户登陆

 要求:
 使用JFrame制作
 按下登陆按钮后弹出消息框,分别显示如下消息:
 用户名和密码都对的时候显示登陆成功
 用户名错时显示“登陆失败,用户名错误”
 密码错误的时候显示“登陆失败,密码错误”
 两者均错的时候显示“登陆失败,用户名密码错误“
 按下登陆按钮后将文本框中的字符清空
textField.setText("");
 密码输入框要求使用回显字符
 判断字符串是否相等:
textField.getText().equals("123")

急用,谢谢关注并给与解答!!!

我来试试第一个:

Car.java

class Car
{
public String car_Number;//车辆号码
public int car_Speed;//车辆速度
public int car_Capacity;//车辆容量(应该是当前载人数)
Car()
{}
Car(String num,int sp,int cap)
{
this.car_Number = num;
this.car_Speed = sp;
this.car_Capacity = cap;
}
public static void main(String [] arg)
{
Car mycar = new Car("川C94518",71,12);
CarTest mytest = new CarTest();
mytest.Test(mycar);
}
}

CarTest.java

public class CarTest
{
int flag =0;

public void Test(Car car)
{
System.out.println("车辆号码:"+car.car_Number);
System.out.println("--------------------");
if(car.car_Capacity>10)
{
System.out.println("超载:"+car.car_Capacity+"人");
flag +=1;
}
if(car.car_Speed>70)
{
System.out.println(&quo