我不知道如何通過用戶輸入...請幫助!?!?這是用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