java oop

java oop

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)

instruction - Define DayType class appropriate methods and constructor - Your program should get the input/output via the main method and pass appropriate arguments through the class methods. - Your program should continuously running until it receives a special signal (character/number) in which the program will exit.

View Answers

February 4, 2011 at 2:37 PM

Hi Friend,

Try this:

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();
        }       
}

Hope that it will be helpful for you.

Thanks


February 8, 2011 at 12:52 PM

hi member

ask something haves one error in public static void and daytypes d=newtypes(sunday) ; program said cannot have static declared you know what the solution

Ads









Related Tutorials/Questions & Answers:
java oop
java oop  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
Java with OOP assignment (Eclipse)
Java with OOP assignment (Eclipse)  How do i control the length of characters in an input? E.g.: Enter your name > Hi * Name too short
Advertisements
oop
oop  can you tell me about why java is not 100% object oriented language
Java with OOP assignment (Eclipse) - Java Beginners
Java with OOP assignment (Eclipse)  "THREE Ts GAME" *Description* A "tic-tac-toe" game is a two player's board game where the game board..." games using Java. When your game application started, the players will be able
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.16.0 is released. Learn to use oop-lib-jvm version 0.16.0 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.16.0 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.16.0 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.16.1 is released. Learn to use oop-lib-jvm version 0.16.1 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.16.1 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.16.1 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.0 is released. Learn to use oop-lib-jvm version 0.17.0 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.0 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.17.0 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.1 is released. Learn to use oop-lib-jvm version 0.17.1 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.1 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.17.1 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.2 is released. Learn to use oop-lib-jvm version 0.17.2 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.2 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.17.2 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.3 is released. Learn to use oop-lib-jvm version 0.17.3 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.3 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.17.3 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.4 is released. Learn to use oop-lib-jvm version 0.17.4 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.4 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.17.4 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.18.0 is released. Learn to use oop-lib-jvm version 0.18.0 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.18.0 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.18.0 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.18.1 is released. Learn to use oop-lib-jvm version 0.18.1 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.18.1 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.18.1 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.18.2 is released. Learn to use oop-lib-jvm version 0.18.2 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.18.2 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.18.2 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.19.0 is released. Learn to use oop-lib-jvm version 0.19.0 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.19.0 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.19.0 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.20.0 is released. Learn to use oop-lib-jvm version 0.20.0 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.20.0 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.20.0 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.20.1 is released. Learn to use oop-lib-jvm version 0.20.1 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.20.1 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.20.1 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.20.2 is released. Learn to use oop-lib-jvm version 0.20.2 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.20.2 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.20.2 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
oop concept
oop concept  why Object class is super class for all class? 1.to use the Object class methods in subclass directly or 2.the Object class is usefull at the time of object create of subclass what
OOP
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.16.1-dev4o+a2fea905 is released. Learn to use oop-lib-jvm version 0.16.1-dev4o+a2fea905 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.16.1-dev4o+a2fea905 java library...+a2fea905 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 13 Mar
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.16.1-dev4u+b2f05e44 is released. Learn to use oop-lib-jvm version 0.16.1-dev4u+b2f05e44 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.16.1-dev4u+b2f05e44 java library...+b2f05e44 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 13 Mar
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.16.1-dev4z+7e0f0041 is released. Learn to use oop-lib-jvm version 0.16.1-dev4z+7e0f0041 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.16.1-dev4z+7e0f0041 java library...+7e0f0041 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 14 Mar
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev0v+25724c0c is released. Learn to use oop-lib-jvm version 0.17.1-dev0v+25724c0c in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev0v+25724c0c java library...+25724c0c of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 19 Apr
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev0w+54dd0dd0 is released. Learn to use oop-lib-jvm version 0.17.1-dev0w+54dd0dd0 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev0w+54dd0dd0 java library...+54dd0dd0 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 20 Apr
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev0z+70805b63 is released. Learn to use oop-lib-jvm version 0.17.1-dev0z+70805b63 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev0z+70805b63 java library...+70805b63 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 20 Apr
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev1o+35e72985 is released. Learn to use oop-lib-jvm version 0.17.1-dev1o+35e72985 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev1o+35e72985 java library...+35e72985 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 15 May
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev03+67bb5e23 is released. Learn to use oop-lib-jvm version 0.17.1-dev03+67bb5e23 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev03+67bb5e23 java library...+67bb5e23 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 01 Apr
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev18+089dd410 is released. Learn to use oop-lib-jvm version 0.17.1-dev18+089dd410 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.1-dev18+089dd410 java library...+089dd410 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 22 Apr
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.2-dev03+43981b51 is released. Learn to use oop-lib-jvm version 0.17.2-dev03+43981b51 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.2-dev03+43981b51 java library...+43981b51 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 17 May
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.3-dev0a+b6708d58 is released. Learn to use oop-lib-jvm version 0.17.3-dev0a+b6708d58 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.3-dev0a+b6708d58 java library...+b6708d58 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm project have released the latest version of this library on 15 Jun

Ads