검색결과 리스트
글
손쉽게 저지를수 있는 MFC 실수중 하나
// CPoint에서 pt라고 줬으니 당근 pt.x, pt.y로 해야 됨
void CMyView::OnLButtonDown(UINT id, CPoint pt)
{
CString strPos;
strPos.Format("%03d %03d",pt.x,pt.y);
HDC hdc;
hdc=::GetDC(m_hWnd);
::TextOut(hdc,0,0,strPos,strPos.GetLength());
::ReleaseDC(m_hWnd,hdc);
CView::OnLButtonDown(id,pt);
}
// CPoint 전역함수 아니고 지역함수잖아, 여기서 point라고 줬으니 아래도 point.x, point.y이런식으로
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
CString strPos2;
strPos2.Format("%03d %03d",point.x,point.y);
CDC*pDC;
pDC=this->GetDC();
pDC->TextOutA(0,0,strPos2);
this->ReleaseDC(pDC);
CView::OnMouseMove(nFlags, point);
}
설정
트랙백
댓글
글
20130522 HCI 과제 완료
/*
sell 추가
Buyer 클래스에 sell(Product p) 메서드를 추가하라
*/
package polyargumenttest2;
class Product {
int price; // 제품의 가격
int bonusPoint; // 제품구매 시 제공하는 보너스점수
Product(int price) {
this.price = price;
bonusPoint = (int) (price / 10.0);
}
Product() {
price = 0;
bonusPoint = 0;
}
}
////////////////////////////////////////////////////////상품 추가 부분/////////////////////////////////////////////////////////////////////
// iPad 추가
class iPad extends Product {
iPad() {
super(90);
}
public String toString() {
return "iPad";
}
}
// Tv 추가
class Tv extends Product {
Tv() {
super(100);
}
public String toString() {
return "Tv";
}
}
// Computer 추가
class Computer extends Product {
Computer() {
super(200);
}
public String toString() {
return "Computer";
}
}
// Audio 추가
class Audio extends Product {
Audio() {
super(50);
}
public String toString() {
return "Audio";
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
class Buyer { // 고객, 물건을 사는 사람
int money = 1000; // 소유금액
int bonusPoint = 0; // 보너스점수
//ArrayList al = new ArrayList();
Product[] item = new Product[10]; // 구입한 제품을 저장하기 위한 배열
int i = 0; // Product배열에 사용될 카운터
void buy(Product p) {
if (money < p.price) {
System.out.println("잔액이 부족하여 물건을 살수 없습니다.");
return;
}
money -= p.price; // 가진 돈에서 구입한 제품의 가격을 뺀다.
bonusPoint += p.bonusPoint; // 제품의 보너스 점수를 추가한다.
item[i++] = p; // 제품을 Product[] item에 저장한다.
System.out.println(p + "을/를 구입하셨습니다.");
}
// 판매를 진행하되, 물건을 구입한 적이 없으면 판매를 할 수 없음, 그 조건을 반드시 사용하도록 해야됨
void sell(Product p) {
int sellcount = 0;
// 배열 안에서 검색
System.out.println("[판매] : "+p+" 를 판매합니다. 실제 물품을 가지고 있는지 확인합니다");
// 배열에서 검색 진행
for (int i = 0; i < item.length; i++) {
// 배열에 해당 상품명이 있을 경우
if (item[i] == p) {
money += p.price; // 가진 돈에서 구입한 제품의 가격을 더함
bonusPoint -= p.bonusPoint; // 제품의 보너스 점수를 뺌
//System.out.println("해당 상품이 발견된 배열의 위치 : " + i);
System.out.println("[승인] : 물품 보유를 확인하였습니다.");
System.out.println("[알림] : "+p + "를 팔았다! 해당 금액은 " + p.price + ", 금액을 환불받아 잔액은 " + money + ", 포인트는 차감되어 다음과 같습니다 : " + bonusPoint);
sellcount++;
// 배열 재정렬 진행 (item 배열), i는 상품이 저장된 인덱스를 의미함, 기존 배열 위치에 있던 녀석을 다음 인덱스의 녀석으로 덮어버리고 마지막에 null 처리
for (int j = i + 1; j <= item.length; j++) {
if (item[j] != null) {
item[j - 1] = item[j];
} else {
item[j - 1] = null;
break;
}
}
}
}
//위 검색이 끝나고, 판매한 적이 없거나 구매하지 않은 물품일 경우 다음 메시지 출력
if (sellcount == 0) {
System.out.println("[오류] : 해당 물품을 구매하지 않았으므로 팔 수 없습니다. 판매룰 중단합니다.");
}
}
void summary() { // 구매한 물품에 대한 정보를 요약해서 보여 준다.
int sum = 0; // 구입한 물품의 가격합계
String itemList = ""; // 구입한 물품목록 초기화
// 반복문을 이용해서 구입한 물품의 총 가격과 목록을 만든다.
// 판매가 아닌 구매의 경우
for (int i = 0; i < item.length; i++) {
if (item[i] == null) {
break;
}
sum += item[i].price;
itemList += item[i] + ", ";
}
System.out.println("");
System.out.println("[상태 확인] - 보유물품 : " + itemList + " 총 물건 가격 : " + sum + ", 잔액 : " + money + " , 보너스 포인트 : " + bonusPoint);
System.out.println("");
}
}
class PolyArgumentTest2 {
public static void main(String args[]) {
// 바이어 생성
Buyer b = new Buyer();
// 제품 생성 부분
Tv tv = new Tv();
Computer com = new Computer();
Audio audio = new Audio();
iPad ipad = new iPad();
// 물건 구매 진행
b.buy(tv);
b.buy(com);
b.buy(audio);
// 내역 확인 및 잔액 포인트 누계
b.summary();
// 판매부분
b.sell(tv);
b.sell(ipad);
// 내역 확인 및 잔액 포인트 누계
b.summary();
}
}
설정
트랙백
댓글
글
20130522 HCI
/*
자손타입의 참조변수fr로 조상타입의 인스턴스 뉴카를 참조하려고 했기 때문에 에러가 남
*/
package castingtest2;
/**
*
* @author User
*/
class CastingTest2 {
public static void main(String args[]) {
Car car = new FireEngine();
//Car car = new Car();에서 위와 같이 바뀜, 맨처음 만들때 워터 들어가도록 파이어엔진을 만들면 됨, car객체 아닌 파이어 객체 만들어
//fr=(FireEngine)car는 변환 시 문제 발생하지 않음
Car car2 = null;
FireEngine fe = null;
car.drive();
if (car instanceof FireEngine) {
fe = (FireEngine) car; // 8번째 줄. 실행 시 에러가 발생한다.
fe.drive();
car2 = fe;
car2.drive();
}
}
}
class Car {
String color;
int door;
void drive() { // 운전하는 기능
System.out.println("drive, Brrrr~");
}
void stop() { // 멈추는 기능
System.out.println("stop!!!");
}
}
class FireEngine extends Car { // 소방차
void water() { // 물을 뿌리는 기능
System.out.println("water!!!");
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package captiontvtest;
/**
*
* @author User
*/
class Tv {
boolean power; // 전원상태(on/off)
int channel; // 채널
void power() { power = !power; }
void channelUp() { ++channel; }
void channelDown() { --channel; }
}
class CaptionTv extends Tv {// tv를 상속받음
boolean caption; // 캡션상태(on/off)
void displayCaption(String text) {
if (caption) { // 캡션 상태가 on(true)일 때만 text를 보여 준다.
System.out.println(text);
}
}
}
class CaptionTvTest {
public static void main(String args[]) {
CaptionTv ctv = new CaptionTv();
ctv.channel = 10; // 캡션에선 없지만 tv조상 클래스로부터 상속받은 멤버
ctv.channelUp(); // 조상 클래스로부터 상속받은 멤버
System.out.println(ctv.channel);
ctv.displayCaption("Hello, World");
ctv.caption = true; // 캡션기능을 켠다.
ctv.displayCaption("Hello, World"); // 캡션을 화면에 보여 준다.
Tv t = new CaptionTv();
t.channel = 10;
t.channelUp();
System.out.println(t.channel);
//t.displayCaption("Hello, World"); //can not find symbol
//t.caption = true;
//t.displayCaption("Hello, World");
//CaptionTv ctv1 = new Tv();
}
}
////////////////////////////////////////////////////////////////////////////////////////////
/*
자손타입의 참조변수fr로 조상타입의 인스턴스 뉴카를 참조하려고 했기 때문에 에러가 남
*/
package castingtest2;
/**
*
* @author User
*/
class CastingTest2 {
public static void main(String args[]) {
Car car = new FireEngine(); // 아빠 참조변수로 자녀를 참조, 파이어엔진 만들었찌만 카 객체가 있고, 화이트하고 4가 나오게 됨
System.out.println("Color : "+car.color+".Door : " + car.door);
//Car car = new Car();에서 위와 같이 바뀜, 맨처음 만들때 워터 들어가도록 파이어엔진을 만들면 됨, car객체 아닌 파이어 객체 만들어
//fr=(FireEngine)car는 변환 시 문제 발생하지 않음
car.water();
Car car2 = null;
FireEngine fe = null;
car.drive();
if (car instanceof FireEngine) {
fe = (FireEngine) car; // 8번째 줄. 실행 시 에러가 발생한다.
// 자녀의 참조변수를 참고하였기 때문에
System.out.println("Color : "+fe.color+".Door : " + fe.door);
// 오버라이딩 된 녀석이 튀어나옴
fe.water();
//fe.drive();
//car2 = fe;
//car2.drive();
}
}
}
class Car {
String color="White";
int door=4;
void drive() { // 운전하는 기능
System.out.println("drive, Brrrr~");
}
void stop() { // 멈추는 기능
System.out.println("stop!!!");
}
void water()
{
System.out.println("Car Water!!!");
}
}
class FireEngine extends Car { // 소방차
String color="Red";
int door=8;
void water() { // 물을 뿌리는 기능
System.out.println("Car Water!!!");
}
}