Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


badrul hisham
SENTINEL
2 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


PLZ GIVE THE SUGGESTION,WHERE I MUST PUT THE SENTINEL IN THIS PROGRAME OR 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();
    }

}


Advertisement
View Answers

February 8, 2011 at 1:00 PM


Implementation of DayType class

import java.util.*;
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 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){
            DayType d = new DayType();
            Scanner input=new Scanner(System.in);
            boolean check=false;
            do{
            System.out.println("******Test Day******");
            System.out.println("1 Set day");
            System.out.println("2 Print day");
            System.out.println("3 Return day");
            System.out.println("4 Return Previous day");
            System.out.println("5 Return Next day");
            System.out.println("6 Exit");
            System.out.println();

            System.out.print("Enter your choice: ");
            int num=input.nextInt();
            switch(num){
            case 1:
            System.out.print("Set day(0-6): ");
            int day=input.nextInt();
            d.setDay(day);
            break;
            case 2:
            d.print();
            break;
            case 3:
            System.out.print("Next day: ");
            d.setDay(d.nextDay());
            d.print();
            break;
            case 4:
            System.out.print("Previous day: ");
            d.setDay(d.previousDay());
            d.print();
            case 5:
            System.out.print("Add no of days: ");
            int no=input.nextInt();
            d.setDay(d.addDays(no));
            d.print();
            break;
            case 6:
            check=true;
            break;
            }
            }
            while(!check);
    }
}


February 8, 2011 at 7:24 PM


thank you very much friend...



Related Tutorials/Questions & Answers:
SENTINEL
SENTINEL  PLZ GIVE THE SUGGESTION,WHERE I MUST PUT THE SENTINEL IN THIS PROGRAME OR CODING public class DayType{ final static int SUN = 0; final static int MON = 1; final static int TUE = 2; final
sentinel value
sentinel value  how to count the number of red cars that assume 10 cars using sentinel value
Advertisements
sentinel value
sentinel value  how to count the number of red cars. Assume there are 10 cars.   how to count the number of red cars that assume 10 cars using sentinel value
sentinel value
sentinel value  how to count the number of red cars. Assume there are 10 cars
how to find [count the number of integers whose value is less than the average value of the integers]
a collection of payroll amounts entered at the terminal until a sentinel amount of 999 is entered. After the sentinel has been entered, display the total payroll
a java program
a java program  Write a java program that accepts positive numbers from the user and finds both the average, maximum, and the minimum value of entered numbers. The sentinel value (the last value that differs from the previous
java program
java program  A user will input a sequence of positive integers ending with a sentinel -1. write a while loop hat counts the number of even an dodd integers and prints the cumulative total. for example, if the input is 1 7 2 9
Creat a program MinMax.java
Creat a program MinMax.java  Create a program MinMax.java that finds and prints the minimum and the maximum of integers read in from the keyboard. Use -9999 as a sentinel to stop the read. Do not count -9999 as one
java compilation - Design concepts & design patterns
a `$` sentinel.  Hi Friend, Try the following code: import java.util.
INTEGERS
results. Use class Scanner and sentinel-controlled repetition to obtain the data
In Java..
the sentinel value -1. After all data has been read, the tester class should
Logic and desgin HELP just need to get started on this.
is finished. When purchases are complete, enter a sentinel value of -1 (Make certain you do not include the -1 sentinel value in your total). Keep track
 

 

 

DMCA.com