Parking lot charges

Source: Internet
Author: User

Within three hours: 3

More than per hour: 0.5

Maximum: 10

 

Mport java. AWT. container;
Import java. AWT. flowlayout;
Import java. AWT. event. actionevent;
Import java. AWT. event. actionlistener;

Import javax. Swing. japplet;
Import javax. Swing. jbutton;
Import javax. Swing. jlabel;
Import javax. Swing. jtextfield;

Public class charges extends japplet implements actionlistener {
Int hour;
Float charges, sum = 0;
 
Jlabel inlabel;
Jlabel resultlabel;
Jtextfield intextfield;
Jtextfield resultfield;
Jbutton rollbutton;
 
Public void Init ()
{
Container = getcontentpane ();
Container. setlayout (New flowlayout ());

Inlabel = new jlabel ("input the hour of (-1 = end ):");
Container. Add (inlabel );

Intextfield = new jtextfield (10 );
Container. Add (intextfield );

Resultlabel = new jlabel ("the total cost is :");
Container. Add (resultlabel );

Resultfield = new jtextfield (10 );
Resultfield. seteditable (false );
Container. Add (resultfield );

Rollbutton = new jbutton ("calculater ");
Rollbutton. addactionlistener (this );
Container. Add (rollbutton );
}
 
Public void actionreceivmed (actionevent event)
{
Calculater ();
Resultfield. settext (float. tostring (SUM ));
}
 
Public void calculater ()
{
Hour = integer. parseint (intextfield. gettext ());
If (hour =-1)
Showstatus ("the last data! ");
Else {
If (hour <= 3)
Charges = 2;
Else
Charges = 2 + (hour-3) * (float) 0.5;
If (Charges> 10)
Charges = 10;

Showstatus ("current costs is:" + charges );

Sum + = charges;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.