2008年6月22日 星期日

Lab Magic Parking Tower(補交)

sorry 老師~
我以為我已經上傳了
所以現在才補交...





















2008年6月18日 星期三

期末報告

書名:JVAV HOW TO PROGRAM –Sixth Edition-
作者:H.M.Deitel & P.J.Deitel
出版社:PEARSON
出版日期:2005
習題4.38:
一、為什麼選擇這個習題:
因為與老師之前所出的考試題目很像,可是 之前都是紙上撰寫,所以想試試看用程式寫出來。
二、學到的概念:
1. 如何計算階層。
2. 如何使用for迴圈。
3. 如何計算次方。
三、說明:
a)寫出一個程式可以讀入非負數的整數,並計算階層,最後顯示。












b)計算自然對數
















c)計算
















///////////////////////////////////////////////////////////////////

書名:Introduction to JVAV PROGRAMING –Fifth Edition-
作者:Y.Daniel Liang
出版社:PEARSON
出版日期:2005
習題3.2:
一、為什麼選擇這個習題:
我們之前學的只是單純比較三者中最大的,所以我這次想比較三個數字的大小,並且進而排序出來。
二、學到的概念:
1. 如何比較三個數字的大小。
2. 如何排序。
三、說明:
撰寫一個程式可以輸入三個數字,經過比較後,將數字排序,並以num1<=num2<=num3的順序顯示出來。

2008年6月15日 星期日

2008年6月2日 星期一

Lab Java Constructor

如果直接執行下列程式
Date birthday = new Date("Jan",1,2000);
birthday.Date("Feb",1,2000);
birthday.setDate("Feb",1,2000);
birthday=new Date("Mar",1,2000);
會有錯誤
原因為birthday.Date("Feb",1,2000);
建構子不可以這樣呼叫
他必須跟在new後面











如果刪除那一行則可以正常運作
如下






2008年6月1日 星期日

2008年5月26日 星期一

Lab Overloading

import java.util.Scanner;
public class LabOverloading
{
private String mouth;
private int day;
private int year;

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

public void setDate(String mouthString,int day,int year)
{
if (dateOK(mouthString,day,year))
{
this.mouth=mouthString;
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 mouthInt,int dayInt,int yearInt )
{
return ((mouthInt>=1)&&(mouthInt<=12)&&(dayInt>=1)&&(dayInt<=31)&&(yearInt>=1000)&&(yearInt<=9999));
}

private boolean dateOK(String mouthString,int dayInt,int yearInt )
{
return (mouthOK(mouthString)&&(dayInt>=1)&&(dayInt<=31)&&(yearInt>=1000)&&(yearInt<=9999));
}

private boolean mouthOK(String mouth)
{
return (mouth.equals("January")mouth.equals("February")mouth.equals("March")mouth.equals("April")mouth.equals("May")mouth.equals("June")mouth.equals("July")mouth.equals("August")mouth.equals("September")mouth.equals("October")mouth.equals("November")mouth.equals("Deceber"));
}

public void readInput()
{
boolean tryAgain=true;
Scanner keyboard=new Scanner(System.in);
while(tryAgain)
{
System.out.println("Enter mouth ,day and year.");
System.out.println("Do not use a comma.");
String mouthInput= keyboard.next();
int dayInput= keyboard.nextInt();
int yearInput= keyboard.nextInt();
if (dateOK(mouthInput,dayInput,yearInput))
{
setDate(mouthInput,dayInput,yearInput);
tryAgain=false;
}
else System.out.println("Illegal date. Reenter input");
}
}

public String mouthString(int mouthNumber)
{
switch(mouthNumber)
{
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 "Deceber";
default: System.out.println("Fatal Error");
System.exit(0); return "Error";
}
}

public String toString()

{
return year+"/"+mouth+"/"+day;
}


public static void main(String[] args)
{
LabOverloading date1=new LabOverloading(),
date2=new LabOverloading(),
date3=new LabOverloading();

date1.setDate(1,2,2008);
date2.setDate("February",2,2008);
date3.setDate(2008);

System.out.println(date1);
System.out.println(date2);
System.out.println(date3);
}
}



Lab ADT, accessor, mutator

public class Complex
{
private int real;
private int imaginary;

public void setComplex(int real,int imaginary)
{
this.real=real;
this.imaginary=imaginary;
}

public String getComplex()
{
return (real+"+"+imaginary+"i");
}

public Complex addComplex(Complex newComplex)
{
Complex result=new Complex();
result.real=real+newComplex.real;
result.imaginary=imaginary+newComplex.imaginary;
return result;
}

}


public class LabComplexClass
{
public static void main(String[] args)
{
Complex data1= new Complex(),
data2= new Complex();

data1.setComplex(2,3);
data2.setComplex(4,5);

System.out.println(data1.addComplex(data2).getComplex());

//Mutator
data1.setComplex(5, 6);
System.out.println(data1.addComplex(data2).getComplex());
}

}












2008年5月19日 星期一

lab Fraction equality test

public class Fraction
{
private int mom;
private int son;

public void setFraction(int son ,int mom)
{
this.mom=mom;
this.son=son;
}
public Fraction add (Fraction newFraction)
{
Fraction result=new Fraction();
result.mom=newFraction.mom*mom;
result.son=newFraction.mom*son+mom*newFraction.son;
return result;
}
public String equals (Fraction newFraction)
{
if((float)son/(float)mom==(float)newFraction.son/(float)newFraction.mom)
{
return "they are equal";
}
else
{
return "they are not equal";
}
}

public String toString()
{
return this.son+"/"+this.mom;
}

}

public class labFractionAddition
{
public static void main(String[] args)
{
Fraction f1=new Fraction(),
f2=new Fraction();

f1.setFraction(5,6);
f2.setFraction(6,7);
System.out.println(f1.equals (f2).toString());
}

}






















lab Fraction Addition

public class Fraction
{
private int mom;
private int son;

public void setFraction(int son ,int mom)
{
this.mom=mom;
this.son=son;
}
public Fraction add (Fraction newFraction)
{
Fraction result=new Fraction();
result.mom=newFraction.mom*mom;
result.son=newFraction.mom*son+mom*newFraction.son;
return result;
}
public String equals (Fraction newFraction)
{
if((float)son/(float)mom==(float)newFraction.son/(float)newFraction.mom)
{
return "they are equal";
}
else
{
return "they are not equal";
}
}

public String toString()
{
return this.son+"/"+this.mom;
}

}



public class labFractionAddition
{
public static void main(String[] args)
{
Fraction f1=new Fraction(),
f2=new Fraction();

f1.setFraction(1,2);
f2.setFraction(1,3);
System.out.println(f1.add (f2).toString());
}

}























2008年4月28日 星期一

Class Definition 3






















應該做的修正:

改成

this.month=month

this.day=day

this.year=year


Lab counter

public class Counter
{
private int number;

public void reset()
{
number=0;
}
public void inc()
{
number=number+1;
}
public void dec()
{
number=number-1;
}
public void output()
{
System.out.println(number);
}
}


public class CounterMain
{
public static void main(String[] args)
{
Counter count;
count = new Counter();
count.reset();
count.inc();
count.inc();
count.dec();
count.output();
}
}

結果:













2008年4月14日 星期一

Average income by gender (補交)

import java.util.Scanner;

public class AverageIncomeByGender
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter the sex and income");

double woman=0,man=0;
int f=0,m=0;
String key="y";
do
{
String sex = keyboard.next();
double income=0;
if(sex.equals("m"))
{
income = keyboard.nextDouble();
man=man+income;
m++;
}
else if (sex.equals("f"))
{
income = keyboard.nextDouble();
woman=woman+income;
f++;
}
else
{
System.out.println(f+" women's average income is "+(woman/f)+"元");
System.out.println(m+" men's average income is "+(man/m)+"元");
System.out.println("Do you have another data to input?(y/n)");
key=keyboard.next();
}
}
while(key.equals("y"));
}
}

結果:











p.s.忘記交了~sorry~

Display4.1+ makeItNewYear

public class DateFirstTry
{
public String month;
public int day;
public int year;
public void writeOutput()
{
System.out.println(month+" "+day+","+year);
}
public void makeItNewYear()
{
month = "January";
day = 1 ;
}
}


public class DateFirstTryDemo
{
public static void main(String[] args)
{
DateFirstTry date1,date2;
date1 = new DateFirstTry();
date2 = new DateFirstTry();
date1.month = "December";
date1.day = 31;
date1.year = 2007;
System.out.println("date1:");
date1.writeOutput();

date1.makeItNewYear();
System.out.println("new date1:");
date1.writeOutput();

date2.month = "July";
date2.day = 4;
date2.year = 1776;
System.out.println("date2:");
date2.writeOutput();

date2.makeItNewYear();
System.out.println("new date2:");
date2.writeOutput();
}
}

結果:

Display4.1

public class DateFirstTry
{
public String month;
public int day;
public int year;
public void writeOutput()
{
System.out.println(month+" "+day+","+year);
}
}

public class DateFirstTryDemo
{
public static void main(String[] args)
{
DateFirstTry date1,date2;
date1 = new DateFirstTry();
date2 = new DateFirstTry();
date1.month = "December";
date1.day = 31;
date1.year = 2007;
System.out.println("date1:");
date1.writeOutput();

date2.month = "July";
date2.day = 4;
date2.year = 1776;
System.out.println("date2:");
date2.writeOutput();
}
}

結果

2008年4月7日 星期一

Lab 9*9

public class Lab99
{
public static void main(String[] args)
{
for(int i=1;i<10;i++)
{
for(int j=1;j<10;j++)
{
System.out.print(i+"*"+j+"="+(i*j)+" ");
}
System.out.println();
}
}
}

結果:


Lab Fibonacci numbers

import java.util.Scanner;

public class Homework0407
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter the limit number:");

float first,second,temp,max,per;
first=1;
second=1;
max=keyboard.nextInt();

while(second<=max)
{
per=second/first;
System.out.println(second+"/"+first+"="+per);
temp=first+second;
first=second;
second=temp;
}
}
}

結果:

2008年3月27日 星期四

Homework 3-24-2008

1. Based on your study of Display 3.8, write a code to find the max and min of a list of number.For example, given 1,3,5, and9, the max is 9 and the min is 1.Your program should be able to process a list of any length.

程式:
import java.util.Scanner;

public class Homework0324
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter a list of nonnegative number:");
System.out.println("Mark the end with a negative number!");
System.out.println("I will show the max and min number!");

double number,max,min;
number=keyboard.nextDouble();
max=number;
min=number;

while (number>=0)
{
if(number>=max)
max=number;
if(number<=min)
min=number;
number=keyboard.nextDouble();
}
System.out.println("the max of three number is : "+max);
System.out.println("the min of three number is : "+min);
}
}

結果:










2. Write a program to generate the series 1, 1, 2, 3, 5, 8, 13, ...The series has a property that the third number is the sum of the first and second numbers. For example, 2=1+1, 3=1+2, and 5=2+3.


程式:
import java.util.Scanner;

public class Homework0324_2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter the limit number:");

int first,second,temp,max;

first=1;
second=1;
max=keyboard.nextInt();

System.out.print(first+" ");
System.out.print(second+" ");

while(second<=max)
{
temp=first+second;
first=second;
second=temp;
System.out.print(temp+" ");
}
}
}

結果:

2008年3月24日 星期一

Lab: Tax Calculation

import java.util.Scanner;

public class TaxCalculation
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter net income:");

double netIncome = keyboard.nextInt();
double tax;

if (netIncome<=370000)
tax=netIncome*0.06;
else if((netIncome>370000)&&(netIncome<=990000))
tax=netIncome*0.13-25900;
else if ((netIncome>990000)&&(netIncome<=1980000))
tax=netIncome*0.21-105100;
else if ((netIncome>1980000)&&(netIncome<=3720000))
tax=netIncome*0.30-283300;
else if (netIncome>3720000)
tax=netIncome*0.40-655300;
else
tax=0.0;

System.out.print("總共需要");
System.out.printf("%10.2f",tax);
System.out.println("元");
}
}

結果:
1000000的稅




2000000的稅

Lab Finding the max of three numbers

import java.util.Scanner;

public class MaxOfThreeNumbers
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter three number:");

int firstNumber = keyboard.nextInt();
int secondNumber = keyboard.nextInt();
int thirdNumber = keyboard.nextInt();
int temp=firstNumber;

if(secondNumber>=temp)
{temp=secondNumber;}
if(thirdNumber>=temp)
{temp=thirdNumber;}

System.out.println("the max of three number is : "+temp);
}
}

結果:

2008年3月17日 星期一

Homework 3-17-2008_Project 3 of Chap. 2.

import java.util.Scanner;

public class Homework20080317Part3
{
public static void main(String[] args)
{
System.out.println("please enter two integers.");
Scanner keyboard = new Scanner(System.in);
int first=keyboard.nextInt();
int second=keyboard.nextInt();

System.out.println("sum :"+(first+second));
System.out.println("difference :"+(first-second));
System.out.println("product :"+(first*second));
}
}


結果:

Homework 3-17-2008_Project 1 of Chap. 2.

import java.util.Scanner;

public class Homework0317Part1
{
public static void main(String[] args)
{
System.out.println("please enter a number.");
Scanner keyboard = new Scanner(System.in);

double n=keyboard.nextDouble();
double myGuess=n/2;
double r=0.0;

for(int i=0;i<5;i++)
{
r=n/myGuess;
myGuess=(myGuess+r)/2;
}

System.out.print("my guess is ");
System.out.printf("%10.2f",myGuess);
System.out.println();
System.out.print("the real one is ");
System.out.printf("%10.2f",Math.sqrt(n));
}
}

結果:
1.使用較小的數字(誤差較小)










2.使用較大的數字(誤差較大)

Lab Keyboard input

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class LabKeyboardinput
{
public static void main(String[] args)throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the number of pods followed by");
System.out.println("the number of peas in the pod:");
String numberOfPods = keyboard.readLine();
String peasPerPod = keyboard.readLine();

double totalNumberOfPeas = Double.parseDouble (numberOfPods)*Double.parseDouble (peasPerPod);

System.out.print(numberOfPods+"pods and");
System.out.println(peasPerPod+"peas per pod.");
System.out.println("The total number of peas ="+totalNumberOfPeas);
}
}

結果:

Lab Scanner

import java.util.Scanner;

public class ScannerDemo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter the number of pods followed by");
System.out.println("the number of peas in the pod:");
int numberOfPods = keyboard.nextInt();
int peasPerPod = keyboard.nextInt();
int totalNumberOfPeas = numberOfPods*peasPerPod;

System.out.print(numberOfPods+"pods and");
System.out.println(peasPerPod+"peas per pod.");
System.out.println("The total number of peas ="+totalNumberOfPeas);
}
}

2008年3月10日 星期一

Homework 3-10-2008: String Processing

public class StringProcessing
{
public static void main(String[] args)
{
String original,newly,temp;
original="I hate you.";
int index;
index=original.indexOf("hate");
newly=original.substring(0,index)+"love"+original.substring(index+"hate".length(),original.length());
System.out.println("The line of text to be changed is:");
System.out.println(original);
System.out.println("I have rephrased that line to read:");
System.out.println(newly);
}
}





Lab: Simple Calculation

public class SimpleCalculation
{
public static void main(String[] args)
{
double result6;
result6=6000/5280.0;
System.out.print("6000 feet 為");
System.out.printf("%10.2f",result6);
System.out.println("mile");
System.out.print("6000 feet 總共需要");
System.out.printf("%10.2f",5000*result6);
System.out.println("元");

double result4;
result4=4000/5280.0;
System.out.print("4000 feet 為");
System.out.printf("%10.2f",result4);
System.out.println("mile");
System.out.print("4000 feet 總共需要");
System.out.printf("%10.2f",5000*result4);
System.out.println("元");
}
}


2008年3月9日 星期日

Homework 3-3-2008

1. Explain bytecode, JVM
bytecode 是給 JVM(Java Virtual Machine) 下指令的一種虛擬機器碼,也就是說,JVM 是負責把Java原始碼編譯成為bytecode,為bytecode 的解譯程式。雖然 JVM 可能因平台而異,但是所有的 JVM 都能執行 bytecode ,所以不會被綁死在特定的硬體上。

2. Explain class, object
class是一種"類別"(抽象), 而object則為"物件"(實體)。
java將每個程式視為一class, 包含許多object, 物件執行的動作就是method。java實際寫法如下:
public class (name of class)
{
object.method();
}

3. Reading Assignments:
Read 1.1, 1.2, 1.3 of Textbook
4.1 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (i++);
Print i;
Ans: 2, 4, 3






4.2 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (++i);
Print i;
Ans: 2, 6, 3






4.3 Write a Java program as follows:
Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;
Ans: 3.5, 3.5

Lab 2 Java for Scientific Computation

阿斯巴甜的每日安全劑量:每公斤體重50毫克。
小白鼠平均體重:20g








參考資料:
http://tw.search.yahoo.com/
http://tw.knowledge.yahoo.com/question/?qid=1405102414901

2008年3月3日 星期一

Lab Get familiar with JBuilder

Do Display 1.1

1.開啟新的專案
2.開啟新的類別
3.執行java應用程式
4.結果如下:



2008年3月1日 星期六

HOMEWORK 2-25-2008

List at least 5 applications of Java. You must provide the references you used. We recommend Google Search engine.
1.手機遊戲
2.網路遊戲、動畫...應用在網際網路上的程式語言
3.資料庫
4.金融證卷
5.汽車資訊監控系統:http://cgi.taiwan.cnet.com/jpc/sp2-10.htm


Watch The Inside Story (Video), write your words on the development and inventor of Java.
Java,是一種物件導向的程式語言,它是由Sun Microsystems的James Gosling等人在1990年初開發的。它最初被命名為Oak,用來設定小型家電的程式語言,解決電器的控制和通訊問題。但是由於智慧型家電的市場需求沒有預期的高,最後被迫放棄。後來隨著網際網路的發展,Sun看到了Oak在電腦網路上的廣闊應用前景,於是改造了Oak,在1995年5月以「Java」的名稱正式發佈。Java伴隨著網際網路的迅猛發展而發展,逐漸成為重要的網路程式語言。
Java一開始是流行使用在瀏覽器中的,受到網景公司的重視,甚至成立了Java業務集團,但是幾年後它在瀏覽器的地位被逐步侵蝕。同時,Java也受到微軟的排擠,他們決定在新版本的IE和Windows中不再有Java平臺。看起來,未來的發展似乎是一片灰暗...但是近年來,Java傾被用在撰寫線上的一些小遊戲,還有資訊網的伺服器端以及手機設備上,特別是以手機設備上最被為重視,讓Java又開始流行起來。
參考文獻:http://zh.wikipedia.org/&再經過我吸收消化整理

2008年2月25日 星期一

這是我的第一次喔@////@

哈哈哈~
不要想歪喔~~
這是我第一次申請部落格拉~~
~^^~

我叫做劉怡旻(移民)
目前就讀醫工系
就快要從中原畢業了...@@...
突然感傷了起來
但是也不想要再多留一年
所以...
很高興認識大家
p.1