Commit bf76b9d3 authored by andyguest's avatar andyguest

Initial commit

parents
File added
public class Date {
public int day;
public int month;
public int year;
}
1. Run this code to ensure it does what you expect
2. Change `day` from **public** to **private**
Does the code still run? Why not?
3. Create a new method `setDay(int day)`. This method should check to ensure 0 < day < 32
Modify `main()` to use this method rather than setting day directly. Does this fix the code?
4. Create a new method `getDay()` that returns the value of day. Update main to use `getDay()` in the
output line.
\ No newline at end of file
File added
class Main {
public static void main ( String [] args ){
Date d = new Date ();
d.day = 42;
System.out.println("The day is " + d.day);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment