顯示具有 《JAVA》Homework 標籤的文章。 顯示所有文章
顯示具有 《JAVA》Homework 標籤的文章。 顯示所有文章

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.





2009年5月11日 星期一

Homework 5-4-2009

Do Project 7 of Chapter 4

Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degress if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius).


degreesC = 5 ( degreesF - 32 ) / 9
degreesF = ( 9 ( degreesC ) / 5 ) + 32








*結果:

=>最後跑完結果似乎有點出錯,C、F轉換的數據錯誤了。不知道哪裡出了問題,還要再仔細看看。

2009年5月4日 星期一

Homework 4-27-2009

Do project 2 of Chapter 4.



題目:
Define a class called Fraction. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator and the denominator. Also include a member function that returns the value of numerator or denominator as a double. Include an additional member function that output the value of the fraction reduced to lowest terms (e.g., instead of outputting 20/60 the method should output 1/3). This will require finding the greatest common divisor for the numerator and denominator, then dividing both by that number. Embed your class in a test program










=> 利用最大公因數相除後,可得到分數之最簡化。大致上的方法都相同,都看幾次後就可顯的較容易上手了。

2009年4月27日 星期一

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 of2 fractions should be equal to a fraction.
Use 1/2 * 1/3 as the test.

Hints:
Fraction f1, f2;
f1.multiply(f2);




2009年3月31日 星期二

Homework 3-30-2009: counter

Define a class called Counter whose objects count things. An object of this class records a count that is a nonnegative integer. Include methods to set the counter to 0, to increase the count by 1, and to decrease the count by 1. Include an accessor method that returns the current count value and a method that outputs the count to the screen. Write a program to test


counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();




2009年3月30日 星期一

Homework: 3/23/2009

Write a program to calculate average income by gender based on the following data, where F stands for female and M for male.

F 62,000
M 25,000
F 38,000
F 43,000
M 65,000
M 120,000
F 80,000
M 30,100

You should be able to allow users to type in a whole line such as F 80,000 followed by next line M 30,100.











2009年3月18日 星期三

Homework 3-16-2009

1. Project 7 of Chap. 3

n=1

n=10




n=50


n=100




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












2009年3月14日 星期六

Homework 3-9-2009

1. Do Project 4 in Chapter 2





2. Do Project 5 in Chapter 2






3. Do Project 6, in Chapter 2




4. Do Project 7, in Chapter 2










2009年3月9日 星期一

Homework 3-2-2009

1. Write a program that can reverse the order of an input string. For example, if you input "ab", it will output "ba". If you input "abcdefg", it should return "gfedcba".







2. Write a program that can print names alternatively. The names are in the format of "First Name + Last Name" or "Last Name, First Name". For example, if you input "Walt Savitch", your program will output "Savitch, Walt". If you input "Savitch, Walt", your program will output "Walt Savitch".







2009年3月1日 星期日

Homework 2-23-2009

1. 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.











2. Write a Java program that displays the results of the expressions 15/4, 4/15, 15%4, 4%15. Calculate the values of these expressions manually to verify that the displayed values are correct.

2009年2月22日 星期日

Homework 1


1. 兩年前寫了幾篇文章,探討為什麼要學寫程式。參考之後,也描述一下你對寫程式的看法。

   對於現在科技社會而言,電腦已是大眾必備的工具。而許多作業系統也已由人力轉為電腦代勞,而電腦的運作勢必就要靠人類寫一套程式才可執行工作,程式在電腦世界裡已是不可或缺的東西。不管在未來需不需要寫到程式,但如文章裡所提到的,寫程式是一種邏輯思考設計的訓練,可以訓練清晰頭腦,對未來也是很有幫助的!希望我能學會所有的程式語言~加油!




2. 參考課本第一章,回答以下問題

a. What is Java Virtual Machine and Java Bytecode?


   Java虛擬機Java Virtual Machine)是一個虛構出來的計算機,通過在實際的計算機上模擬模擬各種計算機功能來實現的。Java虛擬機有自己完善的硬體架構,如處理器堆疊暫存器等,還具有相應的指令系統。JVM屏蔽了與具體作業系統平台相關的信息,使得Java程序只需生成在Java虛擬機上運行的目標代碼(位元組碼),就可以在多種平台上不加修改地運行。


[引用:http://zh.wikipedia.org/w/index.php?title=Java_Virtual_Machine&variant=zh-tw]



b. Explain Java's feature "Write once, run anywhere.

 意思是JAVA程式跨越任何平台都可以執行。