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;
}
}
}