Uni Programing Help

sam83uk said:
write a func to null out the 30th date in the feb array if the year is divisible by 4

Not every leap year is divisible by four, though. I believe the general algorithm is:

Code:
if year mod 400 eq 0 // leap year
else if year mod 100 eq 0 // no leap year
else if year mod 4 eq 0 // leap year
else // no leap year

Edit: Yep:

The Gregorian calendar, the current standard calendar in most of the world, adds a 29th day to February in all years evenly divisible by 4, except for centennial years (those ending in -00), which receive the extra day only if they are evenly divisible by 400. Thus 1600, 2000 and 2400 are leap years but 1700, 1800, 1900 and 2100 are not.
 
Last edited:
robmiller said:
I meant that not every year divisible by four is a leap year.
Put it this way, I'll give you a magic cookie if you can find me a year that divides exactly by 4 and isn't a leap year. (century's excluded :p).
 
Last edited:
Phnom_Penh said:
I was bored :p.
Code:
if(((year % 4 == 0)&(year % 100 != 0))|(year % 400 == 0))
{
days = days + 1;
}

<pedant>If your meaning to do it in java you want logical AND/OR not bitwise.</pedant>
 
Una said:
<pedant>If your meaning to do it in java you want logical AND/OR not bitwise.</pedant>
That is java, and it compiles in Eclipse. :\ I never have got AND/OR working...


Edit.. I get you, like && / || etc.
 
Last edited:
Phnom_Penh said:
Never got taught that... well at least I learnt something :p.

What, you mean I can use it for Prolog and C++ too? ;).

Yeah you can use eclipse for C++ with CDT plugin.

http://www.eclipse.org/cdt/

Not sure about prolog never used it.

I used to use it for Java/C++/Ruby till I found IntelliJ idea.
 
Last edited:
Had to do something similar for my assessment, but we were using scheme and I don't know java. Also be glad that you don't have to create appointments for date and check for clashes.
 
Currently trying to get the .output and .set bits working got

Code:
    public void set(){
        int m, d, y = TextIO.getInt();
    }
    public void output(){
       
        System.out.print(dates);
        System.out.print("/");

I cant get set to work, as it tells me that it does not understand m, etc when i type:
Code:
Test.set(m);

I also cannot get output to output the date of month, day and year at the same time rather than going:

Code:
Test.output();
Test1.output();
Test2.output();

Each time, it would be better to just get the output in one line of code
 
jcb33 said:
Currently trying to get the .output and .set bits working got

Code:
    public void set(){
        int m, d, y = TextIO.getInt();
    }
Test.set(m);

Wtf, of course you can't call set(m) because for a start m is out of scope and your function does not take any parameters.

I think you need to read a java tutorial.
 
Phnom_Penh said:
Erm use a scanner for input.
As for output, System.out.println(day + "/" + month + "/" + year); tbh.
thanks, just found this in some of our lecture notes, think it be worth me revising them some more before I sit scratching my head for a few hours!

Having said that, it still does not like it, as I do not define day, month, and year in Date, but in the sub classes of Day, Month and Year
 
Last edited:
The way I read your spec is like this - obviously you need to provide all the correct validation of input and stuffs.

Code:
public class Date
{
    private int year;
    private int month;
    private int day;

    public void set(int year,int month,int day)
    {
        this.year = year;
        this.month = month;
        this.day = day;
    }
}
 
Back
Top Bottom