수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • 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가 되게하면 되는건가요..?

번호 제 목 글쓴이 날짜
2704551 HTML5 질문이요 (1) 마루한 2025-08-11
2704491 자바스크립트 인강 괜찮은 곳 아시는분?? (5) 이플 2025-08-10
2704465 C질문 다시 애기 2025-08-10
2704437 출근후 파폭을 6.0으로 업뎃할거냐는 메세지가 나오길래... (3) 마호 2025-08-10
2704383 max-width , min-width, width 세 녀석 관련 질문드립니다. (1) 다와 2025-08-09
2704356 이번 과제로 성적관리 프로그램을 작성해야 하는데... (3) 칸나 2025-08-09
2704305 캐릭터 방향 전환에 대해서 질문합니다. (4) 우수리 2025-08-09
2704276 센터정렬 사이트에서의 정렬문제 (3) 새론 2025-08-08
2704219 충돌감지에 대한 질문입니다. (액션 3.0) (1) 화이티 2025-08-08
2704192 hover 이미지 적용시에..IE에서는 hover 후 원래대로 돌아가지를 않습니다. (2) 민아 2025-08-08
2704135 레이어있는 문서가 뒤로가기버튼 누르면 레이어가 안생깁니다. (4) 개구리 2025-08-07
2704113 왕초보 질문합니다. (3) 민들레 2025-08-07
2704084 스타일시트를 찾을 수 없다고 나오면서 테마 설치가 안되네요 ;; 다힘 2025-08-07
2704026 혼자서 코딩하구있어요 select박스질문입니닷! (4) 콩알눈 2025-08-06
2704000 button value="" 값 css로 수정관련 (2) 꼬붕 2025-08-06
2703971 접근성에 맞는dtd선언하기 (2) 하루 2025-08-06
2703917 div코딩 어느 해상도에서도 중앙정렬문의!!ㅠㅠ 해긴 2025-08-05
2703887 미치겠습니다. 테마 등록, 강남맨 2025-08-05
2703862 아바다 테마 사용도중 질문 드려요~! 모은 2025-08-05
2703831 자바에서 애프릿이랑 어플리케이션 같이쓸때 창 닫는법 (1) 소리 2025-08-04
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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