1 užduotis: programėlė ir įskiepis




Pasirinkite vieną porą, kurią sudaro Java programos ir įskiepio kodas. Ir programos ir įskiepio koduose yra klaidų. Pabandykite išsiaiškinti ką turėtų veikti programa ir įskiepis, pabandykite sukompiliuoti, peržvelkite informaciją apie klaidas. Tikslas - ištaisyti jas ir priversti programas veikti. Kai jos veiks, ką nors pakeiskite savo nuožiūra, kad programos veiktų šiek tiek kitaip.

Pirmoji pora

import java.io.*;
 public class Java_programa_1 {
    
    String iv;
     double a;
    public static void main(String[] args) throws IOException {
     
     String iv;
    	
    	
     BufferedReader br = new BufferedReader ( 
     new InputStreamReader (System.in)); 
     
    
     System.out.print ("Iveskite skaiciu: ");
     iv = br.readLine()
     a = Double.parseDouble(iv);
     System.out.print ("Ivestas skaicius "+a+"\n o jo kvadratas "+a*a);
     System.in.read();
     }
}
_____________________________________________________

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_1 extends Applet implements ActionListener
{ Label antr, antr1;
  Button mygt;
  TextField txt;
  double sk;
  
 public void init ()
  {setLayout(new BorderLayout());
  antr = new Label("Galiu apskaiciuoti skaiciaus kvadrata");
  add(antr, "North")
  txt= new TextField("Iveskite skaiciu");
  add(txt, "Center");
  mygt = new Button ("Spauskite");
  mygt.addActionListener(this);
    antr1= new Label("Cia rasysime atsakymus");
  add(antr1,"South");
 }	


public void actionPerformed(ActionEvent ivykis)
{
if (ivykis.getSource()==mygt) 
{ try {sk = Double.parseDouble(txt.getText());}
 catch (Exception e) {}
 antr1.setText("Rezultatas:"); 
}}}

Antroji pora

 import java.io.*;
 public class Java_programa_2 {
 	
    int iv;
    double a;	
    	
    BufferedReader br = new BufferedReader ( 
    new InputStreamReader (System.in)); 
   
     Java_programa_2 () {
      darbas();
      }
    
    public static void main(String[] args)  {
     new Java_programa_2();}
     
    public void darbas ( )    {
    System.out.print ("Galiu apskaiciuoti apskritimo ilgi \n");	
    System.out.print ("Iveskite spindulio ilgi: ");
    try { iv = br.readLine();
    a = Double.parseDouble(iv);
    System.out.print ("Spindulio ilgis "+a+"\n o apskritimo ilgis "+ilg(a));
    System.in.read();}
    catch (IOException e) {}
     } 
     
  public double ilg(double x)   
  {return 2*Math.PI*x
  	}     
}
___________________________________________________________
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_2 extends Applet { Label antr, antr1;
  Button mygt;
  TextField txt;
  double sk;
  
 public void init ()
  {setLayout(new BorderLayout());
  antr = new Label("Galiu apskaiciuoti apskritimo ilgi");
  add(antr, "North);
  txt= new TextField("Iveskite spindulio ilgi");
  add(txt, "Center");
  mygt = new Button ("Spauskite");
  mygt.addActionListener(this);
  add(mygt,"East");
  antr1= new Label("Cia rasysime atsakymus");
  add(antr1,"South");
 }	


public void actionPerformed(ActionEvent ivykis)
{
if (ivykis.getSource()==mygt) 
{ try {sk = Double.parseDouble(txt.getText());}
 catch (Exception e) {}
 antr1.setText("Apskritimo ilgis: "+2*Math.PI*sk ); 
}
}
}

Trečioji pora

import java.io.*;
 public class Java_programa_3 {
 		
    public static void main(String[] args)  throws IOException{
    	
    String v;
    int b;
    
    BufferedReader br = new BufferedReader ( 
    new InputStreamReader (System.in)); 
    
    System.out.print ("Galiu apskaiciuoti skaiciaus naturini logaritma \n");	
    System.out.print ("Iveskite skaiciu: ");
     v = br.readLine()
    b = Double.parseDouble(v);
    System.out.print ("Skaicius  "+b+"\n o jo naturinis logaritmas "+Math.log(b));
    System.in.read();
    
     }           
}
__________________________________________________
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_3 extends Applet implements ActionListener
{ Label antr;
  Button mygt;
  TextField txt;
  
  
 public void init ()
  {setLayout(new BorderLayout());
  antr = new Label("Galiu apskaiciuoti naturini skaiciaus logaritma");
  add(antr, "South");
  tkst= new TextField("Iveskite skaiciu");
  add(txt, "Center");
  mygt = new Button ("Spauskite");
  mygt.addActionListener(this);
  add(mygt,"North");
  
 }	


public void actionPerformed(ActionEvent ivykis)
{double sk=0;
if (ivykis.getSource()==mygt) 
{ try {sk = Double.parseDouble(txtgetText());}
 catch (Exception e) {}
 txt.setText("Skaiciaus "+sk+ " naturinis logaritmas lygus "+Math.log(sk) ); 
}
}
}

Ketvirtoji pora

import java.io.*;
public class Java_programa_4  {
 	
   
    BufferedReader br = new BufferedReader ( 
    new InputStreamReader (System.in));
    
    Java_programa_4 ( )
    {
    System.out.print ("Funkcijos f(x)=x^2-3x skaiciavimas: \n");	
    System.out.print ("Iveskite skaiciu: ");		
    funkcija()
    }
    
    public static void main(String[] args) {
    new Java_programa_4( );	
    } 	
    
   public void funkcija( )
   {
    
    try{
    x = Double.parseDouble(br.readLine());
    System.out.print ("Ivestas skaicius "+x+"\n f(x)="+(x*x-3*x));
    System.in.read(); }	
    catch (IOException e) {}
  }  }
_______________________________________________________________

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_4 extends Applet implements ActionListener
{ Label head;
  Button mgt;
  TextField t;
  
  
 public void init ()
  {setLayout(new BorderLayout());
  head = new Label("Galiu apskaiciuoti f(x)=x^2-3x");
  add(head, "North");
  t= new TextField("Iveskite skaiciu x");
  add(t, "Center");
  mgt = new Button ("Spauskite");
  mgt.addActionListener(this);
    
 }	


public void actionPerformed(ActionEvent ivykis)
{double x=0;
if (ivykis.getSource()==mgt) 
{ try {x = Double.parseDouble(t.getText())}
 catch (Exception e) {}
 t.setText("Jei x= "+x+ ", tai   f(x)="+(x*x-3*x) ); 
}
}
}

Penktoji pora

import java.io.*;
public class Java_programa_5  {
 	
   
    BufferedReader br = new BufferedReader ( 
    new InputStreamReader (System.in));
    
    int a;
    
    Java_programa_5 ( )
    {
    System.out.print ("Generuoju penkis  atsitiktinius intervalo [a;b] skaicius  \n");	
    ivedimas();
    }
    
    public static void main(String[] args) {
    new Java_programa_5( );	
    } 	
    
   public void ivedimas( )
   { try {
   	System.out.print ("Iveskite skaiciu a: ");
     a =Integer.parseInt(br.readLine());
     System.out.print ("Iveskite skaiciu b: ");
     b =Integer.parseInt(br.readLine());
     generuoti (a,b);
     }
     catch (IOException sit) {}
   }
   
   public void generuoti (int u, int v) 
    { int d=v-u;
    System.out.print("Atsitiktiniai skaiciai:\n");
    System.out.print("Pirmasis:"+(int)u+(v-u)*Math.random())+"\n" );
    System.out.print("Antrasis:"+(int)(u+(v-u)*Math.random())+"\n" );
    System.out.print("Treciasis:"+(int)(u+(v-u)*Math.random())+"\n" );
    System.out.print("Ketvirtasis:"+(int)(u+(v-u)*Math.random())+"\n" );
    System.out.print("Penktasis:"+(int)(u+(v-u)*Math.random())+"\n" );	
    }
}
__________________________________________________

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_5 extends Applet implements ActionListener
{ Label head;
  Button mgt;
  TextField t;
  
  
 public void init ()
  {setLayout(new BorderLayout());
  head = new Label("Galiu generuoti 5 atsitiktinius skaicius, mazesnius uz ivestaji");
  add(head, "North");
  t= new TextField("Iveskite skaiciu x");
   mgt = new Button ("Spauskite");
  mgt.addActionListener(this);
  add(mgt,"South");
  }	


public void actionPerformed(ActionEvent ivykis)
{int x=0;
if (ivykis.getSource()==mgt) 
{ try {x = Integer.parseInt(t.getText());}
 catch (Exception e) {}
 generuoti(x); 
}
}
public void generuoti (int a){
 t.setText("Atsitiktiniai skaiciai:  "
 + (int)(a*Math.random()+"; "
 + (int)(a*Math.random())+"; "
 + (int)(a*Math.random())+"; "
 + (int)(a*Math.random())+"; "
 + (int)(a*Math.random())+"; ");
}
}

Šeštoji pora

import java.io.*;
 public class Java_programa_1 {
    
    String iv;
     double a;
    public static void main(String[] args) throws IOException {
     
     int iv;
     double a;	
    	
     BufferedReader br = new BufferedReader ( 
     new InputStreamReader (System.in)); 
     
    
     System.out.print ("Iveskite skaiciu: ");
     iv = br.readLine()
     a = Double.parseDouble(iv);
     System.out.print ("Ivestas skaicius "+a+"\n o jo kvadratas "+a*a);
     System.in.read();
     }
}
_____________________________________________________

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_1 extends Applet implements ActionListener
{ Label antr, antr1;
  Button mygt;
  TextField text;
  double sk;
  
 public void init ()
  {setLayout(new BorderLayout());
  antr = new Label("Galiu apskaiciuoti skaiciaus kvadrata");
  add(antr, "North");
  txt= new TextField("Iveskite skaiciu");
  add(txt, "Center");
  mygt = new Button ("Spauskite");
  mygt.addActionListener(this);
  antr1= new Label("Cia rasysime atsakymus");
  add(antr1,"South");
 }	


public void actionPerformed(ActionEvent ivykis)
{
if (ivykis.getSource()==mygt) 
{ try {sk = Double.parseDouble(txt.getText());}
 catch (Exception e) {}
 antr1.setText("Rezultatas:"); 
}}}

Septintoji pora

 import java.io.*;
 public class Java_programa_2 {
 	
    String iv;
    int a;	
    	
    BufferedReader br = new BufferedReader ( 
    new InputStreamReader (System.in)); 
   
     Java_programa_2 () {
      darbas();
      }
    
    public static void main(String[] args)  {
     new Java_programa_2();}
     
    public void darbas ( )    {
    System.out.print ("Galiu apskaiciuoti apskritimo ilgi \n");	
    System.out.print ("Iveskite spindulio ilgi: ");
    try { iv = br.readLine();
    a = Double.parseDouble(iv);
    System.out.print ("Spindulio ilgis "+b+"\n o apskritimo ilgis "+ilg(a));
    System.in.read();}
    catch (IOException e) {}
     } 
     
  public double ilg(double x)   
  {return 2*Math.PI*x;
  	}     
}
___________________________________________________________
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_2 extends Applet implements ActionListener
{ Label antr, antr1;
  TextField txt;
  double sk;
  
 public void init ()
  {setLayout(new BorderLayout());
  antr = new Label("Galiu apskaiciuoti apskritimo ilgi");
  add(antr, "North");
  txt= new TextField("Iveskite spindulio ilgi");
  add(txt, "Center");
  mygt = new Button ("Spauskite");
  mygt.addActionListener(this);
  add(mygt,"East");
  antr1= new Label("Cia rasysime atsakymus");
  add(antr1,"South");
 }	


public void actionPerformed(ActionEvent ivykis)
{
if (ivykis.getSource()==mygt) 
{ try {sk = Double.parseDouble(txt.getText());}
 catch (Exception e) {}
 antr1.setText("Apskritimo ilgis: "+2*Math.PI*sk ); 
}
}

Aštuntoji pora

import java.io.*;
 public class Java_programa_3 {
 		
    public static void main(String[] args)  throws IOException{
    	
    String w;
    double b;
    
    BufferedReader br = new BufferedReader ( 
    new InputStreamReader (System.in)); 
    
    System.out.print ("Galiu apskaiciuoti skaiciaus naturini logaritma \n");	
    System.out.print ("Iveskite skaiciu: ")
     v = br.readLine();
    b = Double.parseDouble(v);
    System.out.print ("Skaicius  "+b+"\n o jo naturinis logaritmas "+Math.log(b));
    System.in.read();
    
     }           
}
__________________________________________________
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_3 extends Applet implements ActionListener
{ Label antr;
  Button mygt;
  TextField txt;
  
  
 public void init ()
  {setLayout(new BorderLayout());
  antr = new Label("Galiu apskaiciuoti naturini skaiciaus logaritma");
  add(antr, "South");
  txt= new TextField("Iveskite skaiciu");
  add(text, "Center");
  mygt = new Button ("Spauskite");
  mygt.addActionListener(this);
  add(mygt,"North");
  
 }	


public void actionPerformed(ActionEvent ivykis)
{double sk=0
if (ivykis.getSource()==mygt) 
{ try {sk = Double.parseDouble(txt.getText());}
 catch (Exception e) {}
 txt.setText("Skaiciaus "+sk+ " naturinis logaritmas lygus "+Math.log(sk) ); 
}
}
}

Devintoji pora

import java.io.*;
public class Java_programa_4  {
 	
   
    BufferedReader br = new BufferedReader ( 
    new InputStreamReader (System.in));
    
    Java_programa_4 ( )
    {
    System.out.print ("Funkcijos f(x)=x^2-3x skaiciavimas: \n);	
    System.out.print ("Iveskite skaiciu: ");		
    funkcija();
    }
    
    public static void main(String[] args) {
    new Java_programa_4( );	
    } 	
    
   public void funkcija( )
   { int x;
    
    try{
    x = Double.parseDouble(br.readLine());
    System.out.print ("Ivestas skaicius "+x+"\n f(x)="+(x*x-3*x));
    System.in.read(); }	
    catch (IOException e) {}
  }  }
_______________________________________________________________

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_4 extends Applet implements ActionListener
{ Label head;
  Button mgt;
  TextField t;
  
  
 public void init ()
  {setLayout(new BorderLayout());
  head = new Label("Galiu apskaiciuoti f(x)=x^2-3x");
  add(head, "North");
  t= new TextField("Iveskite skaiciu x");
  add(t, "Center");
  mgt = new Button ("Spauskite");
  mgt.addActionListener(this);
    
 }	


public void actionPerformed(ActionEvent ivykis)
{double x=0;
if (ivykis.getSource()==mgt) 
{ try {x = Double.parseDouble(t.getText());}
 catch (Exception e) {}
 t.setText("Jei x= "+x+ ", tai   f(x)="+(x*x-3*x) ); 
}
}
}

Dešimtoji pora

import java.io.*;
public class Java_programa_5  {
 	
   
    BufferedReader br = new BufferedReader ( 
    new InputStreamReader (System.in));
    
    int b;
    
    Java_programa_5 ( )
    {
    System.out.print ("Generuoju penkis  atsitiktinius intervalo [a;b] skaicius  \n");	
    ivedimas();
    }
    
    public static void main(String[] args) {
    new Java_programa_5( );	
    } 	
    
   public void ivedimas( )
   { try {
   	System.out.print ("Iveskite skaiciu a: ");
     a =Integer.parseInt(br.readLine());
     System.out.print ("Iveskite skaiciu b: ");
     b =Integer.parseInt(br.readLine());
     generuoti (a,b);
     }
     catch (IOException sit) {}
   }
   
   public void generuoti (int u, int v) 
    { int d=v-u;
    System.out.print("Atsitiktiniai skaiciai:\n");
    System.out.print("Pirmasis:"+(int)(u+(v-u)*Math.random())+"\n" );
    System.out.print("Antrasis:"+(int)(u+(v-u)*Math.random())+"\n" );
    System.out.print("Treciasis:"+(int)(u+(v-u)*Math.random())+"\n" );
    System.out.print("Ketvirtasis:"+(int)(u+(v-u)*Math.random())+"\n" );
    System.out.print("Penktasis:"+(int)(u+(v-u)*Math.random())+"\n" );	
    
}
__________________________________________________

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Iskiepis_5 extends Applet implements ActionListener
{ Label head;
  Button mgt;
  TextField t;
  
  
 public void init ()
  {setLayout(new BorderLayout());
  head = new Label("Galiu generuoti 5 atsitiktinius skaicius, mazesnius uz ivestaji");
  add(head, "North");
  t= new TextField("Iveskite skaiciu x");
  add(t, Center");
  mgt = new Button ("Spauskite");
  mgt.addActionListener(this);
  add(mgt,"South");
  }	


public void actionPerformed(ActionEvent ivykis)
{int x=0;
if (ivykis.getSource()==mgt) 
{ try {x = Integer.parseInt(t.getText());}
 catch (Exception e) {}
 generuoti(x); 
}
}
public void generuoti (a){
 t.setText("Atsitiktiniai skaiciai:  "
 + (int)(a*Math.random())+"; "
 + (int)(a*Math.random())+"; "
 + (int)(a*Math.random())+"; "
 + (int)(a*Math.random())+"; "
 + (int)(a*Math.random())+"; ");
}
}