Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: PLEASE HELP

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PLEASE HELP

    Design and implement a class called DayType that implements the day of the week in a program. The class DayType should store the day, such as Sun for Sunday, Mon for Monday and so on and so forth. The program should be able to perform the following operations on an object of type of
    DayType:
    Set the day
    Print the day
    Return the day
    Return the next day
    Return the previous day
    Calculate and return the day by adding and subtracting certain days to the current day (i.e if current day is Monday and we add 6 days, the day to be returned is Sunday. Similarly is we subtract 3 days, the day to be return is Friday)

    Instructions
    1. Define DayType class – appropriate methods and constructor
    2. Your program should get the input/output via the main method and pass appropriate arguments through the class methods.
    3. Your program should continuously running until it receives a special signal (character/number) in which the program will exit.
    4. Compile and run
    5. Write a short description on what you have done in your program

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: PLEASE HELP

    No one is going to do this for you. I suggest you site down, break the problems apart, and make an effort. If you have specific questions along the way post some code with specific questions about it.

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP

    Quote Originally Posted by copeg View Post
    No one is going to do this for you. I suggest you site down, break the problems apart, and make an effort. If you have specific questions along the way post some code with specific questions about it.
    plz check my coding...
    public class DayType{
            final static int SUN = 0;
            final static int MON = 1;
            final static int TUE = 2;
            final static int WED = 3;
            final static int THU = 4;
            final static int FRI= 5;
            final static int SAT = 6;
     
            private int day;
     
            public DayType(int day) {
                    this.day = day;
            }
     
            public void setDay(int day){
                    this.day = day;
            }
     
            public int getDay() {
                    return day;
            }
     
            public void print() {
                    System.out.println(this.toString());
            }
            public int nextDay(){
                    int next;
                    next = day + 1;
                    return next;
            }
            public int previousDay(){
                    int prevDay;
                    prevDay = day - 1;
                    return prevDay;
            }
            public int addDays(int days) {
                    return (day + days) % 7;
            }
                    public String toString() {
                    switch (this.day) {
                    case SUN:
                            return "Sunday";
                    case MON:
                            return "Monday";
                    case TUE:
                            return "Tuesday";
                    case WED:
                            return "Wednesday";
                    case THU:
                            return "Thursday";
                    case FRI:
                            return "Friday";
                    case SAT:
                            return "Saturday";
                    }
                    return "";
            }       
            public static void main(String[] args) {
                    System.out.println("******Test Day******");
                    System.out.println();
                    System.out.print("Set day: ");
                    DayType d = new DayType(SUNDAY);
                    d.print();
                    System.out.print("Next day: ");
                    d.setDay(d.nextDay());
                    d.print();
                    System.out.print("Previous day: ");
                    d.setDay(d.previousDay());
                    d.print();
                    System.out.print("After 5 days: ");
                    d.setDay(d.addDays(5));
                    d.print();
            }       
    }
    Last edited by helloworld922; February 5th, 2011 at 12:29 AM.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: PLEASE HELP

    What happens when you run the program?
    What inputs are you providing, and what outputs is it giving back to you?
    What outputs do you expect to get back?
    Are you getting any exceptions? If so, please post the exception message.

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP

    i'm using jcreator software....when i run this program ...they output is error....i dont know which part error...

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: PLEASE HELP

    can you post the error message?

  7. #7
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP

    --------------------Configuration: <Default>--------------------
    java.lang.NoClassDefFoundError: Day
    Caused by: java.lang.ClassNotFoundException: Day
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    Could not find the main class: Day. Program will exit.
    Exception in thread "main"
    Process completed.

  8. #8
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Smile Re: PLEASE HELP

    DayType d = new DayType(SUNDAY);
    What is SUNDAY?

    if you mean this

    final static int SUN = 0;
    then please change the above SUNDAY TO SUN.

    After changing this it running fine, but one logical error in your previous day function.

    Secondly,

    if your current day in sun=0
    then previous day will be -1;


    so what it will print.


    public int previousDay(){
    int prevDay;
    prevDay = day - 1;
    return prevDay;
    }
    Thanks and Regards
    Dan Brown

    Common Java Mistakes