- <pre class="cpp" name="code"><img src="http://img.blog.csdn.net/20171130174554451" alt="">package Kuang;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Scanner;
- public class Test {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- List<Book> bookList = new ArrayList<Book>();
- bookList.add(new Book("英语", 29.99));
- bookList.add(new Book("数学", 50));
- bookList.add(new Book("化学", 30));
- bookList.add(new Book("生物", 30));
- bookList.add(new Book("历史", 30));
- System.out.println("请输入价格:\n");
- Book book = new Book("对比价格", 50);
- System.out.println(book.name + book.price);
- for (int i = 0; i < bookList.size(); i++
- /* Book books:bookList)*/)
- {
- if (book.compareTo(bookList.get(i)/*books*/) == 0)
- System.out.println((bookList.get(i)/*books*/.name));
- //+ (bookList.get(i)/*books*/.price)));
- }System.out.println("价格相同的:"+(book.price));
- // Map<Book> bookmap = new HashMap<Book>();
- // bookmap.put("english","18.5");
- // bookmap.put("math","18.5");
- // bookmap.put("chinese","18");
- // bookmap.put("生物","185");
- // bookmap.put("化学","15");
- // bookmap.put("历史","8.5");
- // System.out.println("请输入您要搜索的价格:\n");
- // Scanner input = new Scanner(System.in);
- }
- }</pre><br>
- package Kuang;public class Book implements Comparable<Book>{String name;Double price;public Book (String nm,double p){name=nm;price=p;}@Overridepublic int compareTo(Book o) {// TODO Auto-generated method stubreturn this.price.compareTo(o.price);}}
- <pre></pre>
- <br>
book
Posted 北有孤鹜
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了book相关的知识,希望对你有一定的参考价值。
以上是关于book的主要内容,如果未能解决你的问题,请参考以下文章