-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb001_Vector.java
More file actions
50 lines (40 loc) · 1.41 KB
/
Copy pathProb001_Vector.java
File metadata and controls
50 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package java0912_collection.prob;
import java.io.File;
import java.util.Scanner;
import java.util.Vector;
/*
* [문제] : booklist.txt 파일의 데이터를 이용하여
* 책 정보 하나당 하나의 Book 객체를 생성하고 생성된 Book 객체들을
* Vector에 담아서 리턴하는 makeBookList() 메서드를 구현하시오.
*
* [실행결과]
* Java Programming 의 가격 : 25000
* SQL Fundamentals 의 가격 : 47000
* JDBC Programming 의 가격 : 30000
* Servlet Programming 의 가격 : 20000
* JSP Programming 의 가격 : 21000
*/
public class Prob001_Vector {
public static void main(String[] args) throws Exception {
Vector<Book> bookList = makeBookList();
for (Book book : bookList) {
System.out.println(book.getTitle() + " 의 가격 : " + book.getPrice());
}
}// end main()
private static Vector<Book> makeBookList() throws Exception {
// booklist.txt 파일의 데이터를 Vector에 저장한 후 리턴하는 프로그램을 구현하시오.
File file = new File("src/java0912_collection/prob/booklist.txt");
Scanner sc = new Scanner(file);
String sn = null;
String[] strArr = null;
Vector<Book> v = new Vector<Book>();
while (sc.hasNextLine()) {
sn = sc.nextLine();
strArr = sn.split("/");
Book bk = new Book(strArr[0], strArr[1], strArr[2], strArr[3]);
v.add(bk);
}
sc.close();
return v;
}// end makeBookList()
}// end class