수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

[질문] array의 출력을 하는데에서..

별하

2023.04.01

책 제목하고 저자를 array에 저장하고

출력하는 프로그램입니다

Book.java만 고칠수 있습니다

두개를 [Book.java, TestBook.java]돌려서

출력이밑에와 같이 되어야합니다

코드를 고쳤거든요 Book.java의 일부를요..

근데 중간 중간에 false를 만들어서 The book requested is unavailable.를 출력하게 해야하는데요

그게 일정한게 아니라서요

밑에 있는 Book.java를 보면 toString()이 있는데요

여기서 고쳐야하는데요 여기를 어떻해 고쳐야할지 모르겠습니다

저에게 힌트를 좀 부탁드립니다
public String toString()
{
if (available = true)
return title + \n + author;
else return The book requested is unavailable.;
}
----------------------------------------------------

출력은 이와같이

The library contains 0 books.

The library contains 1 books.

The library contains 2 books.

The library contains 3 books.
theLibrary[0] is:

Aus dem Leben eines Taugenichts

Josef von Eichendorff

theLibrary[1] is:

Aquamarine

Carol Anshaw

theLibrary[2] is:

An Introduction to Object-OrientedProgramming with Java

C. Thomas Wu
theLibrary[0] is:

Aus dem Leben eines Taugenichts

Josef von Eichendorff

theLibrary[1] is:

Aquamarine

Carol Anshaw

theLibrary[2] is:

The book requested is unavailable.
theLibrary[0] is:

The book requested is unavailable.

theLibrary[1] is:

Aquamarine

Carol Anshaw

theLibrary[2] is:

The book requested is unavailable.
theLibrary[0] is:

The book requested is unavailable.

theLibrary[1] is:

Aquamarine

Carol Anshaw

theLibrary[2] is:

An Introduction to Object-OrientedProgramming with Java

C. Thomas Wu
-------------------------------------------------public class Book
{
private String author;
private String title;
private boolean available;

private static int numberOfBooks = 0;

// All four statements in this method must be altered
public Book(String initTitle, String initAuthor)
{
title = initTitle;
author = initAuthor;
boolean available = false;
numberOfBooks = numberOfBooks +1;
}

// No statements must be altered in this method
public void checkOut()
{
available = false;
}

// No statements must be altered in this method
public void checkIn()
{
available = true;
}

// One line (not even the entire statement) must be altered
// in this method
public String toString()
{
if (available = true)
return title + \n + author;
else return The book requested is unavailable.;
}

// No statements must be altered in this method
public static int libraryCount()
{
return numberOfBooks;
}
}------------------------------

public class TestBook
{
public static void main(String[] args)
{
Book[] theLibrary = new Book[3];

System.out.println(The library contains +
Book.libraryCount() + books.);

theLibrary[0] = new Book(Aus dem Leben eines Taugenichts,
Josef von Eichendorff);

System.out.println(The library contains +
Book.libraryCount() + books.);

theLibrary[1] = new Book(Aquamarine, Carol Anshaw);

System.out.println(The library contains +
Book.libraryCount() + books.);

theLibrary[2] = new Book(An Introduction to Object-Oriented +
Programming with Java, C. Thomas Wu);

System.out.println(The library contains +
Book.libraryCount() + books.\n);

for (int i = 0; i theLibrary.length; i++)
System.out.println(theLibrary[ + i + ] is:\n +
theLibrary[i].toString());
System.out.println();

theLibrary[2].checkOut();

for (int i = 0; i theLibrary.length; i++)
System.out.println(theLibrary[ + i + ] is:\n +
theLibrary[i].toString());
System.out.println();

theLibrary[0].checkOut();

for (int i = 0; i theLibrary.length; i++)
System.out.println(theLibrary[ + i + ] is:\n +
theLibrary[i].toString());
System.out.println();

theLibrary[2].checkIn();

for (int i = 0; i theLibrary.length; i++)
System.out.println(theLibrary[ + i + ] is:\n +
theLibrary[i].toString());
System.out.println();
}
}

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

  • LO

    헉! 제 컴이 클래스 패스가 않잡히네요. 잠시만 기다리세요..ㅜㅅㅜ

  • 검사

    최초에 theLibrary[]의 available는 다 false입니다. 생성자에 그렇게 되어있으니까요... 그러니 !=를 하면 다 찍힙니다. 그런데 theLibrary[2].checkOut()을 하면 false로 셋팅하는건데.. flase는 찍으라는 상태정보인데 문제가 약간 헷갈리는군요..? 혹시 교재에 있는 문제인가요..?

  • 별하

    if (available = true)를 어떻해 바꿔야할런지-.- ㅠ.ㅠ.ㅠ

  • 눈내리던날

    전체가 바뀌는게 아니라 한 문장만 바뀌어야해서요 그래서 if 뒤에 배열을 나타나는것이[물론 false가 되는 공식이 들어가야겠죠-이걸 모르겠다는-.-] 나와야할것같아서요

  • 개랑

    고칠수 있으면 좋겠는데요 한문장만 바뀐데요 ㅠ.ㅠ 그게 조건이라서요

  • 로와

    전부 false로 setting이 된다는-.-

  • BlackCat

    일단 첫번째 toString()에 if 문을 보시면 = 가 하나입니다.. 2개가 되어야 if가 되겠죠..?

  • 빛나라

    아.. 제 컴퓨터가 조금 많이 느립니다.. ㅈㅅ..

  • 새

    2번째 출력의 3번째 3번째 출력의 첫번째, 세번째 4번째 출력의 첫번째가 false로 해야하는건데요 어떻해 짜야할지..

  • 이퓨리한나

    이거 정확하게 뭘 어떻게 도와달라는건지 이해가...-ㅅ-;; 중간에 false가 되게하면 되는건가요..?

번호 제 목 글쓴이 날짜
2697284 이미지를 흐리게 (2) 난새 2025-06-06
2697258 VC++ 6.0(studio)을 깔면서 재미가 붙었는데..ㅠㅠ (4) 앵겨쪼 2025-06-06
2697228 WorkFlow가 궁금합니다.. 다들 어떻게 하시는지.. (1) 애기 2025-06-06
2697174 button 태그와 input 태그의 type 속성을 사용한거와 차이 (1) 여름 2025-06-05
2697149 익스플로러에서 이미지로딩이 느려지는건지..깨져서 나옵니다. (4) 든솔 2025-06-05
2697122 호환성질문 (5) 미즈 2025-06-05
2697066 웹에서 다른이름으로 저장 할때 파일 이름 저장하는 방법은? 코이 2025-06-04
2697043 position:absolute; 로 하면 사라져 버리는 이유 ㅠㅠ (3) 풍란 2025-06-04
2697016 테이블 thead tbody 질문 아란 2025-06-04
2696989 contact us 페이지는 dl로 작성하는게 좋을까요? (4) 파라 2025-06-03
2696964 img 태그 질문드려요 (9) 연블루 2025-06-03
2696907 [질문] 올플래시 메뉴 고정할수 있는[수정] (4) 맨삶이 2025-06-03
2696875 책구입 후 따라하다가 ShortCode Ultimate 오류 가지등 2025-06-02
2696844 css 마우스 오버시 display:block되는 영역 질문드립니다 ㅠㅠ (2) 갅쥐누뉨 2025-06-02
2696816 엉엉엉...영상이 올라타네요 (5) 다은 2025-06-02
2696792 Doctype 문의 떠나간그녀 2025-06-02
2696683 컴파일된 클립 질문 드립니다. 흰추위 2025-06-01
2696656 C질문요 (4) 블랙캣 2025-05-31
2696504 플래시 위에 div 올리기 (5) 큰꽃늘 2025-05-30
2696458 제가 만든 소스 한번 봐주시고 수정 할 꺼 있으면 말해주세요. (실행은 되지만 깜빡거리네요) 이플 2025-05-29
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com