4/29/2011

Do Inspect in Eclipse


Right-click on the class => Select imports







4/28/2011

Greatest Common Divisor

話說這回的作業是上研究所課程以來第三次的程式作業,內容只有這一小部份跟之前不一樣,卻大大加長了我寫爪哇作業的時間,只能說接下來的這一個半月還得跟爪哇做好朋友,爪哇~我要每天多認識你一點一點呀!



這次作業主要是請玩家輸入兩個數字,然後求這兩個入字的最大公因數。

// import class
import java.util.Scanner;

public class CH04PR43
{
public static void main(String[] args)
{
// Welcome the user to come to the program
System.out.println("Greatest Common Divisor Finder");
System.out.println();

Scanner sc = new Scanner(System.in);
String choice = "y";

while (choice.equalsIgnoreCase("y"))
{
// Get numbers from the user
System.out.print("Enter first number:  ");
int firstNumber = sc.nextInt();
System.out.print("Enter second number:  ");
int secondNumber = sc.nextInt();

// do algorithm
int temp = 0;
while (secondNumber!=0)
{
temp = firstNumber % secondNumber;
firstNumber = secondNumber;
secondNumber = temp;
}
System.out.println("Greatest Common Divisor: " + firstNumber);
System.out.println();

// see if the user want to continue
System.out.print("Continue? (y/n): ");
choice = sc.next();
System.out.println();
     }
}
}

4/21/2011

Start to Learn Access

我這學期修的System Analysis這門課用的其中一本課本是Gary B.(Gary B. Shelly) Shelly等人合著的Microsoft Office Access 2007: Complete Concepts and Techniques。

老師上課只教系統分析的理論部份,還有Visible Analyst Workbench實做,不會教Access,但是作業跟考試仍包含Access,所以得自己在家裡認真看這本教科書。




課本有豐富的圖解,一一說明操作步驟。在各個圖解的左方也會有Q&A,有一些是問很基本的問題,非常適合我這種對電腦陌生的學習者使用。

以前買過其他中文的Access書籍,也許是以前比較混,對電腦軟體比較不熟悉,總覺得Access書籍像無字天書,有看沒有懂。反倒是使用了這本課本後有點愛上他了,因為我真的看懂Access在做什麼。所以建議初學Access的朋友,如果英文程度還可以,可以試著讀讀這本書,學習效果不錯。










老師的作業也是從Access每個章節的最後面有不同的練習題(Lab)出的,老師會指定其中一題,又為了避免學生互相幫忙(抄襲上個term的同學的作業),所以老師會挑選不同的習題給同學做。

習題內容不難,但習題的描述方式可能跟課文不太一樣,但是只要有讀課本,知道題目問的是什麼,就寫得出作業。



Travel Time Calculator

這是我上禮拜的Java作業,滿分十分,老師給了九分。

以下是我寫的code

// import class
import java.util.Scanner;

public class CH03PR32
{
public static void main(String[] args)
{
// Welcome the user to come to the program
System.out.println("Welcome to the Travel Time Calculator");
System.out.println();

Scanner sc = new Scanner(System.in);
String choice = "y";
while (choice.equalsIgnoreCase("y"))
{
// get input numbers from the user
System.out.print("Enter miles:          ");
double miles = sc.nextDouble();
System.out.print("Enter miles per hour: ");
double milesPerHour = sc.nextDouble();
System.out.println();

// show the estimated travel time
System.out.println("Estimated travel time");

// calculate estimated hours and minutes
double hours = miles / milesPerHour ;
hours = Math.floor(hours);
int estimatedhours = (int)hours;
double minutes = 60 * (miles % milesPerHour) / milesPerHour ;
minutes = Math.floor(minutes);
int estimatedminutes = (int)minutes;

System.out.println("Hours:    " + estimatedhours);
System.out.println("Minutes:  " + estimatedminutes);
System.out.println();

// see if the user wants to continue
System.out.print("Continue? (y/n): ");
choice = sc.next(); // refer to Scanner
System.out.println();
}

}
}

4/09/2011

Differences between Access 2007 and 2010

The textbook is Access 2007 but the teacher recommended students to install version 2010. Sometime when I follow steps of the textbook, I could not find some icons or buttons. Thus, I would like to have some notes about the difference between Access 2007 and 2010.

In Access 2007, when we need to change data properties, we should click on Office button -> Manager -> Database properties -> choose the file

In Access 2010, click File -> Info -> view and edit database properties


we can type our name, class name or other info in the window

4/07/2011

Number letter grade converter

The Java assignment this week is number letter grades converter, which means to make numerical grades into letter grades. For example, 90-100 points may refer to A, 80-89 refers to B and so on.

I read first two chapters and took two hours to do my homework. I will post my code here after professor editing my homework.

In Double, decimal number (ex. 87.5) can refer to whole number (ex. 87). However, in Int, whole number (ex. 87) doesn't refer to decimal number (ex. 87.5). Therefore, I can not use Int here.

My code are as follows,


package chapt02;

import java.util.Scanner;

public class LetterGradeConverter // create class and no space between each word
{
      public static void main(String[] args)
      {
            // welcome the user to come to the program
            System.out.println("Welcome to the Letter Grade Converter"); // do not forget ;
            System.out.println(); // print blank line
           
            // create a Scanner object name sc
            Scanner sc = new Scanner(System.in); // S is uppercase letter
           
            // perform letter grade converter until choice is not "y" or "Y"
            String choice = "y"; // do not forget ;
            while (choice.equalsIgnoreCase("y")) // not case-sensitive
            {
                  // get the number grades from the user
                  System.out.print("Enter numerical grades: ");
                  double numbergrade = sc.nextDouble(); // D in nextDouble is uppercase

                  char lettergrade = 0;
                 
                  // convert number grades to letter grades
                  if (numbergrade >= 88)
                        lettergrade = 'A';
                  else if (numbergrade >= 80)
                        lettergrade = 'B';
                  else if (numbergrade >= 67)
                        lettergrade = 'C';
                else if (numbergrade >= 60)
                        lettergrade = 'D'; // do not forget ; to end the code
                else
                        lettergrade = 'F';
                  System.out.println("Letter grade: " + lettergrade); // do not forget ; to end the code
                  System.out.println();
                 
                  // see if the user wants to continue
                  System.out.print("Continue? (y/n): ");
                  choice = sc.next(); // refer to Scanner object
                  System.out.println();
                 
            }
           
      }

}


And the teacher's comment are as follows.
In order to import the application successfully, it was first necessary to change both the package statement and the name of the class. Please use package and class names specified for assignments. After those adjustments, the application ran fine and produced correct results for the different tests I tried.