Results 1 to 2 of 2
  1. #1
    alcohole4life is offline Member
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Default 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)
    {
    if (NewGrade != null) {// set a copy of newGrade
    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

    }}

    public int getGrades(){
    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....

  2. #2
    radtad82 is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default

    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

Similar Threads

  1. Removal of Homework Requests
    By CaptainMorgan in forum Suggestions & Feedback
    Replies: 14
    Last Post: 08-03-2008, 09:21 PM
  2. Tough Homework Questions, PLEASE HELP!
    By passage in forum New To Java
    Replies: 21
    Last Post: 01-16-2008, 11:04 PM
  3. Help with my java servlet homework
    By jellyfish888 in forum Java Servlet
    Replies: 2
    Last Post: 12-21-2007, 05:41 PM
  4. Homework PREREQUISITE Problem
    By ChrisC in forum New To Java
    Replies: 7
    Last Post: 11-27-2007, 05:36 AM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 08:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •