我不确定我究竟做错了什么,但我想将get方法中的变量放入testClass中的print statetment。例如,用户输入所有信息,然后输出语句。
import java.util.Calendar;
import java.util.Scanner;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class testClass {
public testClass() {
System.out.println("ALARM SET TO: " + getHour ":" + getMinutes + amOrPm);
}
public int getHour() {
Scanner input = new Scanner(System.in);
int getHour;
System.out.println("ENTER HOUR FOR YOUR ALARM: ");
getHour = input.nextInt();
return getHour;
}
public int getMinutes() {
Scanner input = new Scanner(System.in);
int getMinutes;
System.out.println("ENTER MINUTES FOR YOUR ALARM: ");
getMinutes = input.nextInt();
return getMinutes;
}
public int getAMOrPM() {
Scanner input = new Scanner(System.in);
int amOrPm;
System.out.println("ENTER AM or PM FOR YOUR ALARM: ");
amOrPm = input.nextInt();
return amOrPm;
}
public void getSystemTime() {
DateFormat df = new SimpleDateFormat("HH:mm");
Calendar calobj = Calendar.getInstance();
System.out.println(df.format(calobj.getTime()));
}
} // end of testClass
答案 0 :(得分:3)
定义一个调用构造函数类的主方法
public static void main(String[] args)
{
testClass r = new testClass();
}
要调用某个功能,您需要添加一个括号。所以转到这个
public testClass() {
System.out.println("ALARM SET TO: " + getHour()+":" + getMinutes() + getAMOrPM());
}