티스토리 뷰

학교공부/JAVA

[JAVA] Stock 클래스

yunmap 2017. 7. 26. 15:58
DESCRIPTION

여러분은 다음과 같은 특징을 가지는 Stock 클래스를 만들어야 합니다. 

  • id와 name 필드를 가진다.
  • 전날의 주식값을 저장하는 double형의 previousClosingPrice 필드를 가진다.
  • 오늘의 주식값을 저장하는 double형의 currentPrice 필드를 가진다.
  • id와 name을 통해서 클래스를 생성할 수 있어야 한다. 
  • 주식값의 변화량을 %로 표시하는 getChangePercent 메소드를 가진다.

여러분이 작성한 코드는 아래 샘플코드의 YOUR_CODE 부분에 들어가 컴파일 됩니다. 

 

(The Stock class) Following the example of the Circle class in Section 9.2, design a class named Stock that contains:

■ A string data field named symbol for the stock’s symbol.

■ A string data field named name for the stock’s name.

■ A double data field named previousClosingPrice that stores the stock price for the previous day.

■ A double data field named currentPrice that stores the stock price for the current time.

■ A constructor that creates a stock with the specified symbol and name.

■ A method named getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice.

 

INPUT

* Line 1 : id 문자열 (최대길이1,000)

* Line 2 : name 문자열 (최대길이1,000)

* Line 3 : 전날의 주식값 (1~1,000,000,000 사이의 실수)

* Line 4 : 오늘의 주식값 (1~1,000,000,000 사이의 실수)

 
OUTPUT

* Line 1~3 : 샘플 출력 참조

SAMPLE CODE
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        Stock stock = new Stock(sc.nextLine(), sc.nextLine());
        stock.setPreviousClosingPrice(sc.nextDouble());
        stock.setCurrentPrice(sc.nextDouble());

        System.out.printf("Prev Price: %.2f\n", stock.getPreviousClosingPrice());
        System.out.printf("Curr Price: %.2f\n", stock.getCurrentPrice());
        System.out.printf("Price Change: %.2f%%\n", stock.getChangePercent() * 100);
    }
}

YOUR_CODE
SAMPLE INPUT
Naver
Naver Corp.
392930
29911223
SAMPLE OUTPUT
Prev Price: 392930.00
Curr Price: 29911223.00
Price Change: 7512.35%
SOURCE

JAVA2015 PE9.2


'학교공부 > JAVA' 카테고리의 다른 글

[JAVA] GregorianCalendar  (0) 2017.07.26
[JAVA] Date 클래스  (0) 2017.07.26
[JAVA] Rectangle 클래스  (0) 2017.07.26
[JAVA] 다각형의 부분넓이  (0) 2017.07.26
[JAVA] 가장 큰 조각 1  (0) 2017.07.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/06   »
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
글 보관함