我希望能夠創建一個for循環這樣對於每個循環和for循環的Java
For(each booking)
所有你專家在那裏聽起來很簡單,但香港專業教育學院試圖研究如何做到這一點, 及其給我留下了有點迷糊,
我認爲ID需要每個循環,這將是這樣的
for (type var : coll) {
body-of-loop
}
這個程序創建一個新的預訂,然後讓我們呃把這些細節輸入到預訂的程序中,我已經命名了這個B1。這是你輸入到for循環的值嗎?
我知道生病得到了評價,但我不明白我是如何得到它爲每個預訂循環。
感謝您的快速回答,我編寫了一些現在不適合提供的代碼。希望它能讓你更容易看到。
訂座艙位
public class Booking
{
private int bookingId;
private String route;
private double startTime;
private String bookingDate;
public Booking()
{
bookingId = 0000;
route = "No Route Entered";
startTime = 0.00;
bookingDate = "No Date entered";
}
public int getBookingId()
{
return bookingId;
}
public String getRoute()
{
return route;
}
public double getStartTime()
{
return startTime;
}
public String getBookingDate()
{
return bookingDate;
}
public void setBookingId(int bookingId)
{
this.bookingId = bookingId;
}
public void setRoute(String route)
{
this.route = route;
}
public void setStartTime(double startTime)
{
this.startTime = startTime;
}
public void setBookingDate(String bookingDate)
{
this.bookingDate = bookingDate;
}
public Booking(int bookingId, String route, double startTime, String bookingDate)
{
setBookingId(bookingId);
setRoute(route);
setStartTime(startTime);
setBookingDate(bookingDate);
}
public String toString()
{
return "BookingId: " + getBookingId() + "\nRoute: " + getRoute() + "\nStart Time: " + getStartTime() +
"\nBooking Date: " + getBookingDate();
}
}
主類
import java.util.*;
public class Main {
public static void main(String[] args) {
//<editor-fold defaultstate="collapsed" desc="Creates new Student and booking">
Student s1 = new Student();
Booking b1 = new Booking();
s1.setStudentId(Integer.parseInt(JOptionPane.showInputDialog("Enter ID for Student: [0001]")));
s1.setFname(JOptionPane.showInputDialog("Enter first name of Student: "));
s1.setLname(JOptionPane.showInputDialog("Enter last name of Student: "));
s1.setAddress(JOptionPane.showInputDialog("Enter address for Student: "));
s1.setPhoneNo(JOptionPane.showInputDialog("Enter phone number for Student: "));
s1.setOtherDetails(JOptionPane.showInputDialog("Enter other details for Student: [Glasses?]"));
b1.setBookingId(0002);
b1.setStartTime(Double.parseDouble(JOptionPane.showInputDialog("Enter Start time for Booking: [1200]")));
b1.setBookingDate(JOptionPane.showInputDialog("Enter Date for Booking: [01-JAN-12]"));
//</editor-fold>
//For Each Booking
}
}
}
如果你花費了相同的努力來解釋你想要的數額而不是你花費的時間,我會理解你的問題。 – UmNyobe 2012-03-13 13:12:22
不知道你在做什麼。對於每個循環只能與實現'Iterable'的類一起使用。通常,對於每個循環,也不應該用來修改它們迭代的Iterable。您是否試圖通過迭代每個字段來初始化預訂? – Dunes 2012-03-13 13:16:20
我添加了代碼Iive,應該幫助 – user1081326 2012-03-13 13:27:02