Week 6: Linear Lists - Simulated Pointer Representation
6주차 선형 목록 : 포인터 시뮬레이트 표현법.
Since we have midterm exams next week, I will give you an extremely easy assignment. I belive that this takes only a couple of hours.
다음주에 시험이니까 매우쉬운 과제를 줄께, 난 이 과제가 2시간 정도 걸릴거라고 생각해.

Section 7.7 introduces the concepts of the equivalent relationship and union set.
7.7장에서 동등관계와 공용체의 컨셉을 소개했다.

Just type in the example code to find the union set, and write a program that test the example code.
책에서 공용체를 찾는 코드를 그대로 쳐라, 그리고 그것을 테스트하는 예제 코드를 만들어 보아라.

What you will turn in is a PDF file that contains the test code, screen shots of the test program in execution, and brief explanation of your understanding on the concepts of the equivalent relationship and union set.
니가 할일은 테스트 코드와, 실행 스크린샷, 그리고 니가 이 컨셉을 이해했다는것을 증명하는 설명을 PDF에 담아 제출하는것이다.

'생활 > 데이터 스트럭쳐' 카테고리의 다른 글

Week 7: Array and Matrices  (0) 2010.05.03
Data Structure 6번째 HW  (0) 2010.04.15
Data Structure 5번째 HW(내맘대로 분석)  (0) 2010.04.10
Data Structure 5번째 HW(번역)  (0) 2010.04.10
Data Structure 5번째 HW  (0) 2010.04.10

Week 6: Linear Lists - Simulated Pointer Representation

Since we have midterm exams next week, I will give you an extremely easy assignment. I belive that this takes only a couple of hours.

Section 7.7 introduces the concepts of the equivalent relationship and union set. Just type in the example code to find the union set, and write a program that test the example code. What you will turn in is a PDF file that contains the test code, screen shots of the test program in execution, and brief explanation of your understanding on the concepts of the equivalent relationship and union set.

'생활 > 데이터 스트럭쳐' 카테고리의 다른 글

Week 7: Array and Matrices  (0) 2010.05.03
Data Structure 6번째 HW(번역)  (0) 2010.04.15
Data Structure 5번째 HW(내맘대로 분석)  (0) 2010.04.10
Data Structure 5번째 HW(번역)  (0) 2010.04.10
Data Structure 5번째 HW  (0) 2010.04.10

Week 5: Linear Lists - Linked Representation

1. Write code for the class ChainWithSortMethods.

ChainWithSortMethods 클래스를 만들어라


This class is a subclass of Chain and it includes the number method insertionSort, which uses insertion sort to reorder the chain elements into nondecreasing order.
이 클래스는 Chain을 상속받는다. 그리고 인자의 크기를 오름차순 정렬하는 insertionSort 메소드를 갖고있다.

=========================================================

위 두가지의 조건에 맞추려면 Chain은 그냥 저자 홈페이지에서 갖고오고, 나머지는 그냥 쓰면 되겠다.


Do not create new nodes or delete old ones.

노드를 새로 생성하거나 삭제하지 마라.


=========================================================

헐,,, 이건 좀 문제다,,,,, 링크만 수정하는 방식으로 가야겠네,,,


a) What is the worst-case time complexity of your method? How much time does your method need if the elements are already in sorted order?

최악의 경우 에 시간복잡도는 얼마인가?

이미 정리되어 있는 경우에는 시간이 얼마나 걸리는가?


b) Test the correctness of your method by compiling and then executing the code. Use your own test data (any programs with any data are allowed).

측정의 정확성을 위해 컴파일링을 하고 실행해봐라.

너만의 테스트 데이터를 만들어라

'생활 > 데이터 스트럭쳐' 카테고리의 다른 글

Data Structure 6번째 HW(번역)  (0) 2010.04.15
Data Structure 6번째 HW  (0) 2010.04.15
Data Structure 5번째 HW(번역)  (0) 2010.04.10
Data Structure 5번째 HW  (0) 2010.04.10
Data Structure 4번째 HW(번역)  (0) 2010.04.01

Week 5: Linear Lists - Linked Representation

1. Write code for the class ChainWithSortMethods.

ChainWithSortMethods 클래스를 만들어라


This class is a subclass of Chain and it includes the number method insertionSort, which uses insertion sort to reorder the chain elements into nondecreasing order.
이 클래스는 Chain을 상속받는다. 그리고 인자의 크기를 오름차순 정렬하는 insertionSort 메소드를 갖고있다.
Do not create new nodes or delete old ones.

노드를 새로 생성하거나 삭제하지 마라.


a) What is the worst-case time complexity of your method? How much time does your method need if the elements are already in sorted order?

최악의 경우 에 시간복잡도는 얼마인가?

이미 정리되어 있는 경우에는 시간이 얼마나 걸리는가?


b) Test the correctness of your method by compiling and then executing the code. Use your own test data (any programs with any data are allowed).

측정의 정확성을 위해 컴파일링을 하고 실행해봐라.

너만의 테스트 데이터를 만들어라

'생활 > 데이터 스트럭쳐' 카테고리의 다른 글

Data Structure 6번째 HW  (0) 2010.04.15
Data Structure 5번째 HW(내맘대로 분석)  (0) 2010.04.10
Data Structure 5번째 HW  (0) 2010.04.10
Data Structure 4번째 HW(번역)  (0) 2010.04.01
Data Structure 4번째 HW  (0) 2010.04.01

Week 5: Linear Lists - Linked Representation

1. Write code for the class ChainWithSortMethods. This class is a subclass of Chain and it includes the number method insertionSort, which uses insertion sort to reorder the chain elements into nondecreasing order. Do not create new nodes or delete old ones.


a) What is the worst-case time complexity of your method? How much time does your method need if the elements are already in sorted order?


b) Test the correctness of your method by compiling and then executing the code. Use your own test data (any programs with any data are allowed).

1. Make an interface “StudentLinearList” as shown in Program 5.1.
프로그램 5.1 에 있는것과 같이 StucentLinearList 인터페이스를 만들어라.

Implement the “StudentArrayLinearList” class, which is an implementation of the interface “StudentLinearList”.
StudentLinearList를 인터페이스로 갖는, StucentArrayLinearList클래스를 구현하여라.

Modify the time measuring program, which was used in the last homework, by replacing the “Student” object array with the “StudentArrayList” class.
지난번 과제에서 만들어 놓은 시간측정프로그램을 Student배열을 사용하던것에서 StudentArrayList클래스를 사용하는것으로 수정해라.

2. Extend “StudentArrayLinearList” to include the method “removeRange”, which removes all elements in the specified index range.
StudentArrayLinearList를 특정 인덱스 범위를 제거하는 removeRange메소드를 갖도록 확장해라.

What is the complexity of your method?
이 메소드의 복잡도는 얼마인가?

3. Extend “StudentArrayLinearList” to include the method “concateList”, which concatenates a parameter “StudentArrayLinearList” to the list of the method-owner object.
StudentArrayLinearList를 StudentArrayLinearList를 인자로 하여, 원래 배열에 인자로 받은 배열을 이어 붙이는 concateList메소드를 갖도록 확장해라.

What is the complexity of your method? Test your code with a simple example code.

'생활 > 데이터 스트럭쳐' 카테고리의 다른 글

Data Structure 5번째 HW(번역)  (0) 2010.04.10
Data Structure 5번째 HW  (0) 2010.04.10
Data Structure 4번째 HW  (0) 2010.04.01
Data Structure 3번째 HW(번역)  (0) 2010.03.27
Data Structure 3번째 HW  (0) 2010.03.27
1. Make an interface “StudentLinearList” as shown in Program 5.1. Implement the “StudentArrayLinearList” class, which is an implementation of the interface “StudentLinearList”. Modify the time measuring program, which was used in the last homework, by replacing the “Student” object array with the “StudentArrayList” class.

2. Extend “StudentArrayLinearList” to include the method “removeRange”, which removes all elements in the specified index range. What is the complexity of your method?

3. Extend “StudentArrayLinearList” to include the method “concateList”, which concatenates a parameter “StudentArrayLinearList” to the list of the method-owner object. What is the complexity of your method? Test your code with a simple example code.

'생활 > 데이터 스트럭쳐' 카테고리의 다른 글

Data Structure 5번째 HW  (0) 2010.04.10
Data Structure 4번째 HW(번역)  (0) 2010.04.01
Data Structure 3번째 HW(번역)  (0) 2010.03.27
Data Structure 3번째 HW  (0) 2010.03.27
Data Structure 2번째 HW(내맘대로 분석 #2)  (0) 2010.03.20
1. Now we have four sorting algorithm implementations, which were originated from the 2nd week homework.
이제 우리는 2번째 과제의 4개의 정렬 알고리즘을 갖고있다.
This is the time for asymptotically analyze each program. Of course, you have to analyze them under best, worst and average cases.
이번엔 점근적인(asymptotically) 분석을 해보자. 물논, 최악, 최적, 평균적인 사건에 대해 분석해야 된다.

2. Since we have the actual implementations, we can measure the execution time of them.
실제로 구현을 해놓았기 때문에 우리는 각 알고리즘의 실행시간을 측정할수 있다.

As we learned in the class, insert profiling (time measuring) code into your programs, and measure the time to sort randomly generated data sets (Yes, you have to make random student object generating code, too!).
우리가 수업에서 배운 시간 측정용 코드를 너의 프로그램에 넣어라, 그리고 임의로 생성된 데이터셋을 정렬하는 시간을 측정하여라(우리는 랜덤한 학생 오브젝트를 만드는것도 수업시간에 해 보았다.)

The number of students to be sorted must vary from 10 to 1,000,000 by log-scale increment (10, 100, 1,000, 10,000, … on and on).
학생의 숫자는 10에서 1,000,000 까지 큼직큼직하게 변해야 한다(10, 100, 1,000, 10,000, 이런식으로,,)

Draw graphs illustrating the tendency of the execution time changes depending on the changes of the data set size.
데이터 셋의 사이즈에 따라 실행 시간이 변하는 추세를 나타내는 그래프를 그려라.

The source codes, analysis results and graphs have to be prepared in a PDF file.
소스코드와, 분석결과, 그리고 그래프는 반드시 PDF파일로 보내세요.
1. Now we have four sorting algorithm implementations, which were originated from the 2nd week homework. This is the time for asymptotically analyze each program. Of course, you have to analyze them under best, worst and average cases.

2. Since we have the actual implementations, we can measure the execution time of them. As we learned in the class, insert profiling (time measuring) code into your programs, and measure the time to sort randomly generated data sets (Yes, you have to make random student object generating code, too!). The number of students to be sorted must vary from 10 to 1,000,000 by log-scale increment (10, 100, 1,000, 10,000, … on and on). Draw graphs illustrating the tendency of the execution time changes depending on the changes of the data set size.

The source codes, analysis results and graphs have to be prepared in a PDF file.
===================================================================================================
RankSort 분석
===================================================================================================





'생활 > 데이터 스트럭쳐' 카테고리의 다른 글

Data Structure 3번째 HW(번역)  (0) 2010.03.27
Data Structure 3번째 HW  (0) 2010.03.27
Data Structure 2번째 HW(내맘대로 분석)  (0) 2010.03.18
Data Structure 2번째 HW(번역)  (0) 2010.03.18
Data Structure 2번째 HW  (0) 2010.03.18
===================================================================================================
문제 분석
===================================================================================================

음,, 일단 랭크소트가 무엇인지를 파악해야겠군,,,
최형이라면 알지도 모르지만, 혼자 해보는것도 재미있을것 같다,,
문제는 시간.

시간 복잡도의 경우도 “counting the comparison operations(비교 연산자 갯수 세기)”는 쉬운데 “counting the steps with the s/e and frequency table(스텝을 세어서 빈도분석)”법은,,,,, 서의성 교수님 시간이었지만, 전날 무리하는 바람에 못들었다..

공부할게 많네,,,

공간 사용에 대해서는 보통 정렬의 경우에 공간은 거의 차지하지 않지, 임시공간 1개 정도? (merge의 경우를 제외하면,, 저번에 보니까 merge도 새로 안만들고 어떻게 하는 모양이던데,, 나는 같은 크기의 배열을 2개 만들고 옮겨 다녔으니,,,,)

 뭐,,, 오늘부터 해봐야지..

'생활 > 데이터 스트럭쳐' 카테고리의 다른 글

Data Structure 3번째 HW(번역)  (0) 2010.03.27
Data Structure 3번째 HW  (0) 2010.03.27
Data Structure 2번째 HW(내맘대로 분석 #2)  (0) 2010.03.20
Data Structure 2번째 HW(번역)  (0) 2010.03.18
Data Structure 2번째 HW  (0) 2010.03.18
===================================================================================================
번역
===================================================================================================
1. Our textbook introduces another sorting algorithm called rank sort at page 80.
1. 우리의 교제에서는 또다른 정령 알고리즘인 rank정렬을 80페이지에서 소개하고 있다.
Make a rank sort program that sorts students by their name and print their scores along side the names in the sorted order.
Rank정렬을 이용하여 학생들을 그들의 이름으로 정렬하고, 그들의 점수를 정렬된 이름옆에 표시하는 프로그램을 작성하여라.
Student names and scores must be included in a Student object.
학생의 이름과 점수는 반드시 Student 오브젝트에 포함되도록 만들어져야 한다.
The data are input through keyboard and the number of students is flexible (use a sentinel).
입력받는 데이터는 키보드로 입력받도록 하고, 학생의 수는 자유롭게 입력 받을수 있도록 한다(sentinel은 보초라는 뜻인데,,,,).
Analyze the best case, worst case and average case space and time complexity of the program you made.
당신이 만든 프로그램에서 시,공간 복잡도를 최적, 최악, 평균적인 경우을 놓고 분석하여라.
For time complexity, use both “counting the comparison operations” and “counting the steps with the s/e and frequency table” approaches.
시간 복잡도의 경우 “counting the comparison operations(비교 연산자 갯수 세기)”와 “counting the steps with the s/e and frequency table(스텝을 세어서 빈도분석)”법을 모두 사용하여라.

2. Modify the program for problem 1 by replacing the sorting algorithm with bubble sort, insert sort and selection sort.
2. 1에서 만들었던 프로그램을 Bubble정렬과 Insert정렬, Selection정렬로 고쳐보아라.
Also, you have to analyze the best, worst and average case space and time complexity of each version.
또한 최적, 최악, 평균적인 경우의 시, 공간 복잡도를 각각 분석하여라.

* The source codes, analysis results and screen shots of your programs in working have to be prepared in a PDF file.
* 소스코드와 분석결과, 그리고 프로그램 작동의 스샷은 PDF파일로 작성하여라.

1. Our textbook introduces another sorting algorithm called rank sort at page 80. Make a rank sort program that sorts students by their name and print their scores along side the names in the sorted order. Student names and scores must be included in a Student object. The data are input through keyboard and the number of students is flexible (use a sentinel). Analyze the best case, worst case and average case space and time complexity of the program you made. For time complexity, use both “counting the comparison operations” and “counting the steps with the s/e and frequency table” approaches.

2. Modify the program for problem 1 by replacing the sorting algorithm with bubble sort, insert sort and selection sort. Also, you have to analyze the best, worst and average case space and time complexity of each version.

* The source codes, analysis results and screen shots of your programs in working have to be prepared in a PDF file.

버블정렬 생활/알고리즘(?) 2009. 11. 15. 01:15
template <class T>
void BubbleSort(T arr[], const int size)
{
for(int i=0; i<size-1; i++)
{
for(int j=0; j<size-1; j++)
{
if(arr[j]>arr[j+1])
{
T t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
}
흠,,,, 뭔가 깨져서 옮겨진것 같지만,,,
소개하자면,, 완전 노가다 알고리즘이다.
처음부터 끝까지 인접한 2개씩 비교하면서 서로 정렬하는거다,,,
조금 개선된 알고리즘도 있으니 좀있다 올리겠다.

'생활 > 알고리즘(?)' 카테고리의 다른 글

버블정렬2  (0) 2009.11.15
엊그제 배송된 페도라 리눅스 책을 보면서 페도라 11을 2대 설치했다.
0

근데 문제는 책에는 페도라 코어 4로 설명이 되있고, 부록으로 설치시디 4장이 들어있다.
하지만 내 책에는 부록으로 시디가 2장밖에 없었다!!!

받자마자 설치파트를 보고 다운받으러 갔다가 페도라 11로 업그레이드 된걸 보고,
처음은 시키는 대로 해야지 라는 생각에 설치시디를 보니 1/4, 2/4만 있고, 3/4, 4/4가 없었다.

혹시 1, 2만 갖고 데모를 써본뒤에 3,4는 알아서 구하라는건가? 싶어 yesXX서점에
바로 문의를 해보고 받은 답변,,
0

일단 페도라 11로 갖고 놀고 있어야지,,, 근데 몇가지 명령어(? 프로그램? )이 빠진건지 사라진건지,,,
코어4는 지원기간도 끝났고,,

P.S. 코어가 무료배포용이라고 했는데, 페도라로 다시 합쳐진건기???

'생활 > 공부' 카테고리의 다른 글

구성 요소 기본 포트 번호  (0) 2009.12.30
10만원어치 책,,,  (0) 2009.11.12
10만원어치 책,,, 생활/공부 2009. 11. 12. 20:58

오늘은 yes**.com에서 주문한 10만원어치 책이 도착했다.
리눅스 서버관리관련 책과, 리눅스 프로그래밍 책을 주문했는데 2일만에 왔으니 빠른편.
012
이 범상치 않은 크기를 보라,,,( 우리방의 임시 쓰레기통이 될듯됨)

개봉샷

012
첫장은 무시,,,,,,,, 역시 큰상자에는 큰 책들이,,,

012
제일 뚜꺼운 실무 바이블책,,, 심지어 상,하 2권,,ㄷㄷ

01

자자 딴건보지말고 컴퓨터책만 98000원,,, 나이거 언제 다보지?

01

다시한번 이 웅장한 뚜께,,(두께가 아님!!)

일주일 만에 완파하고 UPC의 서버를 만들어주마!!

'생활 > 공부' 카테고리의 다른 글

구성 요소 기본 포트 번호  (0) 2009.12.30
호랭이 두마리 입양 완료!!  (0) 2009.11.14
http://dcmichael.tistory.com/28  << 여기에서 확인해 주세요

'생활 > 프로그래밍' 카테고리의 다른 글

간단한 DLL다운로더!  (0) 2009.08.07
에러 잡았다!!!  (0) 2009.08.07
sdl로 ttt만드는중!!  (1) 2009.04.26
리버시(오델로) 프로그래밍 도와주세요!!  (0) 2009.03.19
오델로 게임 1.0.0.0버전  (6) 2009.03.19
JAVA숙제,,, 대학생활/JAVA 2009. 4. 9. 17:36

요즘 정신없이 사느라 티스토리도 못들어 오네요,,,ㄷㄷ
일단 이번숙제는

1. Write a unit conversion program that asks users to identify the unit from which they want to convert and the unit to which they want to convert. Available units should be mm, cm, m, ft, and in. Define two objects of a class UnitConverter that convert between meters and a given unit.
Convert from:
in
Convert to:
mm
Value:
10
10 in = 254 mm
Use the following class as your main class:
import java.util.Scanner;

/**
   This class converts between two units.
*/
public class ConversionCalculator
{
   public static void main(String[] args)
   {
      Scanner in = new Scanner(System.in);

      System.out.println("Convert from:");
      String fromUnit = in.nextLine();

      System.out.println("Convert to:");
      String toUnit = in.nextLine();

      UnitConverter from = new UnitConverter(fromUnit);
      UnitConverter to = new UnitConverter(toUnit);

      System.out.println("Value:") ;
      double val = in.nextDouble();

      double meters = from.toMeters(val);
      double converted = to.fromMeters(meters);

      System.out.println(val+ " "+ fromUnit+ " = "+ converted
            + " "+ toUnit);
   }
}


이거입니다.
mm, cm, m, ft, in중 2개를 선택받아 서로 단위를 변환하는 계산기 문제인데요,,
UnitConverter 란 클래스를 만들어서
생성자에서는 처음 들어간 string을 갖고 처음의 단위를 계산하고, toMeter라는 함수를 이용해서 공통단위인 Meter로 고침니다. 그다음 그Meter단위 숫자를 받아서 다시 원하는 단위로 고치는,,,


순서는 이렇습니다.

1. 먼저 2개의 단위를 입력받습니다.
2.  이것을 각각 from, to라는 UnitConverter클래스에 생성자의 인자로 주어 from, to의 단위를 정합니다.
3. 그다음 from을 meter로 바꾸는 함수를 이용해 meter값을 임시변수에 넣습니다.
4. meter단위인 임시변수를 to 에 집어넣어 to 단위로 바꿈니다.
5. 이것을 출력합니다.,,,

말은 쉽지만, 이걸 하려면 if노가다나 단위변환상수를 정해놔야겠군요,,,

'대학생활 > JAVA' 카테고리의 다른 글

Eclipse 단축키  (0) 2010.03.21
내맘대로 강좌 JAVA편,,,ㅠㅠ  (2) 2009.04.23
4주차 자바숙제 떳어요,,  (0) 2009.04.01
내맘대로 강좌 JAVA편 4.5편!!  (0) 2009.03.25
내맘대로 강좌 JAVA편 4  (0) 2009.03.25
늦었지만 공지 합니다.
제가 C++을 패스하고 좀 게을러 졌네요,,,

1번.
"Do you want to continue?"라는 문구를 출력한뒤 사용자게  "Y", "Yes", "OK", "Sure", or "Why not?"을 입력하면 "OK"를 출력하고, "N", "No"를 입력하면 "Terminating"을 출력,
둘다 아니면 "Bad input"을 출력하도록 하고, 대소문자는 구분하지 않는대요,,

2번.
계속 사용하던 Employee 클래스형 변수를 이용해서 이름과 시급을 읽어 냅니다.
그후 일주일에 몇시간을 일했는지를 물어보고, 1주일의 급여를 계산하는데,
주당 40시간 이상 일한부분은 1.5배의 봉금을 주래요,,, (맞나, 오역이 있으면 댓글이나 쪽지로,,)

문제는 이 두가지 인데,
1번은 입력을 받은뒤 if문을 쓸줄 아느냐? 라는 문제이고,
2번은,, 글쎄,, 값을 갖고,,,, 이것도 if문이네요,,
열심히 해 보세요(참 쉽죠?)

그리고 제가 모든것을 다 설명드릴수는 없지만(검열때문에), dcmichael@nate.com <<네이트온
으로 쪽지주시면 모르는 부분은 좀더 자세히 설명해 드리겠습니다

'대학생활 > C++' 카테고리의 다른 글

내맘대로 강좌 C++편 7 (클래스)  (1) 2009.04.23
C++숙제,,,  (0) 2009.04.09
3주차 C++숙제가 나왔습니다!!  (0) 2009.03.23
내맘대로 강좌 C++편 6 (함수편)  (5) 2009.03.23
내맘대로 강좌 C++편 5  (2) 2009.03.19
도메인 따위 살돈도 없고, 학교에서 밖으로 포트가 열리지도 않으니,,,
주소는 요기,,,>> http://10.62.11.48:8081/
업로드 하실분은 저에게 비밀댓글로 아뒤랑 비번을^^

'생활' 카테고리의 다른 글

동아리 폐부  (0) 2012.03.10
크롬 확장 scribefire를 써보자  (1) 2012.02.23
Haven and Hearth 시작!  (1) 2011.02.09
[TIP!]windows에서 linux의 하드 링크기능 사용하기  (0) 2010.02.07
더미 파일 만들기  (0) 2009.12.29

앞으로 C++은 월,수,금
자바는 화,목,토 에 올리도록 노력해 볼께요,,
제가 요즘 생활이 많이 불규칙해져서,, 언제 생각나면 더 올릴지는 모르고, 몸이 안좋다고 빼먹을지는 모르지만,,, 기본적인 업뎃 날짜는 이렇게 해 놓을게요,,
요즘 동아리에 많이 가입하는바람에,,,

p.s. 동아리에 가입하는거 제한은 없겠죠?
지금 연극, 방송, 기타, 컴터에 가입하려는데,,,

'대학생활' 카테고리의 다른 글

지금은 집 입니다.  (0) 2009.12.22
UNIST 2009년 2학기 기말고사 시간표  (0) 2009.12.05
내맘대로 강좌 공통편 1  (0) 2009.03.20
학생증 드디어 나왔습니다!!!  (0) 2009.03.16
내맘대로 강좌 시작!!  (1) 2009.03.16

지금 와일리를 보다가 나온건데, 콘솔이 아닌 다이얼로그로 입력, 출력하는법 발견,,

Call the static showInputDialog method of the JOptionPane class, and supply the string that prompts the input from the user. For example,
String input = JOptionPane.showInputDialog("Enter price:");
That method returns a String object. Of course, often you need the input as a number. Use the Integer.parseInt and Double.parseDouble methods to convert the string to a number:
double price = Double.parseDouble(input);
You can also display output in a dialog box:
JOptionPane.showMessageDialog(null, "Price: " + price);
Finally, whenever you call the showInputDialog or showMessageDialog method in a program that does not show any other frame windows, you need to add a line
System.exit(0);
to the end of your main method. The showInputDialog method starts a user interface thread to handle user input. When the main method reaches the end, that thread is still running, and your program won't exit automatically. To force the program to exit, you need to call the exit method of the System class. The parameter of the exit method is the status code of the program. A code of 0 denotes successful completion; you can use nonzero status codes to denote various error conditions.
                                                              (원문 출처 와일리,,,)

이 장에 의하면
JOptionPane.showInputDialog("Enter price:");
이 함수는 Enter Price:라는 문구가 들어간 입력 다이얼로그를 띄워주고 다이얼로그에서 확인이 눌리거나 엔터가 쳐질경우 그 값을 srting 형으로 반환합니다.
그 뒤 Double.parseDouble(string)이나 Int.parseInt(string)함수로 각각의 형으로 고칠수 있는것 같구요,,,,
근데 이거를 사용하면 main함수 마지막에
system.exit(0);을 꼭 써야 한다네요,,,

'대학생활 > JAVA' 카테고리의 다른 글

JAVA숙제,,,  (1) 2009.04.09
4주차 자바숙제 떳어요,,  (0) 2009.04.01
내맘대로 강좌 JAVA편 4  (0) 2009.03.25
내맘대로 강좌 JAVA편 3  (0) 2009.03.25
3주차 JAVA숙제가 나왔습니다^^  (2) 2009.03.23

계속 이어서 Arithmetic Operations and Mathematical Functions, Calling Static Methods, Strings, Reading Input 에 대해 설명할께,,,

일단 Arithmetic Operations and Mathematical Functions 요놈,,,
Arithmetic Operations는 산술적인 연산자 + - * / ()설명인데,,, 수학하고 같으니 PASS!!
Mathematical Functions는
Math.sqrt(x)
Square root of x (≥0)
Math.pow(x, y)
xy (x > 0, or x = 0 and y > 0, or x < 0 and y is an integer)
Math.sin(x)
Sine of x (x in radians)
Math.cos(x)
Cosine of x
Math.tan(x)
Tangent of x
Math.asin(x)
Arc sine (sin-1x ε [-π/2, π/2], x ε [-1, 1])
Math.acos(x)
Arc cosine (cos-1x ε [0, π], x ε [-1, 1])
Math.atan(x)
Arc tangent (tan-1x ε [-π/2, π/2])
Math.atan2(y, x)
Arc tangent (tan-1y/x ε [-π, π]), x may be 0
Math.toRadians(x)
Convert x degrees to radians (i.e., returns x · π/180)
Math.toDegrees(x)
Convert x radians to degrees (i.e., returns x · 180/π)
Math.exp(x)
ex
Math.log(x)
Natural log (ln(x), x > 0)
Math.round(x)
Closest integer to x (as a long)
Math.ceil(x)
Smallest integer ≥x (as a double)
Math.floor(x)
Largest integer ≤x (as a double)
Math.abs(x)
Absolute value |x|
Math.max(x, y)
The larger of x and y
Math.min(x, y)
The smaller of x and y
                                                                            (출처 와일리,,,,,)
이거 있다고,, 그냥 그렇다고,,,

그다음은 Calling Static Methods
이건,,,,
int x=4;
double rootofx = x.sqrt();
이렇게 삽질하지 말고
double rootofx = Math.sqrt(x);
이렇게 하래,,,

Strings
String 클래스에는 substr및 각종함수들이 준비되어 있어서 문자열을 사용하기 편하다,,
라는,,,,,,,

이번엔 중요한 Reading Input!!!
C++은 인풋을 읽어오기가 쉬워서 숙제에도 가끔 인풋이 필요했지만,,,
자바는 없었지? 드디어 나왔어 인풋 받는법,,,

Scanner in = new Scanner(System.in);
이렇게 하면 인풋을 받는 스트림이 생긴거야.
그 다음엔
system.out.print("input number : ");
int quantity = in.nextInt();
이렇게 하면 input number : 뒤에 커서가 깜박인데,,, 거기에 숫자를 쓴다음 엔터를 치면quantity에 들어간다는데,,, 지금 컴을 포맷해서 아직 테스트는,,,,

그다음 in.nextInt() 대신 in.nextDouble();을 쓰면 double를 받아오고,,,in.nextLine(); 하면 한 줄(엔터까지) 받아서 string으로,,,in.next(); 까지만 해도 string으로 받는 다는데, 이건 아마 스페이스바가 구분자인가봐,,,
일단 예제,,(출처 와일리 교재 내부,,)

1 import java.util.Scanner;
2
3  /**
4    This program simulates a transaction in which a user pays for an item
5    and receives change.
6    */
7    public class CashRegisterSimulator
8    {
9       public static void main(String[] args)
10      {
11     Scanner in = new Scanner(System.in);
12
13     CashRegister register = new CashRegister();
14
15     System.out.print(“Enter price: ”);
16     double price = in.nextDouble();
17     register.recordPurchase(price);
18
19     System.out.print(“Enter dollars: ”);
20     int dollars = in.nextInt();
21     System.out.print(“Enter quarters: ”);
22     int quarters = in.nextInt();
23     System.out.print(“Enter dimes: ”);
24     int dimes = in.nextInt();
25     System.out.print(“Enter nickels: ”);
26     int nickels = in.nextInt();
27     System.out.print(“Enter pennies: ”);
28     int pennies = in.nextInt();
29     register.enterPayment(dollars, quarters, dimes, nickels, pennies);
30
31     System.out.print(“Your change: ”);
32     System.out.println(register.giveChange());
33      }
34 }

register클래스가 뭔진 몰라도 돈을 입력받을수 있는 클래스인가봐,,,
여하간 여기서 중요한건 register가 아니라 Scanner in 의 용법이니까
실행이 안되면 눈으로 라도 보고,,, 용법만이라도 익혀,,, 근데 아마 저거 다 클럽에 있던,,,
내가 블로그에 퍼놓은  헤더파일에 있는예제인듯

'대학생활 > JAVA' 카테고리의 다른 글

4주차 자바숙제 떳어요,,  (0) 2009.04.01
내맘대로 강좌 JAVA편 4.5편!!  (0) 2009.03.25
내맘대로 강좌 JAVA편 3  (0) 2009.03.25
3주차 JAVA숙제가 나왔습니다^^  (2) 2009.03.23
내맘대로 강좌 JAVA편 2  (0) 2009.03.16

정말 자바강좌는 나도 공부하며 쓰려니까 쓰기가 어렵군,,,

우선 클래스가 무엇인지와 변수가 무엇인지에 대해 대략 설명은 한것 같은데,,,
좀더 자세한 부분을 설명하도록 할께,,

우선
와일리의 쳅터 4의 목차를 보면
        Syntax 4.1: Cast
        Advanced Topic 4.1: Big Numbers
        Advanced Topic 4.2: Binary Numbers
        Random Fact 4.1: The Pentium Floating-Point Bug
        4.2. Constants
        Syntax 4.2: Constant Definition
        Quality Tip 4.1: Do Not Use Magic Numbers
        Quality Tip 4.2: Choose Descriptive Variable Names
        4.3. Assignment, Increment, and Decrement
        Productivity Hint 4.1: Avoid Unstable Layout
        Advanced Topic 4.3: Combining Assignment and Arithmetic
        4.4. Arithmetic Operations and Mathematical Functions
        Common Error 4.1: Integer Division
        Common Error 4.2: Unbalanced Parentheses
        Quality Tip 4.3: White Space
        Quality Tip 4.4: Factor Out Common Code
        4.5. Calling Static Methods
        Syntax 4.3: Static Method Call
        Common Error 4.3: Roundoff Errors
        How To 4.1: Carrying Out Computations
        4.6. Strings
        Productivity Hint 4.2: Reading Exception Reports
        Advanced Topic 4.4: Escape Sequences
        Advanced Topic 4.5: Strings and the Char Type
        Random Fact 4.2: International Alphabets
        4.7. Reading Input
        Advanced Topic 4.6: Formatting Numbers
        Advanced Topic 4.7: Using Dialog Boxes for Input and Output
        4.8. Chapter Summary
        Classes, Objects, and Methods Introduced in this Chapter
        Review Exercises
        Programming Exercises
        Programming Projects
        Answers to Self-Check Questions
        Further Reading
이렇게 되어있어,,, 중요한거는 4.x부분인데,,,
보면
cast, big number, constants, assignment, Increment, and Decrement, Arithmetic Operations and Mathematical Functions, Calling Static Methods, Strings, Reading Input
이 있어,,헉헉

cast 라는것은 형을 변환 시키는 거야. 예를들면,

double dValue=3.5;
int iValue = (int)dValue; 이렇게 하면 dValue 가 int 형으로 바뀌어서 들어가는거야,,
근데 이상하지? 3.5는 정수가 아닌데 어떻게 될까?
1. 반올림
2. 버림
3. 올림




답은 2번 버림,,,, 소숫점은 무조건 버려, 그럼 int를 double에 넣을땐?
상관없지 뭐,, 그땐 오류없이 잘 들어가,,
이런식으로 형을 변환시키는 것을 형변환(casting)이라고 해. 나중에 클래스끼리도 캐스팅이 되긴 하는데, 이거는 서로 부모, 자식 관계가 있는경우에만 되니까 나중에 설명할께,,

그다음으로는 big number인데,, 와일리에 보면 math라는 클래스안에 BigInterger 랑 BigDecimal 클래스가 있어서 큰수 계산이 된데,,,,

다음은 상수(constants)
인데 상수는 C나 C++언어를 배운 사람은 const예약어를 사용한다고 알고있을거야.
하지만 C++의 클래스에서도 사용했듯이 자바는 final이라는 예약어를 사용해.

예를 들면

final double PI = 3.14;
// PI=3.141592             //에러,,,
double radian = 3;
double area=radian*radian*PI;

이런식으로 PI값은 항상 정해져있어서 고쳐지면 안될때 사용하는거,,,
이게바로 상수의 사용법

그다음은 assignment, Increment, and Decrement

이거는 대입과 증가 감소인데,,,

대입은 계속 해왔고,,,
증가와 감소가 있는데,,
int i=0;
i=i+1;         //1
i+=1;         //2
i++;          //3
system.out.println(i);


결과는 3
왜냐하면 1번은 쉽게 알수있는거고,
2번은 1번을 줄여서 쓸수있게 한거고,,
3번은 i에 1을 더하라는거야,, 그래도 i+++한다고 2가 더해진다는 생각은 버려!!

근데 신기한게,,,
int i=0;
system.out.println(++i);
system.out.println(i++);
이렇게 하면 1하고 1이 출력되,

왜냐하면 ++i는 +1을 한 다음 함수라든지 대입을 하고,
 i++은 대입이나 함수에 먼저 처리를 한다음 +1을 하기 때문,,,헥헥,,, 다음은 뒷글에 이어서,,,

'대학생활 > JAVA' 카테고리의 다른 글

내맘대로 강좌 JAVA편 4.5편!!  (0) 2009.03.25
내맘대로 강좌 JAVA편 4  (0) 2009.03.25
3주차 JAVA숙제가 나왔습니다^^  (2) 2009.03.23
내맘대로 강좌 JAVA편 2  (0) 2009.03.16
내맘대로 강좌 JAVA편 1  (3) 2009.03.16

어쩌다보니 공통편이 나오네,,

제어문에 관한거야.
제어문이란 프로그램이 순서대로 쭉 밑으로만 가는게 아니라,

다시 반복도 하고, 조건이 안맞으면 건너 뛰기도하는,,, 그런게 제어문이야.
이번 2주차 C++3번 숙제는 이거 꼭 쓸듯,,,

우선
if( 조건1 )
{
TODO1();
}
else if( 조건2 )
{
TODO2();
}
else
{
TODO3();
}

이거는 조건부분에 a>1 이라고 하면 a가 1보다 클때 그부분의 TODO함수가 실행이 되,
예를들면

int a=15;
if( a<5 )
{
cout<<"a 는 5보다 작다";
}
else if( a>=5 && a<15 )
{
cout<<"a 는 5보다 크고 15보다 작다";
}
else
{
cout<<"a 는 15보다 크다";
}

하면 "a 는 5보다 크고 15보다 작다"가 출력되는거야
조건문에 < 랑 > 는 알테고,, <=(작거나 같다) >=(크거나 같다)
&&(and) 양쪽 모두 참일때 참
||(shift+\) 양쪽중 하나라도 참이면 참
==(같으면 참)
을 써서 논리적인 표현이 가능해

그다음은
while( 조건)
{
TODO();
}

조건은 만족하는동안 계속 반복

for( ㉠ ; ㉡ ; ㉢ )
{
todo(); //㉣
}

㉠으로 반복전 처리
㉡은 while의 조건부분
㉣은 실행부
㉢은 후처리,,,


for( i=0 ; i<5 ; i=i+1 )
{
       cout << i << "회째 반복"<<endl;
}

하면 처음에
i=0실행
그다음 cout
그다음 i=i+1
그다음 i<5비교
그다음 cout
반복,,,, i<5가 거짓이 될때까지,,,

뭐 이정도면 숙제는 가능할듯,,
설마 내가 이렇게 새벽까지 공들여 나는 다 끝낸 숙제때문에 노력하는걸 알면,,,,
댓글이 좀 달리겟지?

'대학생활' 카테고리의 다른 글

지금은 집 입니다.  (0) 2009.12.22
UNIST 2009년 2학기 기말고사 시간표  (0) 2009.12.05
내맘대로 강좌 공지!!!  (1) 2009.03.25
학생증 드디어 나왔습니다!!!  (0) 2009.03.16
내맘대로 강좌 시작!!  (1) 2009.03.16
이분들 뭥미,,^^ 잡담 2009. 3. 19. 21:15
내 블로그에 들어온 유입경로,,, 괄호안은 검색어,,
내 블로그가 검색엔진에도 뜬다는건 기쁜데,,, 이렇게 노골적으로 숙제를 검색하면
안되지 않을까요 여러분? ㅋㅋ
열심히 교재를 읽거나 인터넷의 언어 강좌를 읽어서 스스로 합시다 여러분,,
검색해도 안나와요,, 내 블로그만 나오지 ^^

'잡담' 카테고리의 다른 글

헐,, 질렀다!!  (0) 2009.04.25
샨새교 귀엽네요,,,  (2) 2009.04.01
뭐,, 어찌어찌  (0) 2009.03.15
한동안 못들어 왔네,,,  (0) 2009.02.25
해리포터 6편,,  (0) 2009.02.09

이제 막 개발 시작했습니다.
대학와서 젤 처음 해보고 싶었던 게임개발의 첫걸음!!!

개발환경 Visual Studio6 Ent. MFC.

버전정보

0.0.0.0 윈도우 제위치 제 사이즈에 놓고 사각형 보드 그리기 더블버퍼링 구현,,,

0,0,0,1 Othellomap 클래스 제작, 보드에 말놓기, 턴, 각자의 말 갯수등 기본 변수 세팅,,,

0,0,0,2 말을 놓으면 십자방향으로 리버스가 구현.

1,0,0,0 말을 놓으면 사이의 말 뒤집기 대각선구현(예정) 
          돌이 마우스를 따라다님.
          보드 색상, 돌 색상 변경.
          우측 상단에 간단한 게임 정보 표시.

TODO : 아이콘 변경
           인터페이스 생성
           도움말 작성
           세이브기능
           로드기능
           인공지능(VS컴퓨터)
           기타등등

어찌어찌 1,0,0,0이 나왔습니다. 근데 버전은 VS를 업그레이드하며 꼬여버렸다는,,
아직 할일이 많네요,,
...
역시 이번에도 릴리즈만 올립니다. 버그리포팅 환영이고요,
소스는 필요하신분께는 드립니다,,(공부하느라 퍼온 소스들이 주석으로 남아있어서,,,)

'생활 > 프로그래밍' 카테고리의 다른 글

간단한 DLL다운로더!  (0) 2009.08.07
에러 잡았다!!!  (0) 2009.08.07
sdl로 ttt만드는중!!  (1) 2009.04.26
오델로 게임이 업데이트 되었습니다.  (0) 2009.04.12
리버시(오델로) 프로그래밍 도와주세요!!  (0) 2009.03.19

드디어 나오는군요 우리학교의 학생증!!!

일단 적절한 플래쉬로 모자이크를(디카가 구려서 억지로 입혀졌지만)씌운뒤

다시 삽질해서 올려봅니다.

'대학생활' 카테고리의 다른 글

지금은 집 입니다.  (0) 2009.12.22
UNIST 2009년 2학기 기말고사 시간표  (0) 2009.12.05
내맘대로 강좌 공지!!!  (1) 2009.03.25
내맘대로 강좌 공통편 1  (0) 2009.03.20
내맘대로 강좌 시작!!  (1) 2009.03.16