Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.74 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 auto2;
  7.  
  8. import java.util.Arrays;
  9. import java.util.Objects;
  10. import java.util.Scanner;
  11. import oracle.jrockit.jfr.events.Bits;
  12.  
  13. /**
  14.  *
  15.  * @author Isaackar
  16.  */
  17. public class Auto implements Comparable<Auto>{
  18.    
  19.     private String rendszám;
  20.     private int teljesítmény;
  21.     private boolean automata;
  22.  
  23.     public Auto(String rendszám, int teljesítmény, boolean automata) {
  24.         this.rendszám = rendszám;
  25.         this.teljesítmény = teljesítmény;
  26.         this.automata = automata;
  27.     }
  28.  
  29.     public String getRendszám() {
  30.         return rendszám;
  31.     }
  32.  
  33.     public int getTeljesítmény() {
  34.         return teljesítmény;
  35.     }
  36.  
  37.     public boolean isAutomata() {
  38.         return automata;
  39.     }
  40.  
  41.     @Override
  42.     public String toString() {
  43.         StringBuilder sb = new StringBuilder();
  44.         sb.append("rendszám: ").append(rendszám).append(", teljesítmény: ").append(teljesítmény).append(" lóerő, autómata: ").append(automata);
  45.         return sb.toString();
  46.     }
  47.  
  48.     @Override
  49.     public boolean equals(Object obj) {
  50.         if (obj == null || !(obj instanceof Auto)) {
  51.             return false;
  52.         }
  53.            
  54.             Auto a = (Auto) obj;
  55.             return this.rendszám==a.rendszám;
  56.     }  
  57.  
  58.     @Override
  59.     public int compareTo(Auto o) {
  60.         if(this.teljesítmény!=o.teljesítmény){
  61.       return this.teljesítmény-o.teljesítmény;
  62.     }
  63.         return(this.rendszám).compareTo(o.rendszám);
  64.                 }
  65.    
  66. //11.feladat    
  67. public boolean szabalyos () {
  68. //    if(rendszám.length()==6 &&
  69.             if (rendszám.length()==6 && Character.isLetter(rendszám.indexOf(0))==true && Character.isLetter(rendszám.indexOf(1))==true && Character.isLetter(rendszám.indexOf(2))==true
  70.        && Character.isDigit(rendszám.indexOf(3))==true && Character.isDigit(rendszám.indexOf(4))==true && Character.isDigit(rendszám.indexOf(5))==true);
  71.     {
  72.         return true;
  73.     }
  74.  
  75. //    return false;
  76. }
  77. }
  78. /////////Teherautó///////////
  79.  
  80. class Teherauto extends Auto{
  81.  
  82.     private double teherbiras;
  83.    
  84.     public Teherauto(String rendszám, int teljesítmény, boolean automata, double teherbiras) {
  85.         super(rendszám, teljesítmény, automata);
  86.         this.teherbiras=teherbiras;
  87.     }
  88.  
  89.     @Override
  90.     public String toString() {
  91.         StringBuilder sb = new StringBuilder();
  92.         sb.append("rendszám: ").append(getRendszám()).append(", teljesítménye: ").append(getTeljesítmény()).append(" lóerő, rendszáma: ");
  93.         sb.append(getRendszám()).append(", teherbírása: ").append(teherbiras);
  94.         return sb.toString();
  95.                
  96.     }
  97.    
  98.     /////////MAIN///////////////////
  99.    
  100.     public static void main(String[] args) {
  101.        
  102.         Auto a = new Auto("HA408",100, true);
  103.  
  104.         System.out.println(a);
  105.         System.out.println(a.szabalyos());
  106.    
  107.     Scanner sc = new Scanner(System.in);
  108.         System.out.println("Adja meg a darab számot: ");
  109.        
  110.     int db=sc.nextInt();
  111.     String[] line;
  112.     Auto[] t = new Auto[db];
  113.     String l = sc.nextLine();
  114.        
  115.     for(int i=0; i<db ;i++)
  116.     {  
  117.         line=sc.nextLine().split(" ");
  118.         if(line[0].equals("Auto"))
  119.             t[i]=new Auto(line[1],Integer.parseInt(line[2]),Boolean.parseBoolean(line[3]));
  120.         else
  121.             t[i]=new Teherauto(line[0],Integer.parseInt(line[1]),Boolean.parseBoolean(line[2]),Double.parseDouble(line[3]));
  122.     }
  123.     Arrays.sort(t);
  124.     for(Auto o:t){
  125.         System.out.println(o);
  126.     }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement