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);


}


}

2008年3月3日 星期一

Lab 2 Java for Scientific Computation



public class JAVA {
public static void main (String[] args)
{
int weight_of_mouse = 400;/*各個的體重*/
int weight_of_human = 75000;
int weight_of_strating = 75000;
int weight_of_desired = 70000;
double ratio_of_sweetener_to_soda = 0.001;
double sweetener_to_kill_a_mouse = 1;
double ratio_of_sweetener_to_mouse;
double sweetener_to_human;
double diet_soda_drink_in_safely_range;
System.out.println("某人想要減重所需減肥可樂的量"+"但是過多的代糖會導致死亡!!!");/*輸出"某人想要減重所需減肥可樂的量"+"但是過多的代糖會導致死亡!!!"*/
System.out.println("如果某人"+weight_of_strating/1000+"Kg");/*如果某人xx公斤*/
System.out.println("使用此方法所減的重量");
System.out.println("如果我們知道"+sweetener_to_kill_a_mouse+" g 可殺死1隻"+""+weight_of_mouse+"克的老鼠");
ratio_of_sweetener_to_mouse = sweetener_to_kill_a_mouse / weight_of_mouse;
sweetener_to_human = weight_of_human * ratio_of_sweetener_to_mouse;
diet_soda_drink_in_safely_range = sweetener_to_human / ratio_of_sweetener_to_soda;
System.out.println("一個人所能喝的量為"+sweetener_to_human+" g 的"+ "人工代糖");
System.out.println("如果一個成年人想使用減肥可樂,那他的量不應該超過:"+diet_soda_drink_in_safely_range/1000 + "公升");


}

}

Lab Get familiar with JBuilder



public class firstprogram
{ public static void main (String[]args)
{
System.out.println("hello!! world!!");
System.out.println("welcome to JAVA");
System.out.println("Let's demonstrate a caculation");
int answer;
answer = 3 + 2;
System.out.println("3 PLUS 2 answer:"+ answer);
}
}

2008年3月2日 星期日

Homework 2-25-2008

1. Watch The Inside Story (Video), write your words on the development and inventor of Java.

Java,是一種物件導向的程式語言,它是由Sun Microsystems的James Gosling等人在1990年初開發的。它最初被命名為Oak,用來設定小型家電的程式語言,解決電器的控制和通訊問題。但是由於智慧型家電的市場需求沒有預期的高,最後被迫放棄。後來隨著網際網路的發展,Sun看到了Oak在電腦網路上的廣闊應用前景,於是改造了Oak,在1995年5月以「Java」的名稱正式發佈。Java伴隨著網際網路的迅猛發展而發展,逐漸成為重要的網路程式語言。

2. List at least 5 applications of Java. You must provide the references you used. We recommend Google Search engine.
1.手機遊戲
2.某些應用程式
3.IC卡
4.網頁
5.電腦系統