我不知道如何通过用户输入...请帮助!?!?这是用java编写的。我的教授提供了这个我不做任何改变。如何获取用户输入并将其传递给java中的构造函数?它说artCourse是undefined
/** A generic course at a University
*/
public abstract class Course
{
// The course subject
private String subject;
// The course number
private int number;
// The time the course meets
private MeetingTime time;
/** Create a new Course object and initialize the course
* name, time and difficulty.
* @param theSubject the course subject
* @param theNumber the course number
* @param theTime the course time
*/
public Course (String theSubject, int theNumber,MeetingTime theTime)
{
subject = theSubject;
number = theNumber;
// Store a copy of the time object in the course object.
time = new MeetingTime (theTime.getStartTime(), theTime.getEndTime());
}
/** Get the time when the course meets.
* @return the time the course meets
*/
public MeetingTime getTime()
{
return new MeetingTime (time.getStartTime(), time.getEndTime());
}
}
这是我迄今为止的主要
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
ArrayList<String> courseSchedule =new ArrayList<String>();
String theSubject = " ";
Integer theNumber = 000;
Double theTime = 0000.0;
while (!theSubject.equals("DONE"))
{
System.out.print("Enter a course subject: ");
theSubject = in.nextLine();
System.out.print("Enter course number: ");
theNumber = in.nextInt();
System.out.print("Enter course start time and end time: ");
theTime = in.nextDouble();
String temp = in.nextLine();
if (theSubject.equals("ART"))
{
System.out.print("Enter the studio number: ");
String theStudioNumber = in.nextLine();
System.out.print("Enter the instructors name: ");
String theInstructor = in.nextLine();
ArtCourse artCourse = new ArtCourse (theSubject, theNumber, theTime, theStudioNumber, theInstructor);
}
这是我的子类。
public class ArtCourse extends Course
{
private String studioNumber;
private String instructor;
public ArtCourse (String theSubject,
int theNumber,
MeetingTime theTime,
String theStudioNumber,
String theInstructor)
{
super(theSubject, theNumber, theTime);
studioNumber = "????";
instructor = "????";
}
}
您已经有几行代码创建一个新对象并将参数传递给构造函数。你为什么认为这个任务的这个实例是不同的? – csmckelvey
您需要先创建课程的子类。 – Sedrick