2007-01-12

Lab Hanoi Tower












Lab Squared Array













2007-01-08

Lab Sorting

package untitled1;

public class Sorting
{


public static void main(String[] args)
{
double[] sorting = {45.2,87.5,50.2,33.3,22.2};
double[] a = new double[5];
int i,j,s=0;
double max;
for(i=0;i<5;i++) j="0;">
s++;
}
a[s]=sorting[i];
s=0;

}

for(i=0;i<5;i++) System.out.println(a[i]+","); }
}


2006-12-25

Lab Static Method, Part II

Lab Static Method

2006-12-11

12/4作業

<<overloading>>
package who_is_angela;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class DateSixthTry
{
private String month;
private int day;
private int year;

public void setDate(int monthInt, int day, int year)
{
if (dateOK(monthInt, day, year))
{
this.month = monthString(monthInt);
this.day = day;
this.year = year;
}
else {
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(String monthString, int day, int year) {
if (dateOK(monthString, day, year)) {
this.month = monthString;
this.day = day;
this.year = year;
}
else {
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(int year) {
setDate(1, 1, year);
}

private boolean dateOK(int monthInt, int dayInt, int yearInt) {
return ( (monthInt >= 1) &&amp;amp;amp;amp;amp;amp; (monthInt <= 12) && (dayInt >= 1) && (dayInt <= 31) && (yearInt >= 1000) && (yearInt <= 9999)); } private boolean dateOK(String monthString, int dayInt, int yearInt) { return (monthOK(monthString) &&amp;amp;amp;amp;amp;amp; (dayInt >= 1) && (dayInt <= 31) && (yearInt >= 1000) && (yearInt <= 9999)); } private boolean monthOK(String month) { return (month.equals("January") || month.equals("February") || month.equals("March") || month.equals("April") || month.equals("May") || month.equals("June") || month.equals("July") || month.equals("August") || month.equals("September") || month.equals("October") || month.equals("November") || month.equals("December")); } public void readInput() throws IOException { boolean tryAgain = true; BufferedReader keyboard = new BufferedReader(new InputStreamReader(System. in)); while (tryAgain) { System.out.println("Enter month, day, and year."); System.out.println("Do not use a comma."); String monthInput = keyboard.readLine(); int dayInput = keyboard.read(); int yearInput = keyboard.read(); if (dateOK(monthInput, dayInput, yearInput)) { setDate(monthInput, dayInput, yearInput); tryAgain = false; } else System.out.println("Illegal date. Reenter input."); } } public void writeOutput() { System.out.println(month + " " + day + ", " + year); } public void setMonth(int month) { if ( (month <= 0) || (month > 12)) {
System.out.println("Fatal Error");
System.exit(0);
}
else
this.month = monthString(month);
}

public void setMonth(String month) {
this.month = month;
}

public void setDay(int day) {
if ( (day <= 0) || (day > 31)) {
System.out.println("Fatal Error");
System.exit(0);
}
else
this.day = day;
}

public void setYear(int year) {
if ( (year <> 9999)) {
System.out.println("Fatal Error");
System.exit(0);
}
else
this.year = year;
}

public boolean equals(DateSixthTry otherDate) {
return ( (month.equalsIgnoreCase(otherDate.month))
&&amp;amp;amp;amp;amp;amp; (day == otherDate.day) && (year == otherDate.year));
}

public boolean precedes(DateSixthTry otherDate) {
return ( (year < year ="=" year ="=" date1 =" new" date2 =" new" date3 =" new" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/5813/3816/1600/925535/%3F%3F%3F%3F%3F%3F%3F%3F%3F7.jpg">









.................................................................................................................................
<>






































12/4 Lab Java Constructor
































































2006-12-04

Lab Class Definitions III













2006-11-27




























2006-11-06

第六次作業

1.
import java.io.*;
public class Untitled1
{public static void main(String[] args)throws IOException
{
int x,n,i;
double c,d,sum=1;
String a,b;
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter x of exp(x)");
a=keyboard.readLine();
x=Integer.parseInt(a);
System.out.println("Please enter n of n!");
b=keyboard.readLine();
n=Integer.parseInt(b);
c=d=1;
for(i=1;i<=n;i++) { c*=x; d*=i; sum+=(c/d); } System.out.println("The sum of exp(x)= "+sum); } }






























2.List 5 examples of Fibonacci numbers in nature.
1.兔,牛與蜂的家庭樹
2.Fibonacci Rectangles and Shell Spirals
3.花瓣
4.種子
5.松毬果

lab

public class Untitled1
{ public static void main(String[] args)
{
double a=1;
double b=1;
double result;
for(int x=1; x<=97; x++) { result=a+b; System.out.println(result + " "+(double)b/a); a=b; b=result; } }
}
結果:
2.0 1.0
3.0 2.0
5.0 1.5
8.0 1.6666666666666667
13.0 1.6
21.0 1.625
34.0 1.6153846153846154
55.0 1.619047619047619
89.0 1.6176470588235294
144.0 1.6181818181818182
233.0 1.6179775280898876
377.0 1.6180555555555556
610.0 1.6180257510729614
987.0 1.6180371352785146
1597.0 1.618032786885246
2584.0 1.618034447821682
4181.0 1.6180338134001253
6765.0 1.618034055727554
10946.0 1.6180339631667064
17711.0 1.6180339985218033
28657.0 1.618033985017358
46368.0 1.6180339901755971
75025.0 1.618033988205325
121393.0 1.618033988957902
196418.0 1.6180339886704431
317811.0 1.6180339887802426
514229.0 1.618033988738303
832040.0 1.6180339887543225
1346269.0 1.6180339887482036
2178309.0 1.6180339887505408
3524578.0 1.6180339887496482
5702887.0 1.618033988749989
9227465.0 1.618033988749859
1.4930352E7 1.6180339887499087
2.4157817E7 1.6180339887498896
3.9088169E7 1.618033988749897
6.3245986E7 1.618033988749894
1.02334155E8 1.6180339887498951
1.65580141E8 1.6180339887498947
2.67914296E8 1.618033988749895
4.33494437E8 1.618033988749895
7.01408733E8 1.618033988749895
1.13490317E9 1.618033988749895
1.836311903E9 1.618033988749895
2.971215073E9 1.618033988749895
4.807526976E9 1.618033988749895
7.778742049E9 1.618033988749895
1.2586269025E10 1.618033988749895
2.0365011074E10 1.618033988749895
3.2951280099E10 1.618033988749895
5.3316291173E10 1.618033988749895
8.6267571272E10 1.618033988749895
1.39583862445E11 1.618033988749895
2.25851433717E11 1.618033988749895
3.65435296162E11 1.618033988749895
5.91286729879E11 1.618033988749895
9.56722026041E11 1.618033988749895
1.54800875592E12 1.618033988749895
2.504730781961E12 1.618033988749895
4.052739537881E12 1.618033988749895
6.557470319842E12 1.618033988749895
1.0610209857723E13 1.618033988749895
1.7167680177565E13 1.618033988749895
2.7777890035288E13 1.618033988749895
4.4945570212853E13 1.618033988749895
7.2723460248141E13 1.618033988749895
1.17669030460994E14 1.618033988749895
1.90392490709135E14 1.618033988749895
3.08061521170129E14 1.618033988749895
4.98454011879264E14 1.618033988749895
8.06515533049393E14 1.618033988749895
1.304969544928657E15 1.618033988749895
2.11148507797805E15 1.618033988749895
3.416454622906707E15 1.618033988749895
5.527939700884757E15 1.618033988749895
8.944394323791464E15 1.618033988749895
1.447233402467622E16 1.618033988749895
2.3416728348467684E16 1.6180339887498947
3.7889062373143904E16 1.618033988749895
6.1305790721611584E16 1.618033988749895
9.9194853094755488E16 1.6180339887498947
1.60500643816367072E17 1.618033988749895
2.5969549691112256E17 1.618033988749895
4.2019614072748966E17 1.618033988749895
6.7989163763861222E17 1.618033988749895
1.10008777836610189E18 1.618033988749895
1.77997941600471398E18 1.618033988749895
2.880067194370816E18 1.6180339887498947
4.6600466103755305E18 1.618033988749895
7.5401138047463465E18 1.618033988749895
1.2200160415121877E19 1.618033988749895
1.9740274219868226E19 1.618033988749895
3.19404346349901E19 1.618033988749895
5.168070885485833E19 1.6180339887498947
8.362114348984843E19 1.618033988749895
1.3530185234470676E20 1.618033988749895
2.189229958345552E20 1.618033988749895

第5次作業