[Java] 184-书单类 →→→→→进入此内容的聊天室

来自 , 2021-01-24, 写在 Java, 查看 108 次.
URL http://www.code666.cn/view/54f5f407
  1. import java.util.*;
  2. import java.text.DateFormat;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5.  
  6. public class Main {
  7.         public static void main(String[] args)
  8.         {
  9.                 Scanner s = new Scanner(System.in);
  10.  
  11.                 BookList bl = new BookList();
  12.                 int n = s.nextInt();
  13.                 for (int i=0; i<n;i++) {
  14.                         bl.addBook(new Book(s.next(),s.nextInt(),s.next(),s.nextInt()));
  15.                 }              
  16.                 bl.searchBook(new Book(s.next(),0,s.next(),s.nextInt()));
  17.    }
  18. }
  19. class Book
  20. {
  21.         private String name;
  22.         private int price;
  23.         private String author;
  24.         private int no;
  25.         public Book(String n, int p , String a, int o)
  26.         {
  27.                 name = n;
  28.                 price = p;
  29.                 author = a;
  30.                 no = o;
  31.         }
  32.         public String getname()
  33.         {
  34.                 return name;
  35.         }
  36.         public int getprice()
  37.         {
  38.                 return price;
  39.         }
  40.         public String getauthor()
  41.         {
  42.                 return author;
  43.         }
  44.         public int getno()
  45.         {
  46.                 return no;
  47.         }
  48. }
  49. class BookList
  50. {
  51.         List<Book>  slist;
  52.         public BookList()
  53.         {
  54.                 slist = new ArrayList<Book>();
  55.         }
  56.         public void addBook(Book b)
  57.         {
  58.                 slist.add(b);
  59.         }
  60.         public void searchBook(Book b)
  61.         {
  62.                 int flag = 0;
  63.                 for( int j = 0; j < slist.size(); j++)
  64.         {
  65.             if(slist.get(j).getname().equals(b.getname()) && slist.get(j).getauthor().equals(b.getauthor()) && slist.get(j).getno() == b.getno())
  66.             {
  67.                 System.out.print("found: "+j);
  68.                 flag = 1 ;
  69.             }
  70.         }
  71.                 if( flag== 0)
  72.                 {
  73.                         System.out.print("not found");
  74.                 }
  75.         }
  76. }

回复 "184-书单类"

这儿你可以回复上面这条便签

captcha