Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.*;
- class Gyumolcsok
- {
- String t_e;
- String nev;
- double ar;
- String egyseg;
- int szavatossag;
- int darab;
- public Gyumolcsok(String t_e, String nev, double ar, String egyseg, int szavatossag, int darab) {
- this.t_e = t_e;
- this.nev = nev;
- this.ar = ar;
- this.egyseg = egyseg;
- this.szavatossag = szavatossag;
- this.darab = darab;
- }
- public Gyumolcsok(String t_e, String nev, double ar, String egyseg, int darab) {
- this.t_e = t_e;
- this.nev = nev;
- this.ar = ar;
- this.egyseg = egyseg;
- this.darab = darab;
- }
- @Override
- public String toString() {
- if (t_e.equals("E"))
- return "Gyumolcsok{" +
- "t_e='" + t_e + '\'' +
- ", nev='" + nev + '\'' +
- ", ar=" + ar +
- ", egyseg='" + egyseg + '\'' +
- ", szavatossag=" + szavatossag +
- ", darab=" + darab +
- '}';
- return "Gyumolcsok{" +
- "t_e='" + t_e + '\'' +
- ", nev='" + nev + '\'' +
- ", ar=" + ar +
- ", egyseg='" + egyseg + '\'' +
- ", darab=" + darab +
- '}';
- }
- }
- public class Main {
- public static void main(String[] args) throws IOException {
- // write your code here
- List<Gyumolcsok> lista = new ArrayList<Gyumolcsok>();
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String line;
- while((line=br.readLine())!=null)
- {
- String[] token =line.split(";");
- int k=-1;
- if(token[0].equals("E"))
- {
- Gyumolcsok e = new Gyumolcsok(token[0],token[1],Double.parseDouble(token[2]),token[3],Integer.parseInt(token[4]),Integer.parseInt(token[5]));
- for (int i = 0; i < lista.size(); i++) {
- if(lista.get(i).nev.equals(e.nev))
- {
- k=i;
- break;
- }
- }
- if(k!=-1)
- {
- lista.get(k).darab+=Integer.parseInt(token[5]);
- }
- else
- {
- lista.add(e);
- }
- }
- if(token[0].equals("T"))
- {
- Gyumolcsok t = new Gyumolcsok(token[0],token[1],Double.parseDouble(token[2]),token[3],Integer.parseInt(token[4]));
- for (int i = 0; i < lista.size(); i++) {
- if(lista.get(i).nev.equals(t.nev))
- {
- k=i;
- break;
- }
- }
- if(k!=-1)
- {
- lista.get(k).darab+=Integer.parseInt(token[4]);
- }
- else
- {
- lista.add(t);
- }
- }
- }
- for (Gyumolcsok i:
- lista) {
- System.out.println(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement