Facebook
From Walloping Crane, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 34
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package projekt;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Scanner;
  11. import projekt.Classes.aboutPrinter.toner;
  12. import static projekt.Classes.aboutPrinter.toner.black;
  13. import static projekt.Classes.aboutPrinter.toner.blue;
  14. import static projekt.Classes.aboutPrinter.toner.green;
  15. import static projekt.Classes.aboutPrinter.toner.yellow;
  16.  
  17. /**
  18.  *
  19.  * @author adacze
  20.  */
  21. public class Classes {
  22.     static class device{
  23.         private int Id;
  24.         private String name;
  25.         private boolean efficient;
  26.         private String type;
  27.        
  28.         public void setId(int Id){
  29.             this.Id = Id;
  30.         }  
  31.         public int getId(){
  32.             return this.Id;
  33.         }
  34.         public void setName(String name){
  35.             this.name = name;
  36.         }  
  37.         public String getName(){
  38.             return this.name;
  39.         }
  40.         public void setEfficient(boolean efficient){
  41.             this.efficient = efficient;
  42.         }  
  43.         public boolean getEfficient(){
  44.             return this.efficient;
  45.         }
  46.         public void setType(String type){
  47.             this.type = type;
  48.         }
  49.         public String getType(){
  50.             return type;
  51.         }
  52.        
  53.        
  54.         public void Constructor(int id, String name, boolean efficient){
  55.             setId(id);
  56.             setName(name);
  57.             setEfficient(efficient);
  58.         }
  59.     }
  60.     static class computer extends device{
  61.         private String model;
  62.         private String type = "computer";
  63.         device computer = new device();
  64.         public void setModel(String model){
  65.             this.model = model;
  66.         }  
  67.         public String getModel(){
  68.             return this.model;
  69.         }
  70.        
  71.         public void Constructor(int id, String name, boolean efficient, String ComputerModel, String type){
  72.             computer.setId(id);
  73.             computer.setType(type);
  74.             computer.setName(name);
  75.             computer.setEfficient(efficient);
  76.             setModel(ComputerModel);
  77.         }
  78.     }
  79.    
  80.     static class aboutComputer extends computer{
  81.         private int ram;
  82.         computer computer = new computer();
  83.        
  84.         public void setRam(int ram){
  85.             this.ram = ram;
  86.         }
  87.        
  88.         public int getRam(){
  89.             return this.ram;
  90.         }
  91.        
  92.         public void Constructor(int id, String name, boolean efficient, String ComputerModel, int ram){
  93.             computer.computer.setId(id);
  94.             computer.computer.setName(name);
  95.             computer.computer.setEfficient(efficient);
  96.             computer.setModel(ComputerModel);
  97.             setRam(ram);
  98.         }
  99.     }
  100.    
  101.     static class historyComputer extends aboutComputer{
  102.         private String FV;
  103.         private String type = "computer";
  104.         aboutComputer computer = new aboutComputer();
  105.        
  106.         public void setFV(String FV){
  107.             this.FV = FV;
  108.         }
  109.         public String getFV(){
  110.             return this.FV;
  111.         }
  112.        
  113.         public void Constructor(int id, String name, boolean efficient, String ComputerModel, int ram,String FV){
  114.             computer.computer.computer.setId(id);
  115.             computer.computer.computer.setName(name);
  116.             computer.computer.computer.setEfficient(efficient);
  117.             computer.computer.computer.setType(type);
  118.             computer.computer.setModel(ComputerModel);
  119.             setRam(ram);
  120.             setFV(FV);
  121.         }
  122.        
  123.         public String toString(){
  124.             return computer.computer.computer.getId() + " " + computer.computer.computer.getName() + " " + computer.computer.computer.getEfficient() + " " + computer.computer.getModel() + " " + getRam() + " " + getFV() +"\n";
  125.         }
  126.     }
  127.    
  128.     static class printer extends device{
  129.         private String model;
  130.         private String type = "printer";
  131.        
  132.         device printer = new device();
  133.        
  134.         public void setModel(String model){
  135.             this.model = model;
  136.         }  
  137.         public String getModel(){
  138.             return this.model;
  139.         }
  140.         public String getType(){
  141.             return type;
  142.         }
  143.        
  144.         public void Constructor(int id, String name, boolean efficient, String PrinterModel){
  145.             printer.setId(id);
  146.             printer.setName(name);
  147.             printer.setEfficient(efficient);
  148.             setModel(PrinterModel);
  149.         }
  150.     }
  151.    
  152.     static class aboutPrinter extends printer{
  153.  
  154.         public toner toner;
  155.        
  156.         public enum toner{
  157.             black,yellow,blue,green;
  158.         }
  159.        
  160.         printer printer = new printer();
  161.        
  162.         public void setToner(toner t){
  163.             this.toner = t;
  164.         }
  165.        
  166.         public toner getToner(){
  167.             return this.toner;
  168.         }
  169.        
  170.         public void Constructor(int id, String name, boolean efficient, String PrinterModel, toner toner){
  171.             printer.printer.setId(id);
  172.             printer.printer.setName(name);
  173.             printer.printer.setEfficient(efficient);
  174.             printer.setModel(PrinterModel);
  175.             setToner(toner);
  176.         }
  177.     }
  178.    
  179.     static class historyPrinter extends aboutPrinter{
  180.         private String FV;
  181.         private String type = "printer";
  182.        
  183.         aboutPrinter printer = new aboutPrinter();
  184.        
  185.         public void setFV(String FV){
  186.             this.FV = FV;
  187.         }
  188.         public String getFV(){
  189.             return this.FV;
  190.         }
  191.        
  192.         public void Constructor(int id, String name, boolean efficient, String model, toner toner,String FV){
  193.             printer.printer.printer.setId(id);
  194.             printer.printer.printer.setName(name);
  195.             printer.printer.printer.setEfficient(efficient);
  196.             printer.printer.printer.setType(type);
  197.             printer.printer.setModel(model);
  198.             setToner(toner);
  199.             setFV(FV);
  200.         }
  201.        
  202.         public String toString(){
  203.             return printer.printer.printer.getId() + " " + printer.printer.printer.getName() + " " + printer.printer.printer.getEfficient() + " " + printer.printer.getModel() + " " + getToner() + " " + getFV() + "\n";
  204.         }
  205.     }
  206.    
  207.     public static void main(String[] args){
  208.             List<device> urzadzenia = new ArrayList<device>();
  209.            
  210.             //samolot1.Constructor(1000,"f16",2);
  211.             //Plane samolot2 = new Plane();
  212.             //samolot2.Constructor(1500,"f15",2);
  213.             Scanner scan = new Scanner(System.in);
  214.            
  215.             int id = 0;
  216.             String name;
  217.             boolean efficient;
  218.             String model;
  219.             int ram;
  220.             String FV;
  221.             String toner;
  222.             toner color;
  223.             int option;
  224.            
  225.             do{
  226.                
  227.             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");
  228.             option = Integer.parseInt(scan.nextLine());
  229.            
  230.             switch(option){
  231.         case 1:
  232.             historyComputer computer = new historyComputer();
  233.             System.out.print("Podaj ID\n");
  234.             id = Integer.parseInt(scan.nextLine());
  235.             if(urzadzenia != null){
  236.                 if(urzadzenia.contains(id)){
  237.                     System.out.print("To ID jest już zajęte!\n");
  238.                     break;
  239.             }
  240.             }
  241.                
  242.             System.out.print("Podaj nazwę\n");
  243.             name = scan.nextLine();
  244.             System.out.print("Czy sprawne? 1 -tak, 2 - nie\n");
  245.             String eff = scan.nextLine();
  246.             if(eff == "1") {efficient = true;}
  247.             else{efficient = false;}
  248.             System.out.print("Podaj model\n");
  249.             model = scan.nextLine();
  250.             System.out.print("Ile ramu?\n");
  251.             ram = Integer.parseInt(scan.nextLine());
  252.             System.out.print("Podaj numer FV\n");
  253.             FV = scan.nextLine();
  254.             computer.Constructor(id, name, efficient, model, ram, FV);
  255.             urzadzenia.add(computer);
  256.             break;
  257.         case 2:
  258.            
  259.             System.out.print("Podaj ID\n");
  260.             id = Integer.parseInt(scan.nextLine());
  261.                 if(urzadzenia != null){
  262.                 if(urzadzenia.contains(id)){
  263.                     System.out.print("To ID jest już zajęte!\n");
  264.                     break;
  265.             }
  266.             }
  267.             System.out.print("Podaj nazwę\n");
  268.             name = scan.nextLine();
  269.             System.out.print("Czy sprawne? 1 -tak, 2 - nie\n");
  270.             String effP = scan.nextLine();
  271.             if(effP == "1") {efficient = true;}
  272.             else{efficient = false;}
  273.             System.out.print("Podaj model\n");
  274.             model = scan.nextLine();
  275.             System.out.print("Jaki toner? zielony/żółty/niebieski/czarny\n");
  276.             toner = scan.nextLine();
  277.                 switch(toner){
  278.                     case "zielony":
  279.                         color = green;
  280.                     case "żółty":
  281.                         color = yellow;
  282.                     case "niebieski":
  283.                         color = blue;
  284.                     default:
  285.                         color = black;
  286.                 }
  287.             System.out.print("Podaj numer FV\n");
  288.             FV = scan.nextLine();
  289.            
  290.             historyPrinter newPrinter = new historyPrinter();
  291.  
  292.             newPrinter.Constructor(id, name, efficient, model, color, FV);
  293.             urzadzenia.add(newPrinter);
  294.             break;
  295.         case 3:
  296.             for(device d: urzadzenia){
  297.                 System.out.print(d.toString());
  298.             }
  299.             break;
  300.         case 4:
  301.             for(device d: urzadzenia){
  302.                 if(d.getType() == "printer")
  303.                 System.out.print(d.toString());
  304.             }
  305.             break;
  306.         case 5:
  307.             for(device d: urzadzenia){
  308.                 if(d.getType() == "computer")
  309.                 System.out.print(d.toString());
  310.             }
  311.             break;
  312.         case 6:
  313.             System.out.print("Wpisz szukaną frazę\n");
  314.             String search = scan.nextLine();
  315.             for(device d: urzadzenia){
  316.                 String o = d.getName();
  317.                 System.out.print(d.getName());
  318.                 if(o == search) System.out.print(d.toString());
  319.             }
  320.             break;
  321.         case 7:
  322.             System.out.print("Wpisz ID usuwanego urządzenia\n");
  323.             String delete = scan.nextLine();
  324.         for(device d: urzadzenia){
  325.                 if(d.getId() == Integer.parseInt(delete)){
  326.                     urzadzenia.remove(d);
  327.                 }
  328.             }
  329.         break;
  330.         }
  331.             }
  332.             while(option != 9);
  333. }
  334. }
  335.