0

I was here earlier before, and got pointed in the right direction. But I couldn't get the offered solution to work. It now mostly works, but i'm stuck on one part, and I'm not sure how to proceed. If anyone can point me to the right direction, i'll be grateful. I just need a hint, or pointers to something I'm not seeing.
I'm trying to add a random number of days, and determine what that adds up to. I know I have to have a counter that flips over after 7, but I've tried everything, and keep getting errors

import java.util.*;
public class pooped
{
    static Scanner console = new Scanner(System.in);

    public static void main(String[] args) 
    {
        int day;
        System.out.println(" Days of the week are numbered 1-7"+
                    "From Sunday to Saturday, enter a number now");
        day = console.nextInt();

        System.out.println(isWeek(day));
        printday(day);
    }

    public static boolean isWeek(int day)
    {
        return day >= 0 && day <= 7;
    }

    static Scanner console = new Scanner(System.in);

    public static void addDay()
    {
        int date;
        System.out.println("Enter how many days you want to go forward.");
        date = console.nextInt();

        if (int date > 0)
        {
            int day = date + 1;
        }
    }

    public static void printday(int day) 
    {
        switch (day) {

        case 1:
            System.out.println("Sunday");
        break;

        case 2:
            System.out.println("Monday");
        break;

        case 3:
            System.out.println("Tuesday");
        break;

        case 4:
            System.out.println("Wednesday");
        break;

        case 5:
            System.out.println("Thursday");
        break;

        case 6:
            System.out.println("Friday");
        break;

        case 7:
            System.out.println("Saturday");

        default:
        break;
        }
    }
}
12
  • You didn't ask a question. Commented May 5, 2015 at 15:17
  • I'm trying to add a random number of days, and determine what that adds up to. I know I have to have a counter that flips over after 7, but I've tried everything, and keep getting errors. Commented May 5, 2015 at 15:18
  • @ReinFowler what's not working? Commented May 5, 2015 at 15:20
  • @ReinFowler you declared console twice Commented May 5, 2015 at 15:21
  • You arent calling addDay() method in main class Commented May 5, 2015 at 15:21

2 Answers 2

1

If you need

a counter that flips over after 7

consider using day = day % 7; in your main method, which gives you the modulo operation.

Sign up to request clarification or add additional context in comments.

Comments

0

When you say "I have to have a counter that flips over after 7", do you mean that 7 should roll back to 0, 8 to 1, etc? If that's the case, you need to look at the modulus operator (%)

You inWeek function looks incorrect. If your day is 0 based, it should be:

public static boolean isWeek(int day)
{
    return day >= 0 && day < 7;
}

Otherwise you will have 8 days.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.