Results 1 to 7 of 7
Thread: Need help with blueJ
- 11-25-2010, 08:48 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
Need help with blueJ
I'm an undergrad and have been using blueJ for a couple months but im stuck on my assignment.
Here are the questions.
1.1 declare two private fields to represent the elements of time : hour and minute.
1.2 write a constructor which has no parameters and initialises the time to midnight (0hr 0 min ).
1.3 write a private mutator setHour which sets the value of the hour field from a suitable parameter. If the value of the parameter is within an appropriate range (between 0 - 23), the mutator should set the value of the hour field to the parameter value. If it is outside the appropriate range, the mutator sets the field value to 0.
1.4 write a private method setMinute whose behaviour is similar to setHour but which uses the
range appropriate for minutes (between 0 - 59).
Here is the code
Java Code:/** * Handles time in the format hour:minute. * If an attempt is made to set hour or minute outside appropriate range of 0 - 59, * component is set to 0 * * * @version 9/11/07 */ public class Time { // Write your code here /** Returns the time elapsed in minutes between the object and the time given in the parameter * @param that is represents the time used for comparison * @return gives the minutes elasped between the two times */ public int getElapsedTime(Time that) { int thisTime = this.getTotalMinutes(); int thatTime = that.getTotalMinutes(); if (thisTime > thatTime) { return thisTime - thatTime; } return thatTime - thisTime; } // Task 6.1 /* Returns a time as a total number of minutes e.g. 3.40 is returned as 240 */ private int getTotalMinutes() { return 0; // you must amend this code task 6.1 of Cwk 3 } }
-
Hello, and welcome to the forum.
So in essence what you've done is to give us your entire assignment without asking a question and without showing any evidence of effort on your part, and I'm afraid that in this situation there's not much that we can do for you other than to direct you to a tutorial or two.
I suggest that you post your best solution that you've created so far, and ask as specific questions as possible, and we'll be much better able to help. If you really have no idea how to begin here, then please have a look here: Starting Writing a Program. It's a well-written article that can help.
Much luck
- 11-26-2010, 04:59 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Just posting the assignment not encourage members to helping out. So be specific, are you stuck on anything? Let us know it with what you've tried, doesn't matter right or wrong.
- 11-29-2010, 02:03 PM #4
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
ok then, no worries ive already answered the questions that ive posted up. But im a little stuck on one of the questions.
1.7 Write an accessor getAsString which returns a String representation of the time using two digits each for hour and minute separated by a colon (: ) e.g. 14:35, 07:34, 02:03 and 00:00 for midnight.
(Hint: look at Date class). If you can't get the formatting to work, just return the two numbers separated by a ":"
here is the code i wrote for it, I thought it was right but its still doesnt compile.
Java Code:public String getAsString () { return as2Digits(hour) + ":" + as2Digits(minute); }
-
Can you show your "as2Digits(...) method and the actual error message?
- 12-01-2010, 07:08 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
I've sorted my old problem but I got a new one. I get the error saying "illegal start of expression". And the part where it doesnt compile is "private void setHour(int minute)" I don't understand why I get this error as they are bothe identical.
Java Code:/**1.3 write a private mutator setHour which sets the value of the hour field from a suitable parameter. * If the value of the parameter is within an appropriate range (between 0 - 23), the mutator should set the value of the hour field to the parameter value. * If it is outside the appropriate range, the mutator sets the field value to 0. */ private void setHour(int hour) { if ((replacementValue >= 0) & (replacementValue < 23)) { hour = replacementValue; } else{ hour=0; } /** 1.4 write a private method setMinute whose behaviour is similar to setHour but which uses the range appropriate for minutes (between 0 - 59). */ private void setMinute(int minute) { if ((replacementValue >= 0) & (replacementValue < 23)) { minute = replacementValue; } else{ minute=0; }
- 12-06-2010, 04:59 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You've syntax error in the following code segment.
missing the closing bracket of else block.Java Code:else{ hour=0;
Similar Threads
-
ArrayLists for BlueJ
By heyit'skaye in forum New To JavaReplies: 1Last Post: 09-01-2010, 04:15 AM -
Need Help in BlueJ... Cannot figure this out.
By ERICAMAUVE4 in forum New To JavaReplies: 2Last Post: 09-25-2009, 12:34 AM -
BlueJ help
By Cid17 in forum New To JavaReplies: 2Last Post: 06-29-2009, 07:38 PM -
help using BlueJ
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:07 AM -
BlueJ 2.2.0
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-07-2007, 02:28 PM


LinkBack URL
About LinkBacks

Bookmarks