티스토리 뷰
여러분은 다음과 같은 특징을 가지는 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.
* Line 1 : id 문자열 (최대길이1,000)
* Line 2 : name 문자열 (최대길이1,000)
* Line 3 : 전날의 주식값 (1~1,000,000,000 사이의 실수)
* Line 4 : 오늘의 주식값 (1~1,000,000,000 사이의 실수)
* Line 1~3 : 샘플 출력 참조
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
Naver Naver Corp. 392930 29911223
Prev Price: 392930.00 Curr Price: 29911223.00 Price Change: 7512.35%
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 |