Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

numtoWeek java program help This is off a study guide but I think I am doing thi

ID: 641599 • Letter: N

Question

numtoWeek java program help

This is off a study guide but I think I am doing this wrong. Thank you in advance. Here is the problem:

Write a method, namely numToWeek, to convert each element in the first column to the corresponding element in the second column (of the same row). The method will take one of the elements in the first column as the parameter and return the value of the corresponding element in the second column to the caller. So the following statement should print out "Friday" on the screen.

System.out.println(numToWeek(5) );

1

Monday

2

Tuesday

3

Wednesday

4

Thursday

5

Friday

6

Saturday

7

Sunday

1

Monday

2

Tuesday

3

Wednesday

4

Thursday

5

Friday

6

Saturday

7

Sunday

Explanation / Answer

import java.util.Scanner;

public class lab4 {
  
   public static String numToWeek(int w){
       if(w == 1){
           return "Monday";
       }
       if(w == 2){
           return "Tuesday";
       }
       if(w == 3){
           return "Wednesday";
       }
       if(w == 4){
           return "Thursday";
       }
       if(w == 5){
           return "Friday";
       }
       if(w == 6){
           return "Saturday";
       }
       if(w == 7){
           return "Sunday";
       }
       return "Invalid!";
   }
  
   public static void main(String[] args) {
       System.out.println(numToWeek(5));
   }

}