我在大一時對於c++並沒有學的很好,而大二時修資料結構更是修的十分痛苦,因為概念懂,但是程式碼就是背不起來,也看不懂(就算期中得了滿分還是死在期末考)。但是這學期修了java讓我這個程式苦手能夠稍微寫一些程式,或是看懂別人程式在做什麼,他的想法如何對我而言已經是十分大的進步了(有如阿公那輩的人學會用電腦那種感慨),而讓我覺得java最不一樣的地方在於他很直接,我缺什麼就補什麼,如a+bi我只要把相加的式子寫出來就完成一半了,我也可以偷懶不想一直打a+"+"+b+"i"而建構一個String去幫我偷懶。
除了看課本和聽老師講解之外,我室友也幫了我不少忙,像是之前要小考以及小考0分時,他很有耐性的教導我解決我的疑惑或是我不懂的地方,我認為,進部的相反並不是退步,而是什麼都不去做,我沒有因為不懂就放他去,也遇到願意幫我課後教學的人,我認為這是我除了學會java的初步課程之外最大的收穫。
2009年6月19日 星期五
2009年6月15日 星期一
Lab Hanoi Tower
Lab Recursive method
Lab Factorial
2009年6月8日 星期一
Homework 6-1-2009 Modular Sorting
Write a sort method which takes a double array as parameter
and returns the sorted array. Call this method in a main program.
Hint: The lab is a rewriting of Lab Sorting
to make the sorting procedure a reusable method.

-----.

----
package javaapplication8;
/**
*
* @author KFN
*/
public class Sort
{
/** Creates a new instance of Sort */
public Sort()
{
}
public static void sort( double[] score ) {
int index = 0;
double temp = 0.0;
for( index = score.length-1; index >-1 ; --index)
{
for (int j = 0; j < index; j++)
{
if(score[index] > score[j])
{
temp = score[j];
score[j] = score[index];
score[index] = temp;
}
}
}
}
}
---
package javaapplication8;
/**
*
* @author KFN
*
*/
import java.util.Scanner;
public class ArrayOfScores
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double[] score = new double[5];
int index;
double max, temp;
System.out.println("Enter 5 Scores");
score[0] = keyboard.nextDouble();
max = score[0];
for(index = 1; index < score.length; ++index)
score[index] = keyboard.nextDouble();
Sort.sort( score );
/*
Sort a = new Sort();
a.sort( score );
*/
System.out.println("The scores are" );
for(index = 0; index< score.length; index++)
System.out.println(score[index]);
and returns the sorted array. Call this method in a main program.
Hint: The lab is a rewriting of Lab Sorting
to make the sorting procedure a reusable method.
-----.
----
package javaapplication8;
/**
*
* @author KFN
*/
public class Sort
{
/** Creates a new instance of Sort */
public Sort()
{
}
public static void sort( double[] score ) {
int index = 0;
double temp = 0.0;
for( index = score.length-1; index >-1 ; --index)
{
for (int j = 0; j < index; j++)
{
if(score[index] > score[j])
{
temp = score[j];
score[j] = score[index];
score[index] = temp;
}
}
}
}
}
---
package javaapplication8;
/**
*
* @author KFN
*
*/
import java.util.Scanner;
public class ArrayOfScores
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double[] score = new double[5];
int index;
double max, temp;
System.out.println("Enter 5 Scores");
score[0] = keyboard.nextDouble();
max = score[0];
for(index = 1; index < score.length; ++index)
score[index] = keyboard.nextDouble();
Sort.sort( score );
/*
Sort a = new Sort();
a.sort( score );
*/
System.out.println("The scores are" );
for(index = 0; index< score.length; index++)
System.out.println(score[index]);
2009年6月1日 星期一
"Lab Array"
Study Display 6.1, and then write a program that can sort numbers in ascending order.
-----
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double[] score = new double[5];
int index;
double max, temp;
System.out.println("Enter 5 Scores");
score[0] = keyboard.nextDouble();
max = score[0];
for(index = 1; index <>
score[index] = keyboard.nextDouble();
for( index = score.length-1; index >-1 ; --index){
for (int j = 0; j <>
if(score[index] > score[j]){
temp = score[j];
score[j] = score[index];
score[index] = temp;
}
}
}
System.out.println("The scores are" );
for(index = 0; index<>
System.out.println(score[index]);
}
Lab: Static Method II
Define a Complex class with a static method for computing complex addition. Use (2+3i)*(4+5i) in your test.

public class ADT {
private int real, image ;
public ADT(){
}
public ADT(int real , int image) {
this.real = real;
this.image = image;
}
public ADT mult(ADT ADT2){
ADT ans = new ADT(0,0) ;
ans.real = this.real * ADT2.real + this.image * ADT2.image;
ans.image = this.image * ADT2.real + this.real * ADT2.image;
return ans;
}
public String toString(){
return real + "+" + image + "i";
}
}
-----
public class StaticMethodII {
public static void main(String[] args) {
ADT f1, f2;
f1 = new ADT(2,3);
f2 = new ADT(4,5);
System.out.println("f1 = " + f1.toString());
System.out.println("f2 = " + f2.toString());
System.out.println("f1 x f2 = " + f1.mult(f2).toString());
}
2009年5月25日 星期一
Lab Magic Parking Tower
A parking tower is out of order someday. If you park a Benz, you will end up with a Torben. Write a program to simulate this scenario. First create a class called CarParked which has a static method called outOfOrder. Name an object called yourCar, which happens to be a Benz. Your program should contain a class called CarParked and a test program called CarParkedDemo which test the method by CarParked.outOfOrder(yourCar).
Hint: You may study Display 5.14 to get some ideas.
Hint: You may study Display 5.14 to get some ideas.
-----
public class CarParked {
private String car; //p275 3 name改car
public CarParked( String car )
{
this.car = car;
}
public CarParked()
{
car = " No car yet. ";
}
void setCar(String car)
{
this.car = car;
}
public static CarParked outOfOrder( CarParked car )
{
car.setCar( "Torben" ) ;
return car ;
}
public String toString()
{
return car;
}
}
----
public class CarParkedDemo {
public static void main (String args[]) {
CarParked car = new CarParked( "Benz" ) ;
System.out.println("進入停車場的車為" + car);
CarParked.outOfOrder( car );
System.out.println("離開時的車為" + car);
}
}
2009年5月11日 星期一
Lab Static Method
Define a Complex class with a static method for computing complex addition. Use (2+3i)+(4+5i) in your test.
-------------
public class Complex {
int real;
int image;
public Complex()
{}
public Complex( int real , int image)
{
this.real = real;
this.image = image;
}
public static Complex add(Complex a, Complex b) {
Complex ans = new Complex();
ans.real = a.real + b.real;
ans.image = a.image + b.image;
return ans;
}
public String toString() {
return real + "+" + image + "i";
}
}
---------------
public class LabStaticMethod {
public static void main (String args[]) {
Complex f1, f2;
f1 = new Complex(2, 3);
f2 = new Complex(4, 5);
System.out.println("f1 = " + f1.toString());
System.out.println("f2 = " + f2.toString());
System.out.println("f1 + f2 = " + Complex.add(f1, f2).toString());
}
}
Lab Math methods
Compute the following mathematical functions.
Math.round(3.2)
Math.round(3.6)
Math.floor(3.2)
Math.floor(3.6)
Math.ceil(3.2)
Math.ceil(3.6)
Math.round(3.2)
Math.round(3.6)
Math.floor(3.2)
Math.floor(3.6)
Math.ceil(3.2)
Math.ceil(3.6)
----
public class LabMath {
/**
* @param args
*/
public static void main(String args[]) {
System.out.println("Math.round(3.2) = " + Math.round(3.2) );
System.out.println("Math.round(3.6) = " + Math.round(3.6) );
System.out.println("Math.floor(3.2) = " + Math.floor(3.2) );
System.out.println("Math.floor(3.6) = " + Math.floor(3.6) );
System.out.println("Math.ceil(3.2) = " + Math.ceil(3.2) );
System.out.println("Math.ceil(3.2) = " + Math.ceil(3.6) );
// TODO 自動產生方法 Stub
}
}
Lab Finding the max of three numbers
Write a static method that computes the maximum of three float numbers.
--------
import java.util.Scanner;
public class Maximum {
public static void main (String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("請輸入三個數字比大小");
float a = scan.nextFloat();
float b = scan.nextFloat();
float c = scan.nextFloat();
System.out.println("最大者為"+Maximum.Max(a, b, c));
}
public static float Max( float a,float b,float c )
{
if( a > b && a > c)
return a;
else if( b > c && b >a )
return b;
else
return c;
}
}
HOMEWORK2
/*
* Tempurate.java
*
* Created on 2009年5月11日, 下午 2:41
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package homework;
/**
*
* @author KFN
*/
public class Temperature {
float degree ;
String scale ;
/** Creates a new instance of Tempurate */
public Temperature() {
degree = 0 ;
scale = "C";
}
public Temperature( float degree ) {
this.degree = degree;
scale = "C";
}
public Temperature( String scale ) {
degree = 0 ;
this.scale = scale ;
}
public Temperature( float degree, String scale ) {
this.degree = degree;
this.scale = scale ;
}
public float Change( String type ){
if ( this.scale.equals( type ) )
return degree; // 兩個種類相同的話直接傳入
else {
if ( type.equals( "F" ) )
return ( ( degree / 5 ) * 9 ) + 32 ;
else if( type.equals( "C" ) )
return 5 * ( degree - 32 ) / 9 ;
else
return 0;
}
}
public String toString(){
return this.degree + " degree " + this.scale ;
}
public boolean Equals( Temperature other ) {
if ( this.scale.equals( other.scale ) ) {
if ( this.degree == other.degree )
return true;
else
return false;
} else {
if ( this.degree == other.Change(this.scale) )
return true;
else
return false;
}
}
public boolean Greater( Temperature other ) {
if ( this.scale.equals( other.scale ) ) {
if ( this.degree > other.degree )
return true;
else
return false;
} else {
if ( this.degree > other.Change( this.scale ) )
return true;
else
return false;
}
}
public boolean Less( Temperature other ) {
if ( this.scale.equals( other.scale ) ) {
if ( this.degree <>
return true;
else
return false;
} else {
if ( this.degree <>
return true;
else
return false;
}
}
}
------------------------
/*
* Main.java
*
* Created on 2009年5月11日, 上午 11:40
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package homework;
/**
*
* @author KFN
*/
import java.util.Scanner;
public class Main {
/** Creates a new instance of Main */
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
/*
Scanner scan =new Scanner(System.in);
System.out.println("請輸入溫度");
float n = scan.nextFloat();
System.out.println("請選擇攝氏'C'或是華氏'F'");
String scale = scan.next();
if(scale.equals("C"))
{
float changeF = ((n/5)*9)+32;
System.out.println("您輸入攝氏"+n+"度");
System.out.println("轉換為華氏為"+changeF+"度");
}
else if(scale.equals("F"))
{
float changeC = 5*(n-32)/9 ;
System.out.println("您輸入華氏"+n+"度");
System.out.println("轉換為攝氏為"+changeC+"度");
}
else
{
System.out.println("請選擇攝氏'C'或是華氏'F'");
}
*/
Temperature t1 = new Temperature( 100, "C");
Temperature t2 = new Temperature( 212, "F" );
Temperature t3 = new Temperature( "C" );
Temperature t4 = new Temperature( "F" );
// question 1.
System.out.println("t1 " + t1.toString() );
System.out.println("t2 " + t2.toString() );
System.out.println("t3 " + t3.toString() );
System.out.println("t4 " + t4.toString() );
System.out.println("");
//question 2.
if ( t1.Equals( t2 ) )
System.out.println("t1 is equals to t2 " );
else
System.out.println("t1 is not equals t2 " );
if ( t2.Greater( t4 ) )
System.out.println("t2 is greater than t4 " );
else
System.out.println("t2 is not greater than t4 " );
if ( t2.Less( t4 ) )
System.out.println("t2 is Less than t4 " );
else
System.out.println("t2 is not Less than t4 " );
// TODO code application logic here
}
}
2009年5月4日 星期一
Lab Method Overloading
依據Class definition 3,修改程式使其接受三種setDate
date1.setDate(1,2,2008);
date2.setDate("February",2, 2008);
date3.setDate(2008);


date1.setDate(1,2,2008);
date2.setDate("February",2, 2008);
date3.setDate(2008);
Lab Java Constructor
Write constructors in the lab Fraction Addition.


------程式碼------
public class FractionAddtion {
public static void main(String[] args)
{
Fraction f1 = new Fraction(1 ,2);
Fraction f2 = new Fraction(1 ,3);
System.out.println("f1 = " + f1.outputstring() + "\nf2 = " + f2.outputstring());
System.out.println("f1 + f2 = "+ f1.add(f2).outputstring());
}
}
---------------------------
public class Fraction {
private int numerator;
private int denominator;
public void number( int numerator, int denominator)
{
this.numerator = numerator;
this.denominator = denominator;
}
public String outputstring() {
return (numerator + "/" + denominator); //分數的表示形式
}
public Fraction(int x, int y) {
this.numerator = x;
this.denominator = y;
}
public Fraction add(Fraction Fraction2)
{
Fraction countOfTemp = new Fraction(numerator ,denominator);
countOfTemp.numerator = numerator*Fraction2.denominator + denominator*Fraction2.numerator;
countOfTemp.denominator = denominator*Fraction2.denominator;
//交叉相乘
return countOfTemp;
}
}
------程式碼------
public class FractionAddtion {
public static void main(String[] args)
{
Fraction f1 = new Fraction(1 ,2);
Fraction f2 = new Fraction(1 ,3);
System.out.println("f1 = " + f1.outputstring() + "\nf2 = " + f2.outputstring());
System.out.println("f1 + f2 = "+ f1.add(f2).outputstring());
}
}
---------------------------
public class Fraction {
private int numerator;
private int denominator;
public void number( int numerator, int denominator)
{
this.numerator = numerator;
this.denominator = denominator;
}
public String outputstring() {
return (numerator + "/" + denominator); //分數的表示形式
}
public Fraction(int x, int y) {
this.numerator = x;
this.denominator = y;
}
public Fraction add(Fraction Fraction2)
{
Fraction countOfTemp = new Fraction(numerator ,denominator);
countOfTemp.numerator = numerator*Fraction2.denominator + denominator*Fraction2.numerator;
countOfTemp.denominator = denominator*Fraction2.denominator;
//交叉相乘
return countOfTemp;
}
}
homework
/*
* Fraction.java
*
* Created on 2009年5月4日, 下午 5:18
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package fraction;
/**
*
* @author KFN
*/
public class Fraction
{
private int numerator;
private int denominator;
public void number( int numerator, int denominator)
{
this.numerator = numerator;
this.denominator = denominator;
}
/**
* Creates a new instance of Fraction
*/
public String outputstring()
{
return (numerator + "/" + denominator); //分數的表示形式
}
public Fraction multiply(Fraction Fraction2)
{
Fraction countOfTemp = new Fraction();
countOfTemp.numerator = numerator*Fraction2.numerator;
countOfTemp.denominator = denominator*Fraction2.denominator;
int d = 0;
int a = countOfTemp.numerator;
int b = countOfTemp.denominator;
int c = 0;
do {
c = a % b;
int temp = a%b;
a = b;
b = temp;
d = a;
} while ( c != 0 );// end while
countOfTemp.numerator = countOfTemp.numerator / d;
countOfTemp.denominator = countOfTemp.denominator / d;
return countOfTemp;
}
public Fraction()
{
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Fraction f1 = new Fraction();
Fraction f2 = new Fraction();
f1.number(1, 2);
f2.number(1, 3);
System.out.println("f1 = " + f1.outputstring() + "\nf2 = " + f2.outputstring());
System.out.println("f1 * f2 = "+ f1.multiply(f2).outputstring());
// TODO code application logic here
}
}
* Fraction.java
*
* Created on 2009年5月4日, 下午 5:18
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package fraction;
/**
*
* @author KFN
*/
public class Fraction
{
private int numerator;
private int denominator;
public void number( int numerator, int denominator)
{
this.numerator = numerator;
this.denominator = denominator;
}
/**
* Creates a new instance of Fraction
*/
public String outputstring()
{
return (numerator + "/" + denominator); //分數的表示形式
}
public Fraction multiply(Fraction Fraction2)
{
Fraction countOfTemp = new Fraction();
countOfTemp.numerator = numerator*Fraction2.numerator;
countOfTemp.denominator = denominator*Fraction2.denominator;
int d = 0;
int a = countOfTemp.numerator;
int b = countOfTemp.denominator;
int c = 0;
do {
c = a % b;
int temp = a%b;
a = b;
b = temp;
d = a;
} while ( c != 0 );// end while
countOfTemp.numerator = countOfTemp.numerator / d;
countOfTemp.denominator = countOfTemp.denominator / d;
return countOfTemp;
}
public Fraction()
{
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Fraction f1 = new Fraction();
Fraction f2 = new Fraction();
f1.number(1, 2);
f2.number(1, 3);
System.out.println("f1 = " + f1.outputstring() + "\nf2 = " + f2.outputstring());
System.out.println("f1 * f2 = "+ f1.multiply(f2).outputstring());
// TODO code application logic here
}
}
Homework 4-13-2009 Fraction Multiplication
Write a program to implement a method that can multiply 2 fractions. You will implement a class called Fraction consisting of a numerator and a denominator. The multiplication of
2 fractions should be equal to a fraction.
Use 1/2 * 1/3 as the test.
Hints:
Fraction f1, f2;
f1.multiply(f2);



改成1/2 * 2/3

due date: 4/27/2009
沒有在期限內做出來
卡在通分卡太久
又死撐著不去看別人怎麼寫
不算藉口的藉口...
2 fractions should be equal to a fraction.
Use 1/2 * 1/3 as the test.
Hints:
Fraction f1, f2;
f1.multiply(f2);
改成1/2 * 2/3
due date: 4/27/2009
沒有在期限內做出來
卡在通分卡太久
又死撐著不去看別人怎麼寫
不算藉口的藉口...
2009年4月17日 星期五
Lab Firefox Accessibility Extension
Use Firefox Accessibility Extension to check the accessibility of three sites that you visit most.
Report the summary of all the errors and warnings for each site.

中原大學:http://itouch.cycu.edu.tw/

阿榮福利味:http://azo-freeware.blogspot.com/

google:http://www.google.com.tw
Report the summary of all the errors and warnings for each site.
中原大學:http://itouch.cycu.edu.tw/
阿榮福利味:http://azo-freeware.blogspot.com/
google:http://www.google.com.tw
2009年4月13日 星期一
LAB
public class Fraction {
private int numerator;
private int denominator;
public void number( int numerator, int denominator)
{
this.numerator = numerator; //把這method的區域變數numerator給予這個類別內宣告的numerator
this.denominator = denominator; //this:代表使用中的類別,也可以使用在變數名稱有重複或易於混淆時
}
public String outputstring() {
return (numerator + "/" + denominator); //分數的表示形式
}
public boolean equal(Fraction Fraction2)
{
if(numerator*Fraction2.denominator == denominator*Fraction2.numerator)
{
return true;
}
else
{
return false;
}
}
public static void main(String[] args)
{
Fraction f1 = new Fraction();
Fraction f2 = new Fraction();
f1.number(1, 2);
f2.number(2, 4);
System.out.println("f1 = " + f1.outputstring() + "\nf2 = " + f2.outputstring());
//System.out.println("f1 + f2 = "+ f1.add(f2).outputstring());
System.out.println(f1.equal(f2));
}
}
lab Fraction equality test
Write a program to implement a method that can check whether 2 fractions are equal. You will implement a class called Fraction consisting of a numerator and a denominator. The equality test of 2 fractions should return a boolean value.
Use the following as the tests.
* 1/2, 2/4
* 5/6, 6/7
Hints:
Fraction f1, f2;
f1.equals(f2);
Use the following as the tests.
* 1/2, 2/4
* 5/6, 6/7
Hints:
Fraction f1, f2;
f1.equals(f2);
訂閱:
意見 (Atom)