Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. package com.company;
  2. import java.io.*;
  3. import java.util.*;
  4. class Gyumolcsok
  5. {
  6.     String t_e;
  7.     String nev;
  8.     double ar;
  9.     String egyseg;
  10.     int szavatossag;
  11.     int darab;
  12.  
  13.     public Gyumolcsok(String t_e, String nev, double ar, String egyseg, int szavatossag, int darab) {
  14.         this.t_e = t_e;
  15.         this.nev = nev;
  16.         this.ar = ar;
  17.         this.egyseg = egyseg;
  18.         this.szavatossag = szavatossag;
  19.         this.darab = darab;
  20.     }
  21.  
  22.     public Gyumolcsok(String t_e, String nev, double ar, String egyseg, int darab) {
  23.         this.t_e = t_e;
  24.         this.nev = nev;
  25.         this.ar = ar;
  26.         this.egyseg = egyseg;
  27.         this.darab = darab;
  28.     }
  29.  
  30.     @Override
  31.     public String toString() {
  32.  
  33.       if (t_e.equals("E"))
  34.         return "Gyumolcsok{" +
  35.                 "t_e='" + t_e + '\'' +
  36.                 ", nev='" + nev + '\'' +
  37.                 ", ar=" + ar +
  38.                 ", egyseg='" + egyseg + '\'' +
  39.                 ", szavatossag=" + szavatossag +
  40.                 ", darab=" + darab +
  41.                 '}';
  42.       return "Gyumolcsok{" +
  43.               "t_e='" + t_e + '\'' +
  44.               ", nev='" + nev + '\'' +
  45.               ", ar=" + ar +
  46.               ", egyseg='" + egyseg + '\'' +
  47.  
  48.               ", darab=" + darab +
  49.               '}';
  50.     }
  51. }
  52.  
  53. public class Main {
  54.  
  55.     public static void main(String[] args) throws IOException {
  56.     // write your code here
  57.         List<Gyumolcsok> lista  = new ArrayList<Gyumolcsok>();
  58.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  59.         String line;
  60.         while((line=br.readLine())!=null)
  61.         {
  62.             String[] token =line.split(";");
  63.             int k=-1;
  64.             if(token[0].equals("E"))
  65.             {
  66.                 Gyumolcsok e = new Gyumolcsok(token[0],token[1],Double.parseDouble(token[2]),token[3],Integer.parseInt(token[4]),Integer.parseInt(token[5]));
  67.  
  68.                 for (int i = 0; i < lista.size(); i++) {
  69.                     if(lista.get(i).nev.equals(e.nev))
  70.                     {
  71.                         k=i;
  72.                         break;
  73.                     }
  74.                 }
  75.                 if(k!=-1)
  76.                 {
  77.  
  78.                     lista.get(k).darab+=Integer.parseInt(token[5]);
  79.                 }
  80.                 else
  81.                 {
  82.                     lista.add(e);
  83.                 }
  84.             }
  85.             if(token[0].equals("T"))
  86.             {
  87.                 Gyumolcsok t = new Gyumolcsok(token[0],token[1],Double.parseDouble(token[2]),token[3],Integer.parseInt(token[4]));
  88.                 for (int i = 0; i < lista.size(); i++) {
  89.                     if(lista.get(i).nev.equals(t.nev))
  90.                     {
  91.                         k=i;
  92.                         break;
  93.                     }
  94.                 }
  95.                 if(k!=-1)
  96.                 {
  97.  
  98.                     lista.get(k).darab+=Integer.parseInt(token[4]);
  99.                 }
  100.                 else
  101.                 {
  102.                     lista.add(t);
  103.                 }
  104.             }
  105.         }
  106.         for (Gyumolcsok i:
  107.              lista) {
  108.             System.out.println(i);
  109.         }
  110.  
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement