Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中获取开始和结束日期_Java - Fatal编程技术网

在Java中获取开始和结束日期

在Java中获取开始和结束日期,java,Java,我正在用Java编写一个程序,允许用户选择一个选项(1:新建,2:打印范围,3:全部打印,退出)。一旦他们选择了上述其中一项,如果他们选择了“新建”,则输入约会日期,并输入约会描述,最后他们选择约会是否为(1=一次,2=每日,3=每月) 我在行“if(list.I.compareTo(lowDate)=0)”上遇到错误;“它给了我错误”AppointmentNew.java:69:表达式的非法开始。我不知道为什么它会给我这个错误 这是我的代码,我相信我已经完成了以上任务 import java.

我正在用Java编写一个程序,允许用户选择一个选项(1:新建,2:打印范围,3:全部打印,退出)。一旦他们选择了上述其中一项,如果他们选择了“新建”,则输入约会日期,并输入约会描述,最后他们选择约会是否为(1=一次,2=每日,3=每月)

我在行“if(list.I.compareTo(lowDate)=0)”上遇到错误;“它给了我错误”AppointmentNew.java:69:表达式的非法开始。我不知道为什么它会给我这个错误

这是我的代码,我相信我已经完成了以上任务

import java.util.*;

public class AppointmentNew 
{
public static void main (String[] args)
{
  List<String> list = new ArrayList<String>();
  Scanner stdin = new Scanner(System.in);
  String choice = "";
  int choiceNum = 0;
  String date = "";
  String descrip = "";
  int type = 0;
  String typeChose = "";

  System.out.println("Welcome to Appointment App!\n");
  System.out.println("\t============================\n");

  do
  {
     System.out.print("\tMake Choice ( 1: New, 2: Print Range, 3: Print All, quit): ");
     choice = stdin.nextLine();

     choiceNum = Integer.parseInt(choice);

     if (choiceNum == 1)
     {
        System.out.print("\n\n\tEnter New Appointment Date in mm/dd/yyyy format: ");
        date = stdin.nextLine();

        System.out.print("\n\n\tEnter New Appointment Description: ");
        descrip = stdin.nextLine();

        System.out.print("\n\n\tEnter Type (1 = Once, 2 = Daily, 3 = Monthly): ");
        type = stdin.nextInt();
        if (type == 1)
        {
          Once once = new Once(date, descrip);
           typeChose = "One-Time";
        }
        else if (type == 2)
        {
          Daily daily = new Daily(date, decrip);
           typeChose = "Daily";
        }
        else
        {
          Monthly monthly = new Monthly(date, descrip);
           typeChose = "Monthly";
        }
          String stringToAdd = "";
          strinToAdd = "New " + descrip + " Appointment Added for " + date;
          list.append(stringToAdd);

        System.out.println("\n\n\tNew " + typeChose + " Appointment Added for " + date);

     }

     if (choiceNum == 2)
     {
     System.out.print("\n\n\tEnter START Date in mm/dd/yyyy format: ");
     String lowDate = stdin.nextLine();
     System.out.print("\n\n\tEnter END Date in mm/dd/yyyy format: ");
     String highDate = stdin.nextLine();

     for(int i = 0; i < list.size(); i++)
        {
         int dateSpot = list.i.indexOf(" ");
           if (list.i.compareTo(lowDate) <= 0) && (list.i.compareTo(highDate) >= 0);
        {
           System.out.println(list.i);   
       }}
     }

     if (choiceNum == 3)
     {
       for(int i = 0; i < list.size(); i++)
       {
          System.out.println(list.i);     
       }
     }

  }while (choice != "quit");      
import java.util.*;
公共班级任命新
{
公共静态void main(字符串[]args)
{
列表=新的ArrayList();
扫描仪标准输入=新扫描仪(System.in);
字符串选择=”;
int-choiceNum=0;
字符串日期=”;
字符串descripp=“”;
int类型=0;
字符串typechoosed=“”;
System.out.println(“欢迎使用预约应用!\n”);
System.out.println(“\t===========================================\n”);
做
{
System.out.print(“\t做出选择(1:新建,2:打印范围,3:全部打印,退出):”;
choice=stdin.nextLine();
choiceNum=Integer.parseInt(选项);
如果(选通==1)
{
System.out.print(“\n\n\t输入新约会日期,格式为mm/dd/yyyy:”);
date=stdin.nextLine();
System.out.print(“\n\n\t输入新约会说明:”);
descripp=stdin.nextLine();
System.out.print(“\n\n\t终端类型(1=一次,2=每日,3=每月):”;
type=stdin.nextInt();
如果(类型==1)
{
一次=新一次(日期,描述);
typechoosed=“一次”;
}
else if(类型==2)
{
每日=新的每日(日期、日期);
typechoosed=“每日”;
}
其他的
{
每月=新的每月(日期,描述);
typechoosed=“每月”;
}
字符串stringToAdd=“”;
strinToAdd=“新建”+描述+”为“+日期”添加的约会;
list.append(stringToAdd);
System.out.println(“\n\n\t为“+日期”添加的新“+类型选择+”约会);
}
如果(选择项==2)
{
System.out.print(“\n\n\t开始日期,mm/dd/yyyy格式:”);
字符串lowDate=stdin.nextLine();
System.out.print(“\n\n\t结束日期,mm/dd/yyyy格式:”);
字符串highDate=stdin.nextLine();
对于(int i=0;i
} }


提前感谢您的帮助

访问列表元素的语法
list.i
不正确。您应该使用方法,例如
list.get(i)
,来获取列表中的元素

此外,整个
if
条件必须用括号括起来,并且
if
和它下面大括号中的块之间不应该有分号:

if ((list.get(i).compareTo(lowDate) <= 0) && (list.get(i).compareTo(highDate) >= 0))
{
    System.out.println(list.get(i));
}
if((list.get(i).compareTo(lowDate)=0))
{
System.out.println(list.get(i));
}

还有许多其他错误,包括试图将
字符串
值与
=
进行比较(不要这样做,请使用字符串的
等于
方法),以及大括号关闭问题。

存在许多问题。要访问
集合中的列表项
,您需要使用
get(int)
方法

list.get(i)
if语句格式错误

if (list.i.compareTo(lowDate) <= 0) && (list.i.compareTo(highDate) >= 0);
                                  ^-- Bad bracket
                                                                        ^-- This shouldn't be here
if(list.i.compareTo(lowDate)=0);
^--坏括号
^--这不应该在这里
应该是

if (list.get(i).compareTo(lowDate) <= 0 && list.get(i).compareTo(highDate) >= 0)
if(list.get(i).compareTo(lowDate)=0)

注意,在不需要的地方有一个额外的结束括号和
将使语句变得多余(即它实际上不会做任何事情)

好的,谢谢!但是在修复了“list.i”到“list.get(i)”之后,它仍然给了我同样的错误。“对不起,这么直截了当,我只是对此感到非常失望,我已经尝试修复这个问题至少两个小时了。
list.get(i)
是我注意到的第一件事;我已经更新了我的答案,包括了更多的更正。例如,你在“If(choiceNum==3)”一行中说,我应该改为使用“If(choiceNum.equals(3))”?