|
Levels-4-You : Lounge : Any one good at Java? |
[Forum Rules] |
skvlad01 |
Posted 28th Sep 2008 7:48am |
L4Y Member Post 487 / 614
 |
I have to do this assignment for school. I have to write a small java code.
I really suk at java and have no idea how to write up a code for this
Any one that would be able to help me would be greatly appreciated
the assignment question goes like this .
Design and implement the class Day that implements the day of the week
in a program. The class Day should store the day, such as Sun for
Sunday. The program should be able to perform the following operations
on an object of the type Day:
a) Set the day
b) Print the day
c) Return the day
d) Return the next day
e) Return the previous day
f) Calculate and return a day by adding # of days to current day.
(ie. if current day is Monday and we add 3 days then new day
is Thursday)
g) Add the appropiate constructors // default & set constructors
h) Write the definitins of the methods to implement the
operations for the class Day as defined in a - g
i) Write a program to test various operations on the class Day |
|
D2k |
Posted 28th Sep 2008 9:30am |
L4Y Member Post 1772 / 1923
 |
You should have paid attention in class. |
|
skvlad01 |
Posted 28th Sep 2008 11:23am |
L4Y Member Post 489 / 614
 |
I did, but I dont understand it neither does any one else in my class. Thats why I have come here. |
|
D2k |
Posted 28th Sep 2008 1:23pm |
L4Y Member Post 1773 / 1923
 |
Hmm, either you have a CENSORED ty teacher, or your class is full of retards. 
Well, the first thing i would do is go straight to google and type in "java tutorial" in the search. volla, problem solved. |
|
Duke  |
Posted 29th Sep 2008 5:10am |
Post 1259 / 1353
 |
Use a circular array. Length of 7; [0] - "Sunday", [1] - "Monday" etc. Set an access variable for this array.
Circular arrays are set up in the same way as regular ones, except if the access variable goes beyond the array's limits, it wraps around to the other end, i.e. if it goes to -1, it gets 'reset' to 6, or if it gets to 7, it is automatically changed to 0.
An easy way to handle this is to use the modulus feature (X % Y), as this gives you the remainder when X is divided by Y.
Set the day: Determine what day you want to set it to, and change the access variable to match
Print the day: Print the string stored in the position the access variable is set to.
Return the day: Return the string stored in the position the access variable is set to.
Return the next day: Return the string stored in the position p + 1, where p is the access variable.
Return the previous day: Return the string stored in the position p - 1, where p is the access variable.
Calculate and return a day by adding of days to current day: Return the day at position (p + ) % 7, where p is the access variable.
The rest you can figure out for yourself. |
Those who follow the path of others lack the imagination or courage to create their own.
In my spare time I like to write game reviews for Game Revolution. |
|
|
skvlad01 |
Posted 29th Sep 2008 8:53am |
L4Y Member Post 490 / 614
 |
I understand how to do it logically but can't really put it in to code. Hmm this would be so much easier in PIC assembly language. |
|
Beatonator  |
Posted 6th Oct 2008 4:30pm |
Post 2803 / 3716
 |
Thats weird, my first lesson today was on Java. Im joining in Year 2 as I previously did an HND along with 2 friends, turns out the rest of the class already know Java and are continuing it from the first year. We got some catching up to do! |
Trying to find old players. Anyone about? Drop me a PM or reply to this thread:
>Link< (or head over to RFrun.net's comment section!) |
|
|
|
|