Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package MOTO;
  7. import java.util.*;
  8.  
  9. public class MOTO {
  10. String type;
  11. String color;
  12. int price;
  13.  
  14. public static Comparator obj = new Comparator(){
  15. @Override
  16. public int compare(Object t, Object t1) {
  17. MOTO m1 = (MOTO) t;
  18. MOTO m2 = (MOTO) t;
  19. int p = m1.price - m2.price;
  20. if (p>0) return 1;
  21. if (p==0) return m1.type.compareToIgnoreCase(m2.type);
  22. return -1;
  23. }
  24. };
  25. public MOTO(String type, String color, int price) {
  26. this.type = type;
  27. this.color = color;
  28. this.price = price;
  29. }
  30.  
  31. MOTO() {
  32. }
  33.  
  34.  
  35.  
  36.  
  37. @Override
  38. public String toString() {
  39. return type +" "+ color +" "+ price ;
  40. }
  41.  
  42. String getprice(){
  43. if(type.charAt(type.length()-1)=='N')
  44. return (price+"VND");
  45. return price+"USD";
  46.  
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement