/* * 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 projekt; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import projekt.Classes.aboutPrinter.toner; import static projekt.Classes.aboutPrinter.toner.black; import static projekt.Classes.aboutPrinter.toner.blue; import static projekt.Classes.aboutPrinter.toner.green; import static projekt.Classes.aboutPrinter.toner.yellow; /** * * @author adacze */ public class Classes { static class device{ private int Id; private String name; private boolean efficient; private String type; public void setId(int Id){ this.Id = Id; } public int getId(){ return this.Id; } public void setName(String name){ this.name = name; } public String getName(){ return this.name; } public void setEfficient(boolean efficient){ this.efficient = efficient; } public boolean getEfficient(){ return this.efficient; } public void setType(String type){ this.type = type; } public String getType(){ return type; } public void Constructor(int id, String name, boolean efficient){ setId(id); setName(name); setEfficient(efficient); } } static class computer extends device{ private String model; private String type = "computer"; device computer = new device(); public void setModel(String model){ this.model = model; } public String getModel(){ return this.model; } public void Constructor(int id, String name, boolean efficient, String ComputerModel, String type){ computer.setId(id); computer.setType(type); computer.setName(name); computer.setEfficient(efficient); setModel(ComputerModel); } } static class aboutComputer extends computer{ private int ram; computer computer = new computer(); public void setRam(int ram){ this.ram = ram; } public int getRam(){ return this.ram; } public void Constructor(int id, String name, boolean efficient, String ComputerModel, int ram){ computer.computer.setId(id); computer.computer.setName(name); computer.computer.setEfficient(efficient); computer.setModel(ComputerModel); setRam(ram); } } static class historyComputer extends aboutComputer{ private String FV; private String type = "computer"; aboutComputer computer = new aboutComputer(); public void setFV(String FV){ this.FV = FV; } public String getFV(){ return this.FV; } public void Constructor(int id, String name, boolean efficient, String ComputerModel, int ram,String FV){ computer.computer.computer.setId(id); computer.computer.computer.setName(name); computer.computer.computer.setEfficient(efficient); computer.computer.computer.setType(type); computer.computer.setModel(ComputerModel); setRam(ram); setFV(FV); } public String toString(){ return computer.computer.computer.getId() + " " + computer.computer.computer.getName() + " " + computer.computer.computer.getEfficient() + " " + computer.computer.getModel() + " " + getRam() + " " + getFV() +"\n"; } } static class printer extends device{ private String model; private String type = "printer"; device printer = new device(); public void setModel(String model){ this.model = model; } public String getModel(){ return this.model; } public String getType(){ return type; } public void Constructor(int id, String name, boolean efficient, String PrinterModel){ printer.setId(id); printer.setName(name); printer.setEfficient(efficient); setModel(PrinterModel); } } static class aboutPrinter extends printer{ public toner toner; public enum toner{ black,yellow,blue,green; } printer printer = new printer(); public void setToner(toner t){ this.toner = t; } public toner getToner(){ return this.toner; } public void Constructor(int id, String name, boolean efficient, String PrinterModel, toner toner){ printer.printer.setId(id); printer.printer.setName(name); printer.printer.setEfficient(efficient); printer.setModel(PrinterModel); setToner(toner); } } static class historyPrinter extends aboutPrinter{ private String FV; private String type = "printer"; aboutPrinter printer = new aboutPrinter(); public void setFV(String FV){ this.FV = FV; } public String getFV(){ return this.FV; } public void Constructor(int id, String name, boolean efficient, String model, toner toner,String FV){ printer.printer.printer.setId(id); printer.printer.printer.setName(name); printer.printer.printer.setEfficient(efficient); printer.printer.printer.setType(type); printer.printer.setModel(model); setToner(toner); setFV(FV); } public String toString(){ return printer.printer.printer.getId() + " " + printer.printer.printer.getName() + " " + printer.printer.printer.getEfficient() + " " + printer.printer.getModel() + " " + getToner() + " " + getFV() + "\n"; } } public static void main(String[] args){ List urzadzenia = new ArrayList(); //samolot1.Constructor(1000,"f16",2); //Plane samolot2 = new Plane(); //samolot2.Constructor(1500,"f15",2); Scanner scan = new Scanner(System.in); int id = 0; String name; boolean efficient; String model; int ram; String FV; String toner; toner color; int option; do{ System.out.print("Co chcesz zeobić?\n1 - dodaj komputer\n2 - dodaj drukarkę\n3 - wyświetl wszystkie urządzenia\n4 - wyświetl drukarki\n5 - wyświetl komputery\n6 - szukaj\n7 - usuń urządzenie\n"); option = Integer.parseInt(scan.nextLine()); switch(option){ case 1: historyComputer computer = new historyComputer(); System.out.print("Podaj ID\n"); id = Integer.parseInt(scan.nextLine()); if(urzadzenia != null){ if(urzadzenia.contains(id)){ System.out.print("To ID jest już zajęte!\n"); break; } } System.out.print("Podaj nazwę\n"); name = scan.nextLine(); System.out.print("Czy sprawne? 1 -tak, 2 - nie\n"); String eff = scan.nextLine(); if(eff == "1") {efficient = true;} else{efficient = false;} System.out.print("Podaj model\n"); model = scan.nextLine(); System.out.print("Ile ramu?\n"); ram = Integer.parseInt(scan.nextLine()); System.out.print("Podaj numer FV\n"); FV = scan.nextLine(); computer.Constructor(id, name, efficient, model, ram, FV); urzadzenia.add(computer); break; case 2: System.out.print("Podaj ID\n"); id = Integer.parseInt(scan.nextLine()); if(urzadzenia != null){ if(urzadzenia.contains(id)){ System.out.print("To ID jest już zajęte!\n"); break; } } System.out.print("Podaj nazwę\n"); name = scan.nextLine(); System.out.print("Czy sprawne? 1 -tak, 2 - nie\n"); String effP = scan.nextLine(); if(effP == "1") {efficient = true;} else{efficient = false;} System.out.print("Podaj model\n"); model = scan.nextLine(); System.out.print("Jaki toner? zielony/żółty/niebieski/czarny\n"); toner = scan.nextLine(); switch(toner){ case "zielony": color = green; case "żółty": color = yellow; case "niebieski": color = blue; default: color = black; } System.out.print("Podaj numer FV\n"); FV = scan.nextLine(); historyPrinter newPrinter = new historyPrinter(); newPrinter.Constructor(id, name, efficient, model, color, FV); urzadzenia.add(newPrinter); break; case 3: for(device d: urzadzenia){ System.out.print(d.toString()); } break; case 4: for(device d: urzadzenia){ if(d.getType() == "printer") System.out.print(d.toString()); } break; case 5: for(device d: urzadzenia){ if(d.getType() == "computer") System.out.print(d.toString()); } break; case 6: System.out.print("Wpisz szukaną frazę\n"); String search = scan.nextLine(); for(device d: urzadzenia){ String o = d.getName(); System.out.print(d.getName()); if(o == search) System.out.print(d.toString()); } break; case 7: System.out.print("Wpisz ID usuwanego urządzenia\n"); String delete = scan.nextLine(); for(device d: urzadzenia){ if(d.getId() == Integer.parseInt(delete)){ urzadzenia.remove(d); } } break; } } while(option != 9); } }