- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我以为我可以制作这个简单的程序,而不需要寻求人类的帮助并浪费他们的时间,但我的“想法”在这里被绊倒了。到目前为止,谷歌一直在帮助我,但不幸的是,这是我所能得到的。因此,我们非常感谢任何帮助,在开始之前请注意,我刚刚开始接触 Java。
正如标题所说,这是一个类似于 Google Keep
的迷你议程程序,我们可以这么说,用户会看到一个基于控制台的菜单,如下所示:
当他/她转到选项 2 时,程序应正确列出事件。目前,它仅显示所有内容。实际上,这是 main 中的代码:
public class Agenda
{
public static void main(String[] args) throws IOException
{
Person person = new Person();
Event event = new Event();
Scanner sc1 = new Scanner(System.in);
Scanner sc2 = new Scanner(System.in);
//System.out.println(date.toString());
//System.out.println(hourMinutesSeconds.toString());
boolean agenda = true;
while (agenda)
{
System.out.println("Menu");
System.out.println("====");
System.out.println("1. Register personal events");
System.out.println("2. Current week/day events");
System.out.println("3. Delete events");
System.out.println("4. Edit events");
System.out.println("5. Close agenda");
int choice = sc1.nextInt();
switch (choice)
{
case 1:
{
int exit = 1;
String save = "";
while (exit == 1)
{
System.out.println("Register personal events");
System.out.println("=========================");
System.out.println("Your name:");
person.setName(sc2.nextLine());
System.out.println("Person phone number:");
person.setPhoneNumber(sc2.nextLine());
System.out.println("Add details about someone's anniversary(optional: schedule a date in the format as follows (hour/minutes/seconds day/month/year))");
event.setBirthDay(sc2.nextLine());
System.out.println("Add details about the conference(optional: schedule a date in the format as follows (hour/minutes/seconds day/month/year))");
event.setMeeting(sc2.nextLine());
System.out.println("Add details about the debate(optional: schedule a date in the format as follows (hour/minutes/seconds day/month/year))");
event.setDebate(sc2.nextLine());
System.out.println("Save the event?yes\\no");
save = sc2.nextLine();
if (save.equals("yes"))
{
String fileName = person.toString().substring(6, person.toString().indexOf("\n")) + ".txt";
EventSaver.saveToFile(person.toString() + event.toString(), fileName);
}
System.out.println("Do you wish to add more events? 1-Yes, 0-No");
exit = sc1.nextInt();
}
break;
}
case 2:
{
String[] events = EventSaver.readEvents();
for (int i = 0; i < events.length; i++)
{
System.out.println(events[i]);
}
break;
}
case 3:
{
break;
}
case 4:
{
break;
}
case 5:
{
agenda = false;
sc1.close();
sc2.close();
System.out.println("Agenda closed");
break;
}
default:
{
throw new IllegalArgumentException("Invalid option...\ngoing back to main menu");
}
}
}
}
}
EventSaver 类:
public class EventSaver
{
private static String FILENAME = "D:\\my_stuff\\some_dir\\some_dir\\Workspace\\EventAgenda\\src\\";
public static void saveToFile(String content, String fileName)
{
BufferedWriter bw = null;
FileWriter fw = null;
try
{
fw = new FileWriter(FILENAME + fileName);
bw = new BufferedWriter(fw);
bw.write(content);
System.out.println("Event saved");
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if (bw != null)
{
bw.close();
}
if (fw != null)
{
fw.close();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
public static String[] readEvents() throws IOException
{
File folder = new File("D:\\my_stuff\\some_dir\\some_dir\\Workspace\\EventAgenda\\src\\");
File[] listOfFiles = folder.listFiles();
String fileContents = "";
String[] content;
for (int i = 0; i < listOfFiles.length; i++)
{
File file = listOfFiles[i];
if (file.isFile() && file.getName().endsWith(".txt"))
{
fileContents += FileUtils.readFileToString(file, "UTF-8") + "\n";
}
}
content = fileContents.split("\n");
return content;
保存事件后,属于特定用户的 .txt
文件如下所示:
Name: Bob
Phone Number: 0741123458
Birthday: Elena, at LongDrinks(19:00:00 19/06/2017)
Conference: Current stage of the project SMFA(20:00:00 24/06/2017)
Debate: The meaning of this world(21:30:00 19/06/2017)
我尝试获取这些日期并以某种方式比较它们,但使用此代码却徒劳无功:
public class SetEvents {
if (event.toString().indexOf("(") != -1)
{
String[] eventTimeAndDate = (event.toString().substring(event.toString().indexOf("(") + 1, event.toString().indexOf(")"))).split(" ");
String[] eventTime = eventTimeAndDate[0].split(":");
String[] eventDate = eventTimeAndDate[1].split("/");
Time hourMinutesSeconds = new Time();
hourMinutesSeconds.setHour(Integer.parseInt(eventTime[0]));
hourMinutesSeconds.setMinute(Integer.parseInt(eventTime[1]));
hourMinutesSeconds.setSecond(Integer.parseInt(eventTime[2]));
MyDate date = new MyDate(Integer.parseInt(eventDate[2]), Integer.parseInt(eventDate[1]), Integer.parseInt(eventDate[0]));
}
但是有了这个,我只能从文件中提取第一个日期出现的情况,并且我需要获取所有出现的情况,使用其他类以某种方式比较它们,以查找当前周和天的事件,并在选择选项 2 时正确显示它们。我可以做吗?谢谢
最佳答案
在 Java 中还有第二个 indexOf
方法
indexOf(String str, int fromIndex)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
(参见:https://docs.oracle.com/javase/7/docs/api/java/lang/String.html)
所以你可以这样:
int startAt = 0;
String evt = event.toString();
while (evt.indexOf("(", startAt) != -1){
startAt = indexOf("(", startAt)+2;
String[] eventTimeAndDate = (event.toString().substring(event.toString().indexOf("(") + 1, event.toString().indexOf(")"))).split(" ");
String[] eventTime = eventTimeAndDate[0].split(":");
String[] eventDate = eventTimeAndDate[1].split("/");
Time hourMinutesSeconds = new Time();
hourMinutesSeconds.setHour(Integer.parseInt(eventTime[0]));
hourMinutesSeconds.setMinute(Integer.parseInt(eventTime[1]));
hourMinutesSeconds.setSecond(Integer.parseInt(eventTime[2]));
MyDate date = new MyDate(Integer.parseInt(eventDate[2]), Integer.parseInt(eventDate[1]), Integer.parseInt(eventDate[0]));
}
编辑:没有测试它,但在这个 while 循环中你应该能够提取你得到的所有日期
关于Java:基本议程程序,人们可以在其中操纵他们的事件,并根据需要获得当前一周或一天的事件通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44648650/
我是puppeteer的新手(通常对javascript不太了解),并且正在尝试编写一些基本功能来: 从XPath获取所有链接 循环浏览并单击那些链接 屏幕截图并保存页面的HTML 返回屏幕快照,然后
您好,我正在尝试创建一个我想通过网络发送到服务器的数据包,我几乎已经对数据包进行了排序,但是它缺少一个长度标识符,我需要在我的方法结束时计算它并添加放入数据包。 数据包结构是这样的 前导值标识符 (U
我正在尝试更改按钮的样式(实际上只是一个 div)。我可以在 CSS 中使用 .classname:active 来实现,但是按钮只会在被点击时改变样式;单击释放后,它不会保持样式更改。所以,我决定使
我有一个下拉导航栏(fiddle here 和下面的代码片段)。单击 SubItem 时,JS 函数会进行 Ajax 调用(未显示)。我想要实现的是在单击 SubItem 时隐藏 SubItems 列
给定一组平面图(Autocad、svg 或任何需要的格式...),我想以编程方式生成从 A 点到 B 点的方向。基本上我想说:“我如何获得从101房间到143房间?” (或三倍奖励积分,从 101 房
我在 Win32 下的 MS dev studio 中将一些代码从 C 转换为 C++。在旧代码中,我使用 QueryPerformanceCounter() 进行了一些高速计时,并对获得的 __in
我正在寻找一种方法来从 QTableWidget 单元格中挤出所有可能的空间。我粘贴了一些代码来演示我在下面尝试过的事情,并且我上传了在 OSX 10.8.5、Qt 4.8.4、PySide 1.2.
对于 PhoneGap 移动应用程序,我有以下场景: 应用程序打开并显示index.html 用户登录并被重定向到 home.html 然后用户可以转到 news.html 我想以一种方式处理 hom
可能是一个简单的问题: 尝试使用plotly生成散点图并自定义图例。 这是我的数据: require(plotly) set.seed(1) my.df % add_annotations(text=
在 Instagram/Facebook 上的帖子下方,您会看到类似“第 1 个人、第 2 个人和其他 10 个人喜欢此帖子”的文字。我想知道如何使用 Django 来实现网站的相同效果?通常,我会使
我必须使用 Form.Action 重定向到将从我的页面获取值的脚本。值得注意的是,这个脚本是外部的。 我的问题是,我还想要被点击并连接了 Action 的按钮,以便首先在后面的代码中完成一些功能。
我有一个问题。 我可以在 Express 中操纵路线吗?当我发出 get 或 post 申请地址时,我可以将 2 条路线传递到同一个 get 或 post 申请吗?像这样的东西。 module.exp
如果我在不同的 Canvas 上绘制我的图像,我可以使用 js 库应用一些效果,如淡入淡出、移动和其他效果吗?如果可能的话,在速度和性能方面可能会很有趣,而不是操纵“原始”?非常感谢 最佳答案 if
我希望你能帮助我。如何转换这个扁平的 JavaScript 数组,来自: [ {"state":"First State","district":"First District","local_
我有一个 React JSX 元素,我想遍历它的子元素,对其中的每个字符串元素执行替换(或任何其他操作),然后返回新的、修改后的 JSX 元素。例如: var element = Text { var
我正在制作一个 Java 网络项目,我想在其中使用一些 javascript 操作一些前端 SVG 元素。 我正在绘制一个相当简单的车库图,其中有一个来自 JSP 页面的棚屋元素。 我想要一个 jav
我读过许多帖子,其中人们询问有关对 XML 元素强制执行某些属性顺序的问题,一般的回答是这不合法/必需/不允许/相关/其他。 我不是在寻找任何说我不应该关心属性顺序的回复,所以如果这是你的观点,请不要
大家好,我的问题是,如何将两个 C 风格的字符串 append 到一个字符串中? 我对 C++ 的处理方式 (std::string) 很感兴趣,我从未接触过 C 风格的字符串,需要为我当前的开发项目
我选择了 HTML 页面上的所有节点,如下所示: var all = $('*'); 然后我遍历每个节点,检查每个节点是否有关联的文本值: var newDom = all.map((i, node)
示例取自 Mozilla's help page re = /(\w+)\s(\w+)/; str = "John Smith"; newstr = str.replace(re, "$
我是一名优秀的程序员,十分优秀!