The pseudocode for Hanoi Tower is as follows:
solve(N, Src, Aux, Dst)
if N is 0 return
solve(N-1, Src, Dst, Aux)
Move N from Src to Dst
solve(N-1, Aux, Src, Dst)
Write the Java program based on the pseudocode in the above.
2008年12月26日 星期五
Lab Factorial
Lab Recursive Method
StaticMethod
2008年12月25日 星期四
2008年11月28日 星期五
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);
lab Fraction Addition
2008年11月20日 星期四
2008年11月7日 星期五
Homework 10-24-2008
1. 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.
2. Write a program to generate the following table of arithmetic expressions
1*1=1 1*2=2 1*3=3 ... 1*9=9
2*1=2 2*2=4 2*3=6 ... 2*9=19
...
9*1=9 9*2=18 9*3=27 ... 9*9=81
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.
2. Write a program to generate the following table of arithmetic expressions
1*1=1 1*2=2 1*3=3 ... 1*9=9
2*1=2 2*2=4 2*3=6 ... 2*9=19
...
9*1=9 9*2=18 9*3=27 ... 9*9=81
2008年10月24日 星期五
Lab Finding the max of a list of numbers
Lab: Tax Calculation
2008年10月23日 星期四
2008年10月3日 星期五
Lab Keyboard Input
Rewrite Display 2.6 using BufferedReader.
You need to import the following packages in the first place.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
Change
Scanner keyboard= new Scanner(System.in);
into
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
Note the Main method needs IOException handling as follows:
public static void main (String[] args) throws IOException
You need to import the following packages in the first place.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
Change
Scanner keyboard= new Scanner(System.in);
into
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
Note the Main method needs IOException handling as follows:
public static void main (String[] args) throws IOException
Homework 9-26-2008
Lab: String Processing
Do Project 5 of Chap. 1 on Page 56.
Write a program that starts with a line of text and then outputs that line of text with the first occurrence of "hate" changed to "love". For example, a possible sample output might be
The line of text to be changed is:
I hate you.
I have rephrased that line to read:
I love you.
Hint: You may consider use the methods: indexOf(A_String) and substring(Start, End) in your program.
Write a program that starts with a line of text and then outputs that line of text with the first occurrence of "hate" changed to "love". For example, a possible sample output might be
The line of text to be changed is:
I hate you.
I have rephrased that line to read:
I love you.
Hint: You may consider use the methods: indexOf(A_String) and substring(Start, End) in your program.
2008年9月26日 星期五
Lab: Simple Arithmetics 9/26
Lab: Simple Calculation 9/26
ex:
Suppose you are a landscape architect who charges $5,000 per mile to landscape a highway, and suppose you know the length in feet of the high way you are working on. Write a Java program to calculate the price you charge when the length is 6000 and 4000, respectively.
Hint: There are 5280 feet in a mile.
Suppose you are a landscape architect who charges $5,000 per mile to landscape a highway, and suppose you know the length in feet of the high way you are working on. Write a Java program to calculate the price you charge when the length is 6000 and 4000, respectively.
Hint: There are 5280 feet in a mile.
2008年9月25日 星期四
Homework 9/19/2008
1. Explain bytecode, JVM
The java compiler translates your program into a language called byte-code,which is the machine language for a fictitious computer.It is easy to translate this byte-code into the machine language of any particular computer.Each type of computer will have its own interpreter that translates and executes byte-code instructions.
Byte-code is the machine language for a fictitious computer called the Java Virtual Machine.
2. Explain class, object
Object-orirnted programming has its own specialized terminology.The object are called,appropriately enough,object.Object of the same kind are said to have the same type or,more often,are said to be in the same class.
3. Reading Assignments:
Read 1.1, 1.2, 1.3 of Textbook
4.1
4.2
4.3
The java compiler translates your program into a language called byte-code,which is the machine language for a fictitious computer.It is easy to translate this byte-code into the machine language of any particular computer.Each type of computer will have its own interpreter that translates and executes byte-code instructions.
Byte-code is the machine language for a fictitious computer called the Java Virtual Machine.
2. Explain class, object
Object-orirnted programming has its own specialized terminology.The object are called,appropriately enough,object.Object of the same kind are said to have the same type or,more often,are said to be in the same class.
3. Reading Assignments:
Read 1.1, 1.2, 1.3 of Textbook
4.1
4.2
4.3
2008年9月19日 星期五
訂閱:
文章 (Atom)