# Some input on a homework

• 05-18-2008, 12:54 PM
alcohole4life
Some input on a homework
Hi,guys I am a studying Computrer Science and Math in university, so I got a class this semester "Introduction to programming" in which we use Java. I have been doing below average having 65 points out of 100 on the first test and now I have to do three homeworks in the next three weeks and they will make up for 30% of the final grade. So here is my task for this week which is taken from a book of delitel "Java how to program 6th edition", so if anyone can give me any ideas where I can find solutions for it or sth. let me know.

1. Write the following classes following encapsulation and information hiding
conceptions:
-write class Point. its objects must have an array containing two integers, giving the cordinates of this point
-write three constructors for this class (for copying, main purpose and default), write set and get methods for the global variables and toString method
-write class Rectangle , which objects have an array with two Points and those 2 points give the up left corner and the down
-write three constructors for this class (for copying, main purpose and default), write set and get methods for the global variables and toString method(use the toString method from Point)
- write draw (Graphics g) method in class Rectangle that will let you draw the current "this object" by using the given as an argument object of class g
- write class Line , which objects have an array with two Points and they give the first and the last point of a line
- write three constructors for this class (for copying, main purpose and default), write set and get methods for the global variables and toString method(use the toString method from Point)
- write draw (Graphics g) method in class Line that will let you draw the current "this object" by using the given as an argument object of class g

2. Write enum Weekdays and its constants (NON,TUE, WED....) take 3 parameters the full name of the day, abbreviation of the full name and yhe positon of the day in the week. For example "Monday","Mon",1
Write a test class for this enum, which will randomly select a number from 1 to seven and it will output the following for this day:
a) The full names of the days of the week starting with the day which position was selected. For example with two we will have :Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, Monday
b) the abbreviations of the days of the week in reverse order beginning with the picked number. For example for two we will have:
Tue , Mon , Sun , Sat , Fri , Thu , Wed

Ok. here is what I can do about it.
1.
- public class Point{private int[] cord= {1,2}
- public void setCord(int[] newCord)
{
Cord = new int[newCord.length][];

for (int i = 0; i < Cord.length; i++) {
Cord[i] = newCord[i];

}
} else {
Cord = new int[][]{{0}, {0}}; // by default

}}

int[]temp = new int[Cord.length];

for (int j = 0; j < Cord[i].length; j++) {
temp[j] = Cord[i];
}
return temp;}
And gotta go now to eat but will write the rest of what I can do later today....
• 05-23-2008, 05:18 PM
int day = (int)(Math.random() * 7) + 1; //random# from 1 to 7
//go backwards
for (int i=day; i>=1; i--){
System.out.println(fullNameofDay(i));
}
for (int i=7; i>=day+1; i--){
System.out.println(fullNameofDay(i));
}
//go forwards
for (int i=day; i<=7; i++){
System.out.println(abbrDay(i));
}
for (int i=1; i<day; i++){
System.out.println(abbrDay(i));
}

Hopefully that should point you in the right direction