Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package problema3;
- import java.util.ArrayList;
- import java.util.List;
- public class Produs {
- private double pret, cantitate;
- private String nume;
- private static List<Produs> listaPretMax = new ArrayList<Produs>();
- private static List<Produs> listaPretMin = new ArrayList<Produs>();
- public Produs(String nume, double pret, double cantitate) {
- this.cantitate = cantitate;
- this.nume = nume;
- this.pret = pret;
- if (listaPretMin.isEmpty() || pret < listaPretMin.get(0).pret) {
- listaPretMin.clear();
- listaPretMin.add(this);
- } else if (pret == listaPretMin.get(0).pret)
- listaPretMin.add(this);
- if (listaPretMax.isEmpty() || pret > listaPretMax.get(0).pret) {
- listaPretMax.clear();
- listaPretMax.add(this);
- } else if (pret == listaPretMax.get(0).pret)
- listaPretMax.add(this);
- }
- public static List<Produs> getMin() {
- return listaPretMin;
- }
- public static List<Produs> getMax() {
- return listaPretMax;
- }
- public String toString() {
- return String.format("%-10s%-10.2f%-10.2f", nume, pret, cantitate);
- }
- public boolean CompareCantitatea(double cantitateData) {
- return cantitate <= cantitateData;
- }
- }
Add Comment
Please, Sign In to add comment