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
}

沒有留言:

張貼留言