Да это задание для школы! поэтому никаких ответов, пожалуйста, просто руководство для работы:На основе Java, я не могу найти, где я ошибаюсь в своем коде
Этот код должен получить день недели, установить день и распечатать день. Также ему нужно увеличивать день на один и возвращать на следующий день, уменьшать данный день на единицу и возвращать предыдущий день, а затем увеличивать день на заданную пользователем сумму и возвращать в какой день это будет в х дней.
import java.util.Scanner;
public class MyDay
{
private int tempDays;
private String day;
public String toString()
{
return (day);
}
//Creates the method setDay, Uses switch statements to determine the day.
public void setDay(int tempDay)
{
String day;
switch (tempDay){
case 1: day= "Sun";
break;
case 2: day= "Mon";
break;
case 3: day= "Tues";
break;
case 4: day= "Wednes";
break;
case 5: day= "Thurs";
break;
case 6: day= "Fri";
break;
case 7: day= "Sat";
break;
}
return (day);
}
//Returns the day as a string.
public Day setName(String day)
{
day = tempDay;
return day;
}
//Creates the method printDay, returns the string day.
public void printDay()
{
return (day);
}
//Creates the method nextDay, Determines the next day.
public void nextDay()
{
nextDay=(tempDay+1)%7;
tempDay(nextDay);
printDay();
}
//Creates the method lastDay, Determines the previous day.
public void lastDay()
{
lastDay=(tempDay-1)%7;
tempDay(lastDay);
printDay();
}
//Creates the method getDay, Determines the next day it will be based on the users input.
public void getDay()
{
static Scanner console= new Scanner(System.in);
int x=0;
int y=0;
System.out.println("The next number you will be prompted to enter will return\n"+
"what day it will be in that many days.");
System.out.println("Enter a number using numeric keys only.");
x= console.nextInt();
y = day +(x);
Day = y %7;
tempDay(getDay);
printDay();
}
//Allows Day to be minpulated.
public day()
{
tempDay(0);
}
//converts Day into a string.
public day (int tempDay)
{
tempDay(day);
}
public static void main(String[] args)
{
//Import Scanner as imput device.
static Scanner console= new Scanner(System.in);
System.out.println("Please enter the day you wish to set.");
System.out.println("Enter 1 for Sunday\n"+"Enter 2 for Monday\n"+"Enter 3 for Tuesday\n"+
"Enter 4 for Wednesday\n"+"Enter 5 for Thursday\n"+"Enter 6 for Friday\n"+
"Enter 7 for Saturday");
tempDay= console.nextInt();
Day myDay = new Day(tempDay);
System.out.println();
System.out.println("Today is: ");
myDay.printDay();
System.out.println("Tomorrow is: ");
myDay.nextDay();
System.out.println("Yesterday was: ");
myDay.lastDay();
System.out.println("In "+ x +"day(s), it will be: ");
myDay.getDay();
}
}
Сообщение об ошибке я получаю:
----jGRASP exec: javac -g MyDay.java
MyDay.java:69: error: illegal start of expression
static Scanner console= new Scanner(System.in);
^
MyDay.java:83: error: invalid method declaration; return type required
public day()
^
MyDay.java:89: error: invalid method declaration; return type required
public day (int tempDay)
^
MyDay.java:98: error: illegal start of expression
static Scanner console= new Scanner(System.in);
^
4 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
«требуется тип возврата» - Вы пробовали это самостоятельно? Я бы рекомендовал сделать снимок. – Vulcan
Вы не можете объявить локальную переменную 'static' – MadProgrammer
yes @Vulcan я получил от 48 ошибок до 4 –