Design and implement the class Day that implements the day ofthe week in a program.

Write your question here.

Design and implement the class Day that implements the day ofthe week in a program. The class Day should store the day,such as Sun for Sunday. The program should be able to performthe following operations on the object of type Day:
a. set the day
b. print the day
c.return the day
d.return the next day
e. return the previous day
f. calculate and return the day by adding certain days to the current day.. Such as if today is monday and we add four daysit will return Friday
g. add the appropriate constructors
h.write the definitions of the methods to implement a -g
i.write a program to test the operations of class Day.

i have this codes but i cant make the previous, next and adding days methods to work

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication5;

import java.util.Scanner;

/**
*
* @author paciente
*/
public final class Day {

private int Day;
private String Days;



@Override
public String toString()
{
return (Days);
}
public void setDay(int Day)
{
if (Day == 0)
Days = "Sun";
if (Day == 1)
Days = "Mon";
if (Day == 2)
Days = "Tue";
if (Day == 3)
Days = "Wed";
if (Day == 4)
Days = "Thur";
if (Day == 5)
Days = "Fri";
if (Day == 6)
Days = "Sat";
}
public Day setNameDay(String Day)
{
Day = Days;
return this;
}

public void printDay()
{
System.out.println(Days);
}



public void previousDay()
{


}

public void nextDay()
{
Day=Day+=2;

setDay(Day);
printDay();

// if (Day <1)
// Day = 1;


}

public void calculateDay()
{
int calc = 0;
int dayAdd =0;

Scanner scanner = new Scanner(System.in);
System.out.println("Enter number of days to add: ");
calc =scanner.nextInt();

dayAdd = Day +(calc);

Day = dayAdd %7;

setDay(Day);
printDay();
}

public Day()
{
setDay(0);
}
public Day (int Day)
{
setDay(Day);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("What is your initial day?\nSunday\t\t=\t0\nMonday\t\t=\t1\nTuesday\t\t= \t2\nWednesday\t=\t3\nThursday\t=\t4\nFriday\t\t=\ t5\nSaturday\t=\t6");
System.out.print("Enter the number:");
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
Day myDay = new Day(x);
System.out.println("");

System.out.print("The day of the week is: ");
myDay.printDay();
System.out.println();

System.out.print("The previous day is: ");
myDay.previousDay();

System.out.println();

System.out.print("The next day is: ");
myDay.nextDay();

System.out.println();

myDay.calculateDay();
System.out.println();
}
}
Dude, this is not a java forum.
Topic archived. No new replies allowed.