HJælp til indledende programmerings opgave i eclipse
Hej,
Jeg skal have løst nedenstående opgave i programmet eclipse. Jeg har ingen anelser om hvordan koden skal se ud og hvordan den skal løses.
Håber der er er nogen der kan hjælpe.
Write a program ParkAutomat which controls a park automat. Parking cost 20 dkk. per hour. The maximum parking time 2 hours. The customer arrives at a full hour or half hour ( XX:00 or XX:30). The arrival time is selected at random. The customer buys time by inserting coins (with values 20, 10, 5, 2, 1). The machine shows end time for the parking. The user can select "Buy" or "Cancel" with the obvious reactions. If more money is inserted than the maximum parking time allows, the rest is returned. Times are shown in the format HH:MM. A snippet of a dialog could look like this: **************************** The time is 23:00 Parking time until 23:00 Please insert Coins C - Cancel B - Buy **************************** 20 **************************** The time is 23:00 Parking time until 00:00 Please insert Coins C - Cancel B - Buy **************************** 5 **************************** The time is 23:00 Parking time until 00:15 Please insert Coins C - Cancel B - Buy **************************** 2 B Your ticket is printed . Thank you ========== Customer handled ============ **************************** The time is 08:00 Parking time until 08:00 Please insert Coins C - Cancel B - Buy **************************** 2 **************************** The time is 08:00 Parking time until 08:06 Please insert Coins C - Cancel B - Buy **************************** C Operation cancelled . Money returned 2 dkk. ========== Customer handled ============ **************************** The time is 21:30 Parking time until 21:30 Please insert Coins C - Cancel B - Buy **************************** 20 **************************** The time is 21:30 Parking time until 22:30 Please insert Coins C - Cancel B - Buy **************************** 10 **************************** The time is 21:30 Parking time until 23:00 Please insert Coins C - Cancel B - Buy **************************** 20 Max parking time reached . 10 ddk returned . **************************** The time is 21:30 Parking time until 23:30 C - Cancel 3 B - Buy **************************** B Your ticket is printed . Thank you ========== Customer handled ============
public class ParkAutomat { public static void main (String [] args){ Scanner console = new Scanner (System.in);
System.out.println ("This program computes per hour" + "Parking payments."); System.out.print("Arrival time :"); double Arrivaltime = console.nextDouble ();
Random r= new Random (); System.out.println ("This program computes per hour" + "Parking payments."); System.out.print("Parking time until : "); int result; while (result !=number){ result=r.nextInt(2)+0; System.out.println("next number = " + result);
Random r= new Random (); System.out.println ("This program computes per hour" + "Parking payments."); System.out.print("Parking time until : "); int result; while (result !=number){ result=r.next(24) + ":" + r.next(2)*30; System.out.println("next number = " + result);
Angående den kode du lige skrev, bliver den ved med at sige at der er noget galt ned next. Jeg kan ikke rigtig se hvad fejlen er. Random r= new Random (); int h = r.next(24); int m = r.next(2) * 30; String timstr = h + ":" + m;
Lige nu ser koden således ud og kan ikke komme videre: import java.util.Random; import java.util.Scanner;
public class ParkAutomat { public static void main (String [] args){ Scanner console = new Scanner (System.in); System.out.println ("This program computes parking hours" + "Parking payments."); System.out.print("Arrival time :"); double Arrivaltime = console.nextDouble (); Random r= new Random (); int h = r.nextInt(24); int m = r.nextInt(2) * 30; String timstr = h + ":" + m;
public class ScanDemo { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int sum = 0; boolean done = false; while(!done) { System.out.print("Enter number or S: "); String line = scn.nextLine(); if(line.equals("S")) { done = true; } else if(line.matches("^\\d+$")) { sum += Integer.parseInt(line); } else { System.out.println("Invalid input"); } } System.out.println("The sum is: " + sum); }
det og saa hvordan du laeser noget og tester for hvad det er
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.