75%的作品,這部分工作正常,我的任務......我已經得到了部分洛根。計劃「日」,75%的工作...幫助JAVA
它下面我不能運行與該部分的代碼...
- F.計算並返回當天 一天添加某些天的一天。例如,如果當天是星期一,並且我們添加了四天,則要返回的日期是星期五。同樣,如果今天是星期二,並且 我們增加13天,則返回的日期是星期一。 G.添加適當的構造函數。
任何建議如何我可以構造我寫的,以得到它與第一部分計算?
import java.util.*;
/*
Personal information
*/
public class MyDayIIII
{
static Scanner readinput = new Scanner(System.in); //Creates common input object class
String d1; // Private member variable
public MyDayIIII(String d1) //Constructor of value Sunday
{
d1 = "Sunday";
}
public void setD1(String theD1) //Assigns value for user's input for "set day"
{
d1 = theD1;
}
public String claimD1() //Displays user's day
{
return d1;
}
// print the day, looks unnecessary
public void printD1()
{
System.out.println("Printed Day: " + d1);
}
// return the next day
public String tomD1()
{
// using direct comparison will fail as day == "Saturday"?
// so use compareTo() method...
if(d1.compareTo("Saturday") == 0)
return ("Sunday");
else if(d1.compareTo("Sunday") == 0)
return ("Monday");
else if(d1.compareTo("Monday") == 0)
return ("Tuesday");
else if(d1.compareTo("Tuesday") == 0)
return ("Wednesday");
else if(d1.compareTo("Wednesday") == 0)
return ("Thursday");
else if(d1.compareTo("Thursday") == 0)
return ("Friday");
else if(d1.compareTo("Friday") == 0)
return ("Saturday");
else
return ("\"Please Capitalize the First Letter of Your Day(e.g. Monday)\"");
}
// return the previous day
public String SetprD1()
{
if(d1.compareTo("Friday") == 0)
return ("Thursday");
else if(d1.compareTo("Thursday") == 0)
return ("Wednesday");
else if(d1.compareTo("Wednesday") == 0)
return ("Tuesday");
else if(d1.compareTo("Tuesday") == 0)
return ("Monday");
else if(d1.compareTo("Monday") == 0)
return ("Sunday");
else if(d1.compareTo("Sunday") == 0)
return ("Saturday");
else if(d1.compareTo("Saturday") == 0)
return ("Friday");
else
return ("\"Please Capitalize the First Letter of Your Day(e.g. Monday)\"");
}
public static void main (String args[])
{
MyDay testday = new MyDay("Sun");
System.out.print("Enter A Day(First Letter Capitalized & Full Spelling) ");
// read and store user's day
String storeday = readinput.nextLine();
// invoke setDay() method to set a day defined by user
testday.setDay(storeday);
// invoke getDay() method to get a day
System.out.println("You Chose: " + testday.getDay());
// test printing by invoking printDay() method
testday.printDay();
// invoke getPreDay() method to get the previous day
System.out.println("Day Prior Is: " + testday.getPreDay());
// invoke getNextDay() method to get the next day
System.out.println("The Following Day Is: " + testday.getNextDay());
}
}
我一直試圖插入這一點,把它做兼職F.
這將啓動,但我得到以下...
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.valueOf(Integer.java:554)
at TextCalculator.main(TextCalculator.java:24
所以我把它拿出來,中原來......誰能給我任何意見,我感到沮喪...
我的目標是創建7個元素的數組,然後用7:3的係數計算未來的日期,並把它對應以元素的價值...
String[] day = new String[7];
day[0] = "Monday"; //Elements were assigned the day of the week for their value
day[1] = "Tuesday";
day[2] = "Wendesday";
day[3] = "Thursday";
day[4] = "Friday";
day[5] = "Saturday";
day[6] = "Sunday";
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a Number for Future Days:"); //Prompting user to input number of days
String future = scanner.nextLine();
int futureDay = Integer.valueOf("future");
int numDay = day.length % 7; //Using value of elements, with modulus 7 to assign value and determine placement
while (numDay >= day.length)
{
numDay -= day.length;
}
這是什麼? – Makky
這是一個學校的作業,我分別寫我的代碼,然後把它們放在一起...這對我來說是最簡單的可視化... – iTrauco