Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package auto2;
- import java.util.Arrays;
- import java.util.Objects;
- import java.util.Scanner;
- import oracle.jrockit.jfr.events.Bits;
- /**
- *
- * @author Isaackar
- */
- public class Auto implements Comparable<Auto>{
- private String rendszám;
- private int teljesítmény;
- private boolean automata;
- public Auto(String rendszám, int teljesítmény, boolean automata) {
- this.rendszám = rendszám;
- this.teljesítmény = teljesítmény;
- this.automata = automata;
- }
- public String getRendszám() {
- return rendszám;
- }
- public int getTeljesítmény() {
- return teljesítmény;
- }
- public boolean isAutomata() {
- return automata;
- }
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("rendszám: ").append(rendszám).append(", teljesítmény: ").append(teljesítmény).append(" lóerő, autómata: ").append(automata);
- return sb.toString();
- }
- @Override
- public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof Auto)) {
- return false;
- }
- Auto a = (Auto) obj;
- return this.rendszám==a.rendszám;
- }
- @Override
- public int compareTo(Auto o) {
- if(this.teljesítmény!=o.teljesítmény){
- return this.teljesítmény-o.teljesítmény;
- }
- return(this.rendszám).compareTo(o.rendszám);
- }
- //11.feladat
- public boolean szabalyos () {
- // if(rendszám.length()==6 &&
- 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
- && Character.isDigit(rendszám.indexOf(3))==true && Character.isDigit(rendszám.indexOf(4))==true && Character.isDigit(rendszám.indexOf(5))==true);
- {
- return true;
- }
- // return false;
- }
- }
- /////////Teherautó///////////
- class Teherauto extends Auto{
- private double teherbiras;
- public Teherauto(String rendszám, int teljesítmény, boolean automata, double teherbiras) {
- super(rendszám, teljesítmény, automata);
- this.teherbiras=teherbiras;
- }
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("rendszám: ").append(getRendszám()).append(", teljesítménye: ").append(getTeljesítmény()).append(" lóerő, rendszáma: ");
- sb.append(getRendszám()).append(", teherbírása: ").append(teherbiras);
- return sb.toString();
- }
- /////////MAIN///////////////////
- public static void main(String[] args) {
- Auto a = new Auto("HA408",100, true);
- System.out.println(a);
- System.out.println(a.szabalyos());
- Scanner sc = new Scanner(System.in);
- System.out.println("Adja meg a darab számot: ");
- int db=sc.nextInt();
- String[] line;
- Auto[] t = new Auto[db];
- String l = sc.nextLine();
- for(int i=0; i<db ;i++)
- {
- line=sc.nextLine().split(" ");
- if(line[0].equals("Auto"))
- t[i]=new Auto(line[1],Integer.parseInt(line[2]),Boolean.parseBoolean(line[3]));
- else
- t[i]=new Teherauto(line[0],Integer.parseInt(line[1]),Boolean.parseBoolean(line[2]),Double.parseDouble(line[3]));
- }
- Arrays.sort(t);
- for(Auto o:t){
- System.out.println(o);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement