나는 ISBN, 저자, 제목과 책의 수준을 인쇄코드에서 ArrayList 문제, 어떤 조언을?
시작 왼쪽 책 제목의 이름으로 ISBN 번호를 변경하는 데 문제가 :
0201403765 Jan Skansholm Ada 95 from the Beginning 100
0202535665 M. Ben-Ari Software Engineering 25
034565976X Michael Feldman Program Construction 12
080539057X M.A. Weiss Data Structures 30
0805645782 Ken Arnold Java for Programmers 10
0905297568 A. Badone Chaos Theory 15
인쇄합니다 뭐죠에서 transactions.txt
:
0201403765 -55
0201403765 2
0202535665 10
0202535665 -28
034565976X -7
080539057X -15
0905297568 13
0905297568 -5
그래서 기본적으로 내가해야 할 일이 일치하는 경우이처럼에 책의 제목을 ISBN을 변경할 수있다
Java from the Beginning -55
Java from the Beginning 2
Software Engineering 10
Software Engineering -28
Program Construction -7
Data Structures -15
Chaos Theory 13
Chaos Theory -5
im은 아래 코드에 1로 표시되어 있습니다. isbn이 일치하는지 확인하는 방법이 정말 불확실합니다. 그렇다면 isbn과 일치하는 제목을 확인하고 작성하는 방법은 내 문제가 arraylist라고 생각합니다. (나는 세 번째 arraylist를 만들어야 만한다.) 배열로 모든 것을 만들면 어떤 충고라도 할 것이다.
class Book {
public final String isbn;
public final String title;
public final String author;
public final int level;
public Book(String isbn, String title, String author, int level) {
this.isbn = isbn; this.title = title; this.author = author; this.level = level;
}
}
및 예약 물체로 ArrayList를 채울 : BTW 1
import java.util.*;
import java.io.*;
class inventory{
static void intial(){
try{
RandomAccessFile in = new RandomAccessFile("books.dat","r");
ArrayList<String> list1=new ArrayList<String>();
String author ,title , isbn;
int level=0;
while(in.getFilePointer()<in.length()){
author = in.readUTF(); // author, at most 20 characters
title = in.readUTF(); // title, at most 40 characters
isbn = in.readUTF(); // ISBN
level = in.readInt(); // level, i.e. copies in stock (>=0)
//System.out.printf("%5d", isbn+author+title+level);
System.out.println(isbn+" "+author+" "+title+" "+level);
list1.add(title);
list1.add(isbn);
//list1.add(level);
}
in.close();
System.out.println(" ");
String isbn2;
int level2=0;
//try{
Scanner out = new Scanner(new File ("transactions.txt"));
ArrayList<String> list2=new ArrayList<String>();
while(out.hasNextLine()){
isbn2 = out.next();
level2 = out.nextInt();
System.out.println(isbn2 +" "+level2);
list2.add(isbn2);
//list2.add(level2);
}
out.close();
1) for (isbn: list1){
for(isbn2: list2){
if(isbn.contains(isbn2)){
System.out.println(title+" "+level);
}
}
}
}
catch(IOException f){
System.out.println("file error");
f.printStackTrace();
}
}
}
class BookShop{
public static void main(String[]args){
inventory x = new inventory();
x.intial();
들여 쓰기 BTW –
내 눈 –
그래서 들여 쓰기를 수정 ... 상처 꺼져 – MByD