2008年3月24日 星期一

Lab: Tax Calculation



為 1,000,000時 ↓

為 2,000,000時↓






import java.util.Scanner;

public class work
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
double netIncome, tax;

System.out.println("Enter net income. \n" + "Do not include a dollar sign or commas");
netIncome = keyboard.nextDouble();

if (netIncome <= 370000) tax = 0.06*netIncome; else if (netIncome > 370000 && netIncome <= 990000) tax = 0.13*netIncome-25900; else if (netIncome > 990000 && netIncome <= 1980000) tax = 0.21*netIncome-105100; else if (netIncome > 1980000 && netIncome <= 3720000) tax = (0.3*netIncome-283300); else tax = 0.4*netIncome-655300; System.out.println("Tax of = " + tax); } }

2008年3月23日 星期日

Homework 3-17 2007











import java.util.Scanner;

public class project
{
public static void main(String[] args)
{
System.out.print("type the number you want:");
Scanner keyboard = new Scanner (System.in);
double h = keyboard.nextDouble();
double guess = h / 2;
double n;
for (int i=0 ;i <= 10 ; i++) { n = h/guess; guess =(guess+n)/2; } System.out.println(h+ "開根號:"+guess); }

}



import java.util.Scanner;


public class project2
{
public static void main(String[] args)
{
System.out.println("輸入兩個整數");
Scanner input = new Scanner (System.in);
int a = input.nextInt();
int b = input.nextInt();
int c = a + b;
int d = a - b;
int e = a * b;
System.out.println(a+"+" +b+"="+ c);
System.out.println(a+"-" +b+"="+ d);
System.out.println(a+"*" +b+"="+e);
}

}


Lab Keyboard input


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


public class ScannerDemo
{
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 if peas in a pods");


String numberOfPods = keyboard.readLine();
String peasPerPod = keyboard.readLine();

int a,b;
a = Integer.parseInt(numberOfPods);
b = Integer.parseInt(peasPerPod);

int totalNumberOfPeas = a * b;

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

2008年3月17日 星期一

Lab Scanner


import java.util.Scanner;

public class df
{
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 a pod");
int numberOfPods = keyboard.nextInt();
int peasPerPod = keyboard.nextInt();

int totalNumberOfPeas = numberOfPods*peasPerPod;

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

}

2008年3月10日 星期一

Lab: String Processing


package gf;


public class S1

{ public static void main(String[] args)

{

int a; int b; String part_a = "", part_b = "";

String sentence = "I hate you";

String keyword = "love";

sentence.indexOf("hate");

a = sentence.indexOf("hate");

b = a + 4; part_a= sentence.substring(0,a);

part_b= sentence.substring(b);

System.out.println(part_a+keyword+part_b);

}

}


Lab: Simple Calculation





package gf;
public class S1 {

public static void main(String[] args)

{

double a = 4000/(double)5280;

double b = 6000/(double)5280;

double c = a*5000;

double d = b*5000;

System.out.println("製作4000英里需要的錢為"+c);

System.out.println("製作6000英里需要的錢為"+d);

}

}

2008年3月6日 星期四

Homework 3-3-2008



1. Explain bytecode, JVM
bytecode:是一種中間語言,可以稱為Java byte-code 或是簡稱為 byte-code,當初之所以要發展的原因是為了讓這語言能在不同的機械中運作,而它具有許多的特性:很小, 很容易上手, 而且並不貴等因素,而他負責編譯機械語言,讓使用者變於撰寫

JVM:JVM是一個虛構出來的電腦,並且屏蔽了原有的處理系統的指令,讓JAVA可以有自己的CPU等相關指令,使JAVA可以在任何平台都可以修改
2. Explain class, object

class: A Java program is divided into smaller parts called classes, and normally each class definition is in a separate file and is compiled separately.




object: To make sure it is clear which program we mean, we call the input program, which in our case will be a Java program, the source program, or source code, and call the translated low-level-language program that the compiler produces the object program, or object code.




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;











public class I


{

public static void main(String[] args)



{
int i;/*虛告一個i的函數*/
i = 2;
System.out.println(i);/*輸出i值*/
System.out.println(2*(i++));/*輸出2乘與i++後的值*/
System.out.println(i);

}


}



4.2 Write a Java program as follows:



Let i=2;



Print i;



Print 2 * (++i);



Print i;




package homework;



public class I


{


public static void main(String[] args)


{


int i;/*虛告一個i的函數*/


i = 2;


System.out.println(i);/*輸出i值*/


System.out.println(2*(++i));/*輸出2乘與++i後的值*/


System.out.println(i);


}


}


4.3 Write a Java program as follows:


Let m=7, n=2;


Print (double) m/n;


Print m/ (double)n;


public class I


{


public static void main(String[] args)


{


int m,n;/*虛告m和n的函數*/


m = 7; n = 2;


System.out.println((double)m/n);


System.out.println(m/(double)n);


}


}