944,084 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2327
  • Java RSS
Oct 7th, 2006
0

Program help

Expand Post »
Here is my program with Pseudo code which is yukville, :lol:
but not sure i'm on the right track or have straid, any help would be appreiciated.



Exhibit A-1: UML Class Diagram of Class Garage
Garage

+openForBusiness()
-calculateCharges(hoursParked : double): double


Exhibit A-2: Pseudo code for openForBusiness Method of Class Garage
A-2-01) INSTANTIATE a local variable named input of the Scanner class
A-2-02) Define a local int variable named customerNumber and initialize it to 1
A-2-03) Define a local double variable named totalParkingReceipts and initialize it to 0.0
A-2-04) Define a local double variable named parkingCharges
A-2-05) Define a local double variable named hoursParked
A-2-06) Define a local String variable named hoursParkedPrompt and initialize it to
“Enter number of hours parked for customer %2d, or <ctrl>z to stop:Δ[1]
A-2-07) Define a local String variable named programOutput and initialize it to “\nSummary of Today’s Receipts:\n”
A-2-08) CONCATENATE line one of output column headings onto programOutput using method format[2] of the String class:
programOutput += String.format(“\n\t%8sΔΔΔ%6s ΔΔΔ%7s”,”Customer”,”HoursΔ”,”Parking”);
A-2-09) CONCATENATE line two of output column headings onto programOutput using method format of the String class:
programOutput += String.format(“\n\t%8sΔΔΔ%6s ΔΔΔ%7s”,”ΔNumberΔ”,”Parked”,”ΔΔFeeΔΔ”);
A-2-10) DISPLAY the task / programmer identification line followed by a blank line
A-2-11) DISPLAY the “Parking Attendant Activity” heading followed by a blank line
A-2-12) Using method printf, DISPLAY the following prompt
(“\tΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔ” + hoursParkedPrompt, customerNumber)
A-2-13) WHILE (input.hasNext())
A-2-13-1) ASSIGN input.nextDouble() TO hoursParked
A-2-13-2) ASSIGN calculateCharges (hoursParked)[3] TO parkingCharge
A-2-13-3) ADD parkingCharge TO totalParkingReceipts
A-2-13-4) CONCATENATE the following formatted string onto programOutput:
(“\n\t%8dΔΔΔ%6.1fΔΔΔ$%6.2f”, customerNumber, hoursParked, parkingCharge)
A-2-13-5) Using method printf, DISPLAY the following prompt:
(“\tCharge for customer %2d is $%6.2f;Δ” + hoursParkedPrompt,
customerNumber, parkingCharge, ++customerNumber)
A-2-14) END WHILE
A-2-15) CONCATENATE the following formatted string onto programOutput:
(\n\t%-17sΔΔΔ$%6.2f”, “ΔΔΔTotal Receipts”, totalParkingReceipts)
A-2-16) Using method println, DISPLAY programOutput
A-2-17) Using method println, DISPLAY a blank line followed by the “End of program” line


Exhibit A-3: Pseudo code for calculateCharge Method of Class Garage
A-3-01) Define a named constant[4] for minimumParkingCharge with a value of 2.0;
A-3-02) Define a named constant for maximumParkingCharge with a value of 10.0;
A-3-03) Define a named constant for maximumParkingHoursForMinimumParkingCharge with a value of 3.0;
A-3-04) Define a named constant for chargePerHourAfterMinumum with a value of 0.5.
A-3-05) ASSIGN minimumParkingCharge TO parkingCharge
A-3-06) IF hoursParked > maximumParkingHoursForMinimumParkingCharge THEN
ASSIGN minimumParkingCharge plus product of chargePerHourAfterMinumum and
Math.ceil(hoursParked minus maximumParkingHoursForMinimumParkingCharge)
TO parkingCharge
END-IF
A-3-07) IF parkingCharge IS GREATHER THAN maximumParkingCharge THEN
ASSIGN maximumParkingCharge TO parkingCharge
END IF
A-3-06) RETURN parkingCharge



Exhibit B-1: UML Class Diagram of Class GarageTest
GarageTest

+main(args[ ] : String)


Exhibit B-2: Pseudo code for main Method of Class GarageTest
This method has no return value and has one parameter: arg[ ] as type String.
B-2-01) INSTANTIATE object application of class Garage
B-2-02) CALL application’s openForBusiness method


[1] The Greek letter delta Δ in a string is used represent a single space in the string. As a result, replace all Δ characters shown in a string with a single space character.

[2] Use the format method of the String class to format this string. This is similar to using the printf method with format specifiers to format output. The syntax is: String.format(“My %s has %d numbers: %d, %.2f, %d”, “string”, 3, 1, 2.0, 3);

[3] This is a method call.

[4] Named constants are defined as variables with the “final” keyword as a prefix. The value associated with a named constant cannot be changed at run time. In other words, a named constant cannot appear on the left-hand side of the assignment operator in an assignment statement. An example of a named constant is: final double pi = 3.14;


Java Syntax (Toggle Plain Text)
  1. import java.util.Scanner; // program uses class Scanner
  2. public class Garage
  3. {
  4. private static String hoursParkedPrompt;
  5. private static Object programOutput;
  6. // application starting point
  7. public static void main( String args[] )
  8. {
  9. // Instantiate a loacl variable named input of Scanner class
  10. Scanner input = new Scanner( System.in );
  11. int customerNumber = 1;
  12. double totalParkingReceipts = 0.0;
  13. double ParkingCharges;
  14. double hoursParked;
  15. hoursParkedPrompt = "Enter number of hours parked for customer %2d, or <ctrl>z to stop: ";
  16. String programOutput = "\nSummary of Today's Receipts:\n";
  17. String line1 = programOutput += String.format ("\n\t%8s %6s %7s","Customer","Hours ","Parking");
  18. String line2 = programOutput += String.format ("\n\t%8s %6s %7s"," Numbers ","Parked"," Fee ");
  19. System.out.println("\nTask 09-02, Ch06, Programmed by Michael Statham\n");
  20. System.out.println("\nParking Attendant Activity:\n");
  21. System.out.printf("\t "+hoursParkedPrompt, customerNumber);
  22.  
  23. while (input.hasNext());
  24. hoursParked = input.nextDouble();
  25. Object parkingCharge = calculateCharges(hoursParked);
  26.  
  27.  
  28. String.format = programOutput:("\n\t%8d %6.1f $%6.2f",customerNumber,hoursParked,parkingCharge);
  29. System.out.printf("\tCharge for customer %2d is $%6.2f; " + hoursParkedPrompt,
  30. customerNumber, parkingCharge, ++customerNumber);
  31. }// end while
  32. String.format = programOutput:("\n\t%-17s $%6.2f"," Total Receipts", totalParkingReceipts);
  33. System.out.println("programOutput");
  34. System.out.println("\nEnd of program");
  35. private static Object calculateCharges(double hoursParked) {
  36. // TODO Auto-generated method stub
  37. return null;
  38. final double minimumParkingCharge = 2.0;
  39. final double maximumParkingCharge = 10.0;
  40. final double maximumParkingHoursForMinimumParkingCharge = 3.0;
  41. final double chargePerHourAfterMinimum = 0.5;
  42.  
  43. double parkingCharge = minimumParkingCharge;
  44.  
  45. if (hoursParked > maximumParkingHoursForMinimumParkingCharge);
  46. parkingCharge = minimumParkingCharge + chargePerHourAfterMinimum +
  47. Math.ceil(hoursParked - maximumParkingHoursForMinimumParkingCharge);
  48.  
  49. // end if
  50. if (parkingCharge > maximumParkingCharge);
  51. parkingCharge = maximumParkingCharge;
  52.  
  53. //end if
  54. return parkingCharge;
  55.  
  56. }
  57. }


Last edited by iwlu; Oct 7th, 2006 at 5:56 pm.
Similar Threads
Reputation Points: 12
Solved Threads: 0
Newbie Poster
iwlu is offline Offline
11 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: algorithm problem with recursion
Next Thread in Java Forum Timeline: java constructor..!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC