2005-12-26
2005-12-19
2005-12-18
2005-12-12
Homework 12-5-2005
未設定temp1時,temp1的輸出
The temperature = 0.0 degrees c
將temp2設定為0度C
The temperature = 0.0 degrees C
將temp1的scale更改為F
The temperature = 0.0 degrees F
設定temp1的度數部分為212
The temperature = 212.0 degrees F
設定temp2的degree和scale
The temperature = 100.0 degrees C
將100度c的temp2轉換成華氏
The temperature = 212.0 degrees F
temp1(212度F)是否相等/高/低於temp2(由100度C轉成的212度F)?
Are temp1 and temp2 equal? true
Is temp1 greater than temp2? false
Is temp1 less than temp2? false
設定temp1=0度C,轉換成如下(兩者相等)
The temperature = 32.0 degrees F
設定temp1=-40度F,轉換成如下(兩者相等)
The temperature = -40.0 degrees C
Lab 12-5-2005 (2) Overloading
不曉得為什麼跑出來的結果像是亂碼
也確認過他的型態等等問題
也沒有語法上面的錯誤
總之就很奇怪
後來做些更改
在class DateSixthTry的地方增加
public void outPut()
{
System.out.println(month+" "+day+","+year);
}
然後
在class OverloadingDemo的地方
改
System.out.println(date1);
System.out.println(date2);
System.out.println(date3);
為
date1.outPut();
date2.outPut();
date3.outPut();
之後就可以正常顯示結果如下
至於之前為什麼還是亂碼...
我還是不曉得....>"<
2005-12-05
"This"practice
package practicethis;import javax.swing.JOptionPane;
public class First
{
private String month;
private int day;
private int year;
public void writeOutput()
{
System.out.println(year+"/"+month+"/"+day);
}
public void readInput()
{
String StringYear = JOptionPane.showInputDialog("Enter year");
year = Integer.parseInt(StringYear);
month = JOptionPane.showInputDialog("Enter month");
String StringDay = JOptionPane.showInputDialog("Enter day");
day = Integer.parseInt(StringDay);
}
public void setDate(int month, int day, int year)
{
this.day = day;
this.year = year;
this.month = monthString(month);
}
public String monthString(int month)
{
switch (month)
{
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
default:
System.exit(0);
return "Eorror";
}
}
public int getDay()
{ return day; }
public int getYear()
{ return year; }
public int getmonth()
{
if (month.equalsIgnoreCase("January"))
return 1;
else if (month.equalsIgnoreCase("February"))
return 2;
else if (month.equalsIgnoreCase("March"))
return 3;
else if (month.equalsIgnoreCase("April"))
return 4;
else if (month.equalsIgnoreCase("May"))
return 5;
else if (month.equalsIgnoreCase("June"))
return 6;
else if (month.equalsIgnoreCase("July"))
return 7;
else if (month.equalsIgnoreCase("August"))
return 8;
else if (month.equalsIgnoreCase("September"))
return 9;
else if (month.equalsIgnoreCase("October"))
return 10;
else if (month.equalsIgnoreCase("November"))
return 11;
else if (month.equalsIgnoreCase("December"))
return 12;
else
{
System.out.println("FATAL ERROR"); System.exit(0); return 0;
}
}
}
======================================
package practicethis;
public class Second
{
public static void main(String[] args)
{
First date =new First();
int year=2005;
date.setDate(6,17,year);
date.writeOutput();
date.readInput();
date.writeOutput();
}
}
======================================
public class First
{
private String month;
private int day;
private int year;
public void writeOutput()
{
System.out.println(year+"/"+month+"/"+day);
}
public void readInput()
{
String StringYear = JOptionPane.showInputDialog("Enter year");
year = Integer.parseInt(StringYear);
month = JOptionPane.showInputDialog("Enter month");
String StringDay = JOptionPane.showInputDialog("Enter day");
day = Integer.parseInt(StringDay);
}
public void setDate(int month, int day, int year)
{
this.day = day;
this.year = year;
this.month = monthString(month);
}
public String monthString(int month)
{
switch (month)
{
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
default:
System.exit(0);
return "Eorror";
}
}
public int getDay()
{ return day; }
public int getYear()
{ return year; }
public int getmonth()
{
if (month.equalsIgnoreCase("January"))
return 1;
else if (month.equalsIgnoreCase("February"))
return 2;
else if (month.equalsIgnoreCase("March"))
return 3;
else if (month.equalsIgnoreCase("April"))
return 4;
else if (month.equalsIgnoreCase("May"))
return 5;
else if (month.equalsIgnoreCase("June"))
return 6;
else if (month.equalsIgnoreCase("July"))
return 7;
else if (month.equalsIgnoreCase("August"))
return 8;
else if (month.equalsIgnoreCase("September"))
return 9;
else if (month.equalsIgnoreCase("October"))
return 10;
else if (month.equalsIgnoreCase("November"))
return 11;
else if (month.equalsIgnoreCase("December"))
return 12;
else
{
System.out.println("FATAL ERROR"); System.exit(0); return 0;
}
}
}
======================================
package practicethis;
public class Second
{
public static void main(String[] args)
{
First date =new First();
int year=2005;
date.setDate(6,17,year);
date.writeOutput();
date.readInput();
date.writeOutput();
}
}
======================================
"This"practice
package practicethis;import javax.swing.JOptionPane;
public class First
{
private String month;
private int day;
private int year;
public void writeOutput()
{
System.out.println(year+"/"+month+"/"+day);
}
public void readInput()
{
String StringYear = JOptionPane.showInputDialog("Enter year");
year = Integer.parseInt(StringYear);
month = JOptionPane.showInputDialog("Enter month");
String StringDay = JOptionPane.showInputDialog("Enter day");
day = Integer.parseInt(StringDay);
}
public void setDate(int month, int day, int year)
{
this.day = day; this.year = year; this.month = monthString(month);
}
public String monthString(int month)
{
switch (month)
{
case 1: return "January";
case 2: return "February";
case 3: return "March";
case 4: return "April";
case 5: return "May";
case 6: return "June";
case 7: return "July";
case 8: return "August";
case 9: return "September";
case 10: return "October";
case 11: return "November";
case 12: return "December";
default: System.exit(0);
return "Eorror";
}
}
public int getDay() { return day; }
public int getYear() { return year; }
public int getmonth()
{ if (month.equalsIgnoreCase("January")) return 1;
else if (month.equalsIgnoreCase("February")) return 2;
else if (month.equalsIgnoreCase("March")) return 3;
else if (month.equalsIgnoreCase("April")) return 4;
else if (month.equalsIgnoreCase("May")) return 5;
else if (month.equalsIgnoreCase("June")) return 6;
else if (month.equalsIgnoreCase("July")) return 7;
else if (month.equalsIgnoreCase("August")) return 8;
else if (month.equalsIgnoreCase("September")) return 9;
else if (month.equalsIgnoreCase("October")) return 10;
else if (month.equalsIgnoreCase("November")) return 11;
else if (month.equalsIgnoreCase("December")) return 12;
else { System.out.println("FATAL ERROR");
System.exit(0);
return 0;
}
}
public boolean precedes(First otherDate)
{
return((year}
}
========
package practicethis;public class Second
{
public static void main(String[] args)
{
First date1= new First();
First date2= new First();
int year=2005;
date1.setDate(6,17,year);
date1.writeOutput();
date1.readInput();
date1.writeOutput();
date2.readInput();
date2.writeOutput();
if (date2.precedes(date1))
date2.writeOutput();
else
date1.writeOutput();
}
}
public class First
{
private String month;
private int day;
private int year;
public void writeOutput()
{
System.out.println(year+"/"+month+"/"+day);
}
public void readInput()
{
String StringYear = JOptionPane.showInputDialog("Enter year");
year = Integer.parseInt(StringYear);
month = JOptionPane.showInputDialog("Enter month");
String StringDay = JOptionPane.showInputDialog("Enter day");
day = Integer.parseInt(StringDay);
}
public void setDate(int month, int day, int year)
{
this.day = day; this.year = year; this.month = monthString(month);
}
public String monthString(int month)
{
switch (month)
{
case 1: return "January";
case 2: return "February";
case 3: return "March";
case 4: return "April";
case 5: return "May";
case 6: return "June";
case 7: return "July";
case 8: return "August";
case 9: return "September";
case 10: return "October";
case 11: return "November";
case 12: return "December";
default: System.exit(0);
return "Eorror";
}
}
public int getDay() { return day; }
public int getYear() { return year; }
public int getmonth()
{ if (month.equalsIgnoreCase("January")) return 1;
else if (month.equalsIgnoreCase("February")) return 2;
else if (month.equalsIgnoreCase("March")) return 3;
else if (month.equalsIgnoreCase("April")) return 4;
else if (month.equalsIgnoreCase("May")) return 5;
else if (month.equalsIgnoreCase("June")) return 6;
else if (month.equalsIgnoreCase("July")) return 7;
else if (month.equalsIgnoreCase("August")) return 8;
else if (month.equalsIgnoreCase("September")) return 9;
else if (month.equalsIgnoreCase("October")) return 10;
else if (month.equalsIgnoreCase("November")) return 11;
else if (month.equalsIgnoreCase("December")) return 12;
else { System.out.println("FATAL ERROR");
System.exit(0);
return 0;
}
}
public boolean precedes(First otherDate)
{
return((year
}
========
package practicethis;public class Second
{
public static void main(String[] args)
{
First date1= new First();
First date2= new First();
int year=2005;
date1.setDate(6,17,year);
date1.writeOutput();
date1.readInput();
date1.writeOutput();
date2.readInput();
date2.writeOutput();
if (date2.precedes(date1))
date2.writeOutput();
else
date1.writeOutput();
}
}