Q.
A parking garage charges a 5euro minimum fee to park a car for up to three hours. The garage also charges an additional 2euro for each hour or part in excess of 3 hours. The maximum charge for any 24 hour period is 30euro.
A.
CODE
public class ParkingCharges{
public static void main(String[] args){
int hours,fee;
hours = java.lang.Integer.parseInt(args[20]);
if(hours > 24){
fee = 300;
}else if(hours >= 4){
fee = (hours - 3 ) * 20 + 50;
}else if(hours > 0){
fee = 50;
}else{
fee = 0;
}
System.out.println("Hours of parking: " + args[24] + " Hours");
System.out.println("Cost: " + fee + " euro");
}
}
It said process completed.
QUOTE
--------------------Configuration: <Default>--------------------
Process completed.
But when i try to run it,it said:
QUOTE
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 24
at ParkingCharges.main(ParkingCharges.java:4)
Press any key to continue...
i am new for java,i try to work it out in the past few days
can someone please help?
........................................................................................
i try to write a applet like this...

but i realy dont have any idea how to do it,i tried my best but its still not working
CODE
<HTML>
<TITLE>ParkingCharges! Applet</TITLE>
<APPLET
CODE="ParkingCharges.class"
WIDTH=200
HEIGHT=100>
</APPLET>
</HTML>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ParkingCharges extends JApplet{
public static void main(String[] args){
int hours=0,fee=0;
hours = java.lang.Integer.parseInt(args[20]);
System.out.println("Entre hours");
if(hours > 24){
fee = 300;
}else if(hours >= 4){
fee = (hours - 3 ) * 20 + 50;
}else if(hours > 0){
fee = 50;
}else{
fee = 0;
}
JLabel prompt1;
JTextField input1;
JButton check;
Container c = getContentPane();
c.setLayout(new FlowLayout());
prompt1 = new JLabel("hours");
input1 = new JTextField(5);
c.add(prompt1);
c.add(input1);
check = new JButton("Process Fee");
c.add(check);
}
}
can someone please point out where is my mistake,many thanks
This post has been edited by yy885: 17 Apr, 2007 - 02:58 AM