This is Karthika - you Java Lecturer for this Semester.
Here is a sketch of the homework problem I gave you today. From now on I will make sure the "psuedocode" or the algorithm flow of any program I give you as Homework is discussed here in the forums! If you try to work them out by understanding whats discussed here I am sure you wont complain of the questions given during Java Exams,
Problem : " Write a Java source code for instantiating objects of type SimpleDate. Instantiate 4 date objects and store - days, months and years for all 4 objects using get and set methods"
Steps or Algorithm
1. Declare public Class Simpledate
2. Declare Variables to store month, year and day - that are owned by objects of type Simpledate to store the values accordingly.
3. Define Functions that appear in the class - void main, int getmonth(), void setmonth(int month), int getday(),void setday(int day), int getyear() and void setyear(int yr).
public class Simpledate
//variables to store dates for objects of type Simpledate
public int day;
public int month;
public int year;
public int getmonth()
// should return month (of type int) stored here
public void setmonth(int month)
//object's month variable = month variable given as input
//do the same to set year and date
public static void main(String args)
// main method
Simpledate newyearday = new Simpledate(); // e.g. of declaring/instantiating an object of type Simpledate
newyearday.setmonth(01); // this is an e.g. of setting the month of new year celebration.
// In the Same way try for 4 types of Simpledate objects.
int firstmonth=newyearday.getmonth(); // This is how you access newyearday month and store it in another variable and later print it out!
// try to set the days, months and years through set function, access it through get function as another step and print it.
//END OF MAIN FUNCTION
//END OF SimpleDate Class
/*************end of program***********/
// 1. "method" or "function" will be alternatively addressed for a java method();
// 2. Usually its practise to write the main method first when you start coding but here I have typed it in the end
// so that you understand the flow of the algorithm. This is not a source code but I strongly encourage you write
// a source code yourself fully and practise!
// good luck!