标题: debug, 求助 [打印本页] 作者: diving 时间: 2010-2-23 12:58 AM 标题: debug, 求助 问题如下:
Write a structured Java program program to calculate the parking fare for
customers who park their cars in a parking lot when the following information is
given:
a) A character showing the type of vehicle: C for car, B for bus, T for truck
b) An integer between 0 and 24 showing the hour the vehicle entered the lot
c) An integer between 0 and 60 showing the minute the vehicle entered the lot
d) An integer between 0 and 24 showing the hour the vehicle left the lot
e) An integer between 0 and 60 showing the minute the vehicle left the lot
Vehicle First Rate Second Rate
CAR RM 0.00/hour first 3 hour RM 1.50/hour after 3 hour
TRUCK RM 1.00/hour first 2 hour RM 2.30/hour after 2 hour
BUS RM 2.00/hour for first hour RM 3.70/hour after first hour
The input data consist of a character and a set of four integers representing the
type of vehicle and the entering and leaving hours and minutes. But these
pieces of data must be input into the computer in a user-friendly way. In other
words, the computer must prompt the user to enter each piece of data as show
below. (Note: Red colour indicates typical data)
Type of vehicle? C
Hour vehicle entered lot (0-24)? 14
Minute vehicle entered lot (0-60)? 23
Hour vehicle left lot (0-24)? 18
Minute vehicle left lot (0-60)? 8
The output format is shown below:
PARKING LOT CHARGE
Type of vehicle: Car or Bus or Truck
TIME-IN XX : XX
TIME-OUT XX : XX
-------
PARKING TIME XX : XX
ROUNDED TOTAL XX
-------
TOTAL CHARGE RM XX.XX
This program must first calculate the actual time spent in the parking lot for
each vehicle. You may use the following algorithm:
a) Compare the minute portion of the leaving and the entering time. If the first
one is smaller than the second,
- Add 60 to the minute portion of the leaving time
- Subtract 1 from the hour portion of the leaving time
b) Subtract the hour portions
c) Subtract the minute portions
d) Since there are no fractional hour charges, the program must also round the
parking time up to the next hour before calculating the charge. The program
should use switch statement to distinguish between the different types of
vehicles
Note: You CANNNOT use GUI/Applet and/or object-oriented approach in solving
this question.作者: diving 时间: 2010-2-23 01:01 AM
我的coding如下
import java.util.Scanner;
public class test
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int menu;
int hourin, minutin, hourout, minutout, timeh, timem, newhourout, newminutout, round;
double charges;
System.out.println("Type of Vehicle?");
menu = input.nextInt();
switch(menu) {
case 1:
System.out.println("Hour vehicle entered lot (0-23)? ");
hourin = input.nextInt();
System.out.println("Minute vehicle entered lot (0-59)?");
minutin = input.nextInt();
System.out.println("Hour vehicle left lot (0-23)? ");
hourout = input.nextInt();