2009年3月23日 星期一

Homework 3-16-2009

1. Project 7 of Chap. 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

2009年3月16日 星期一

Lab Finding the max of a list of numbers

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.



主要概念是創造一個arrary,並宣告一個變數令array會往前跑(arrary[0]變arrary[1],在這裡宣告可使用arrary[0]~[99]),也就是將每次key入的數字儲存在這個arrary中(從0開始放)

而while是繼續執行的條件
.
.
.
最後就是大ㄧ有敎過的泡沫排序法...

Lab Finding the max of a list of numbers

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.




Lab Finding the max of three numbers

Write a program to decide the max number of the three input number.




 
import java.util.Scanner;

public class LAB02 {    
    public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double n[] = new double[100];
int count = 0;
System.out.println( "請輸入數字,輸入\"-1\"為停止") ;
                while( count <>
                  n[count] = keyboard.nextDouble();
                  count++;  
                }
                // 讀入INPUT數字
                
                for( int i = 0 ; i <>
                  for( int j = i+1 ; j <>
                    if( n[i] > n[j] ) {
                      double temp = n[i];
                      n[i] = n[j];
                      n[j] = temp;
                    }
               // 上面是網路上COPY的泡沫排序法 
               System.out.println( "min: "+n[0] + " & Max: " + n[count-1] ) ;
                
    }
    
}

Lab Tax Calculation

Study Display 3.1. Based on the income tax rate in Taiwan,
calculate the income tax of a person whose annual income is 1,000,000 or 2,000,000.





import java.util.Scanner;

public class IncomeTax {
public static void main(String[] args)
{      
Scanner keyboard = new Scanner(System.in);
double netIncome = 0.0,tax = 0.0;
System.out.println("請輸入所得淨額");
netIncome = keyboard.nextDouble();
if(netIncome <= 370000)
tax = netIncome*0.06;
else if((netIncome >= 370001)&&(netIncome <= 990000))
tax = netIncome*0.13-25900;
else if ((netIncome>=990001)&&(netIncome<=1980000))
tax = netIncome*0.21-105100;
else if ((netIncome>=1980001)&&(netIncome<=3720000))
tax = netIncome*0.3-283300;
else if( netIncome >= 3720001 )
   tax = netIncome*0.4-655300;
System.out.printf("應繳所得稅為"+ tax + "元" );
}  
}


2009年3月15日 星期日

Homework 3-9-2009

1. Do Project 4 in Chapter 2

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
//new class為配置一個記憶體空間
System.out.println("Enter the distance of the commute in miles.");
double a = keyboard.nextDouble();
System.out.println("Enter the feul consumption rate in miles per gallon.");
double b = keyboard.nextDouble();
System.out.println("Enter the price of a gallon.");
double c = keyboard.nextDouble();
System.out.println("The cost of the commute is \n" + ( a / b ) * c );
// TODO code application logic here
}
2. Do Project 5 in Chapter 2

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the purchase price of an item.");
double P = keyboard.nextDouble();
System.out.println("Enter the exceptd number of years of service.");
double Y = keyboard.nextDouble();
System.out.println("Enter the expected salvage value.");
double S = keyboard.nextDouble();
System.out.println("The yearly depreciation for the item is \n" + (P - S ) / Y );
// TODO code application logic here
}
3. Do Project 6, in Chapter 2

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the amount of artificial sweetener needed to kill a mouse.(g)");
double S = keyboard.nextDouble();
System.out.println("Enter the weight of the mouse.(g)");
double m = keyboard.nextDouble();
System.out.println("Enter the desired weight of the dieter.(g)");
double M = keyboard.nextDouble();
System.out.println("The diet soda pop it is possible to dink is\n" + (M / m ) * S *1000 + "ml or" + (M / m ) * S + "L");
// TODO code application logic here
}
4. Do Project 7, in Chapter 2

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the price of item \n (from 25 cents to a dollar, in 5-cent increments)");
int item = keyboard.nextInt();
System.out.println("You buoght an item for"+ item +"cents and gave me a dollar");

int q = (100 - item)/25;
int n = ((100 - item)%25)/5;

System.out.println("So your change is \n"+ q +" quarters and "+ n +" nickels.");

// TODO code application logic here
}

2009年3月9日 星期一

Lab Keyboard precessing


Project 3 of Chap. 2.