[질문] array의 출력을 하는데에서..
별하
책 제목하고 저자를 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();
}
}
-
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가 되게하면 되는건가요..?