Guest User

Untitled

a guest
May 26th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.76 KB | None | 0 0
  1. for(Object obiekt : kol){
  2.         System.out.println(obiekt);
  3.     }
  4.  
  5. Iterator i = kol.iterator();
  6.     while(i.hasNext()){
  7.         System.out.println(" "+ i.next());
  8.         }
  9.  
  10. ArrayList kol = new ArrayList();
  11.  
  12. String a;
  13.         a = JOptionPane.showInputDialog("Podaj pierwszy");
  14.  
  15. BufferedReader wczyt = new BufferedReader (new InputStreamReader(System.in));
  16.  
  17.  pom =wczyt.readLine();
  18.          liczba=Integer.parseInt(pom);
  19.  
  20. double pom = Double.parseDouble(args[0]);
  21.    
  22.      args[1].equals("Celsius"))
  23.  
  24. char tab[] =s.toCharArray();
  25.  
  26. String wczyt;
  27.         wczyt =JOptionPane.showInputDialog("Podaj ilosc marek");
  28.         Integer ile = Integer.parseInt(wczyt);
  29.  
  30. String marka = tab[i];
  31. char org[] =marka.toCharArray();
  32.  
  33. Random ii = new Random();
  34.  
  35.  
  36.        
  37.    Integer pom = ii.nextInt(25);
  38.  
  39. Arrays.sort(tab);
  40.  
  41. public Dvd(String color, String producer, double price) {
  42.         super(producer, price);
  43.         this.color = color;
  44.     }
  45.  
  46. abstract public class ElectronicParts extends Product
  47. public class ElectronicParts extends Product implements ElectronicPartsInterface
  48.  
  49. int a = new java.util.Random().nextInt(3);
  50.  
  51.         switch(a) {
  52.             case 0: throw new Wyjatek1();
  53.             case 1: throw new Wyjatek2();
  54.             case 2: throw new Wyjatek3();
  55.         }
  56.     }
  57.  
  58.     public static void main(String[] args) {
  59.         try {
  60.           metoda();  
  61.         } catch (Wyjatek1 e) {
  62.             System.out.println("Wyjatek nr : 1 ");
  63.         } catch (Wyjatek2 e) {
  64.             System.out.println("Wyjatek nr : 2 ");
  65.         } catch (Wyjatek3 e) {
  66.             System.out.println("Wyjatek nr : 3 ");
  67.         }
  68.     }
  69.  
  70.  
  71. File plik = new File(sciezka);
  72.  
  73.  FileReader a = null;
  74.         FileWriter b = null;
  75.                 try {
  76.             int znak;
  77.              long start=System.currentTimeMillis();
  78.             a = new FileReader("la.txt");
  79.             b= new FileWriter("lb.txt");
  80.                 while ((znak = a.read()) != -1){
  81.                 b.write(znak);
  82.             }
  83.                 long stop=System.currentTimeMillis();
  84.  System.out.println("Czas wykonania (w milisekundach) Readera : "+(stop-start));
  85.         } catch (FileNotFoundException ex) {
  86.             System.out.println("Brak Pliku");
  87.         }
  88.  
  89. catch    (NumberFormatException e1){
  90.             System.out.println("NumberFormatException");
  91.             //e1.printStackTrace();
  92.             throw e1;
  93.     }
  94.     catch(ArithmeticException e2){
  95.             System.out.println("ArithmeticException");
  96.            // e2.printStackTrace();
  97.             throw e2;
  98.     }
  99.     finally
  100.  
  101.     {
  102.             //System.out.println("Udalo sie");
  103.     }
  104.  
  105. finally {
  106. a.close();
  107. b.close();
  108. }
  109.    
  110.    
  111.        
  112.          FileReader aa = null;
  113.         BufferedReader aaa = null;
  114.          FileWriter bb = null;
  115.          BufferedWriter bbb = null;
  116.         try {
  117.             int znak;
  118.             // TODO code application logic here
  119.             aa = new FileReader("la.txt");
  120.             aaa = new BufferedReader(aa);
  121.  
  122.              bb= new FileWriter("lbb.txt");
  123.             bbb = new BufferedWriter(bb);
  124.             String line = null;
  125.             long start2=System.currentTimeMillis();
  126. while( (line = aaa.readLine()) != null){
  127.                 bb.write(line);
  128.             }
  129. long stop2=System.currentTimeMillis();
  130.  System.out.println("Czas wykonania (w milisekundach) BufferedReader : "+(stop2-start2));
  131.  
  132.         } catch (FileNotFoundException ex) {
  133.             System.out.println("Brak Pliku");
  134.         }
  135.  
  136. finally {
  137.             aa.close();
  138.             bb.close();
  139.             aaa.close();
  140.             bbb.close();
  141.  
  142. }
  143.        
  144.        
  145.    
  146.  }
  147.  
  148. public String toString() {
  149.         return name + telephone;
  150.     }
  151.  
  152. Product tab[]=new Product[5];
  153.        tab[0]=new ElectronicParts("SONY",100);
  154.         tab[1]=new ElectronicParts("JVC",50);
  155.         tab[2]= new Dvd("Czarny", "SONY", 250);
  156.         tab[3]=new Dvd("Bialy", "HP", 200);
  157.         tab[4]=new Tv(42,"Philips", 2500);
  158.  
  159.  
  160.  
  161. void ZglosWyjatek() throws Exception {
  162. if (new java.util.Random().nextInt(5) == 0)
  163. throw new Exception();
  164. }
  165. }
  166.   int liczba=1;
  167. Zad3 zad = new Zad3();
  168. try {
  169.    
  170. zad.ZglosWyjatek ();
  171. liczba++;
  172.    
  173.    
  174. zad.ZglosWyjatek ();
  175. liczba++;
  176.    
  177.    
  178. zad.ZglosWyjatek ();
  179. liczba++;
  180.    
  181.    
  182. zad.ZglosWyjatek ();
  183. liczba++;
  184.    
  185.    
  186. zad.ZglosWyjatek ();
  187. liczba++;
  188.    
  189.    
  190. } catch (Exception e) {
  191.     System.out.println("Wywołanie nr " + liczba + " ktore wyrzucilo wyjatek");
  192. }
  193.  
  194.      
  195.          FileReader aa = null;
  196.         BufferedReader aaa = null;
  197.          FileWriter bb = null;
  198.          BufferedWriter bbb = null;
  199.         try {
  200.             int znak;
  201.             // TODO code application logic here
  202.             aa = new FileReader("la.txt");
  203.             aaa = new BufferedReader(aa);
  204.  
  205.              bb= new FileWriter("lbb.txt");
  206.             bbb = new BufferedWriter(bb);
  207.             String line = null;
  208.             long start2=System.currentTimeMillis();
  209. while( (line = aaa.readLine()) != null){
  210.                 bb.write(line);
  211.             }
  212. long stop2=System.currentTimeMillis();
  213.  System.out.println("Czas wykonania (w milisekundach) BufferedReader : "+(stop2-start2));
  214.  
  215.         } catch (FileNotFoundException ex) {
  216.             System.out.println("Brak Pliku");
  217.         }
  218.  
  219. finally {
  220.             aa.close();
  221.             bb.close();
  222.             aaa.close();
  223.             bbb.close();
  224.  
  225. }
  226.  
  227.  public String toString() {
  228.         return name + telephone;
  229.  
  230. HashSet  kol = new HashSet();
  231.  ArrayList<Student> kol = new ArrayList<Student>();
  232. List<klasa> kol = new List<klasa> ()
  233.  
  234. public class kom implements Comparator<Student>{
  235.  
  236.     @Override
  237.     public int compare(Student o1,Student o2){
  238.  double srednia1 =o1.srednia(o1);
  239.  double srednia2=o2.srednia(o2);
  240.  if(srednia1>srednia2){
  241.      return 1;
  242.  }
  243.  if(srednia1<srednia2){
  244.      return -1;
  245.  }
  246.  else
  247.      return 0;
  248. }
  249. }
  250.  
  251. Collections.sort(kol, new kom());
  252.             System.out.println(kol);
  253.  
  254. //serializacja
  255. ObjectOutputStream out = new ObjectOutputStream(
  256.                                new BufferedOutputStream(
  257.                                  new FileOutputStream(nazwaPliku)));
  258.    
  259.     out.writeObject(test.getCzas());
  260.     out.close();
  261.  
  262.  ObjectInputStream in = new ObjectInputStream(
  263. new BufferedInputStream(
  264. new FileInputStream(nazwaPliku)));
  265.    
  266. b = (dataa) in.readObject();
  267.        // System.out.println(b);
  268. in.close();
  269. System.out.println(test);
  270.  
  271. public class HelloWorld extends JFrame{
  272.     public  HelloWorld(){
  273.  
  274. JLabel label= new JLabel("HelloWorld");
  275.         getContentPane().add(label);
  276.  
  277.  
  278.         setTitle("HellowWorldSwing");
  279.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  280.  
  281.  
  282.  
  283.  setVisible(true);
  284.         setSize(300,300);
  285.     }
  286.  
  287. BorderLayout border = new BorderLayout(10,10);
  288.         setLayout(border);
  289.  border.addLayoutComponent(label1, BorderLayout.NORTH);
  290.  
  291. public class GUI extends JFrame {
  292.     JPanel panel = new JPanel();
  293.     JButton b1 = new JButton("Przycisk");
  294.     int i=0;
  295.  
  296.     GUI() {
  297.       //  setSize(500, 400);
  298.         setTitle("okno");
  299.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  300.         setContentPane(panel);
  301.         panel.add(b1);
  302.        
  303.         b1.addActionListener(new ActionListener(){
  304.             public void actionPerformed(ActionEvent e){
  305.             i++;
  306.             b1.setText("Wciśnięto "+i+ " razy");
  307.             }
  308.         }
  309.                 );
  310.         pack();
  311.         setVisible(true);
  312.        
  313.     }
  314. }
  315.  
  316. public class tekstowe extends JFrame {
  317.   JTextField tekst1;    
  318.   JTextField tekst2;    
  319.   JTextField wynik;
  320.    
  321.     tekstowe() {
  322.         setTitle("Dodawanie");
  323.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
  324.         BorderLayout border = new BorderLayout();
  325.        setLayout(border);  
  326.          tekst1= new JTextField();
  327.           tekst2= new JTextField();
  328.           wynik= new JTextField();
  329.          JButton plus=new JButton("+");        
  330.    
  331.      getContentPane().add(tekst1);
  332.      getContentPane().add(tekst2);
  333.        getContentPane().add(plus) ;
  334.         getContentPane().add(wynik);
  335.      
  336.            
  337.    border.addLayoutComponent(tekst1, BorderLayout.NORTH);
  338.        border.addLayoutComponent(tekst2, BorderLayout.SOUTH);
  339.        border.addLayoutComponent(plus, BorderLayout.WEST);
  340.          border.addLayoutComponent(wynik, BorderLayout.EAST);
  341.        
  342.         ActionListener sl1=new Dodaj();      
  343.     plus.addActionListener(sl1);    
  344.         pack();
  345.         setVisible(true);
  346.        
  347.     }
  348.    
  349. class Dodaj implements ActionListener
  350.   {
  351.     public void actionPerformed(ActionEvent zdarzenie)
  352.     {
  353.       long n=Integer.parseInt(tekst1.getText());
  354.       long m=Integer.parseInt(tekst2.getText());
  355.       long suma=n+m;
  356.       wynik.setText(""+suma+" ");
  357.     }
  358.   }}
Add Comment
Please, Sign In to add comment