ASSIGNMENT 3
[JAVA]
SAN K
[Link] Count
import [Link].*;
public class Linecount
{
public static void main(String[] args) throws Exception
{
int num;
for(int i=0;i<[Link];i++)
{
int count=1;
FileInputStream s1=new FileInputStream(args[i]);
num=[Link]();
while(num != -1)
{
if(num==13)
{
num=[Link]();
if(num==10)
count++;
else
continue;
}
num=[Link]();
}
[Link](args[i]+"--------"+count);
}
}
}
[Link] with args
class T1 extends Thread
{
public void run()
{
[Link]("Hello,I am "+[Link]());
}
}
public class ThreadWithCmdLine
{
public static void main(String[] args) {
for(int i=0;i<[Link](args[0]);i++)
{
new T1().start();
}
}
}
[Link] Priority
class Thread2 extends Thread
{
public void run()
{
[Link]("Hello,I am "+[Link]());
}
}
public class ThreadPriority
{
public static void main(String[] args) {
Thread2 t1=new Thread2();
Thread2 t2=new Thread2();
Thread2 t3=new Thread2();
[Link](Thread.MIN_PRIORITY);
[Link](Thread.MAX_PRIORITY);
[Link](Thread.MAX_PRIORITY);
[Link]();
[Link]();
[Link]();
}
}
[Link] case conversion
import [Link].*;
public class LowerConversion
{
public static void main(String[] args) throws Exception
{
int num;
FileInputStream fis=new FileInputStream("e:\\[Link]");
FileOutputStream fos=new FileOutputStream("e:\\[Link]");
num= [Link]();
while(num!=-1)
{
if(num>=65 && num<=90)
num+=32;
[Link](num);
num=[Link]();
}
[Link]("Written Successfully");
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
public class Conversion {
public static void main(String[] args) {
JFrame f = new JFrame("Conversion");
Label l1 = new Label("Miles");
Label l2 = new Label("Kilometers");
TextField t1 = new TextField(7);
TextField t2 = new TextField(7);
Button b = new Button("Convert!");
[Link](l1);
[Link](t1);
[Link](l2);
[Link](t2);
[Link](b);
[Link](new FlowLayout());
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
Double d = [Link]([Link]());
Double d1 = 1.609 * d;
[Link](d1+"");
}
}
);
[Link](false);
[Link](300, 150);
//[Link]();
[Link](true);
[Link](JFrame.EXIT_ON_CLOSE);
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
class Move extends JFrame implements ActionListener,KeyListener
{
JSeparator js1;
JLabel l1;
JPanel p2;
String str[]={"UP","DOWN","LEFT","RIGHT"};
Move()
{
ImageIcon i1=new ImageIcon("e://1//[Link]");
js1=new JSeparator();
p2=new JPanel();
l1 = new JLabel();
setSize(500,400);
setVisible(true);
setResizable(false);
setLayout(null);
[Link](EXIT_ON_CLOSE);
[Link](50,0,400,50);
[Link](i1);
[Link](100,100,[Link](),[Link]());
add(l1);
[Link](0, 50, 500, 2);
add(js1);
add(p2);
[Link](new GridLayout(1,4,10,0));
for(int i=0;i<[Link];i++)
{
JButton b1=new JButton(str[i]);
[Link](45, 30);
[Link](this);
[Link](b1);
}
addKeyListener(this);
setFocusable(true);
setFocusTraversalKeysEnabled(false);
}
public void actionPerformed(ActionEvent e)
{
if([Link]().equals("UP"))
{
if([Link]() != 50)
[Link]([Link](),[Link]()-25, 100, 100);
}
else if([Link]().equals("DOWN"))
{
if([Link]() != 275)
[Link](
[Link](),[Link]()+25, 100, 100);
}
else if([Link]().equals("RIGHT"))
{
if([Link]() != 375)
[Link]([Link]()+25,[Link](), 100, 100);
}
else if([Link]().equals("LEFT"))
{
if([Link]() != 0)
[Link]([Link]()-25,[Link](), 100, 100);
}
}
public void keyPressed(KeyEvent e)
{
int keyCode = [Link]();
switch(keyCode){
case 38:
if([Link]() != 50)
[Link]([Link](),[Link]()-25, 100, 100);
break;
case 40:
if([Link]() != 275)
[Link]([Link](),[Link]()+25, 100, 100);
break;
case 37:
if([Link]() != 0)
[Link]([Link]()-25,[Link](), 100, 100);
break;
case 39 :
if([Link]() != 375)
[Link]([Link]()+25,[Link](), 100, 100);
break;
}
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e) {}
}
public class Event {
public static void main(String[] args) {
new Move();
}
}
[Link] LIght
import [Link].*;
import [Link].*;
import [Link].*;
class Light extends JFrame implements ActionListener
{
JRadioButton rb1,rb2,rb3;
ButtonGroup b1=new ButtonGroup();
JLabel l1;
JPanel p1=new JPanel();
Light()
{
super("TRAFFIC LIGHT");
rb1=new JRadioButton();
rb2=new JRadioButton();
rb3=new JRadioButton();
l1=new JLabel("");
setSize(400,250);
setLayout(null);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
[Link]("RED");
add(rb1);
[Link](this);
[Link](50, 40, 93, 23);
[Link]("YELLOW");
add(rb2);
[Link](50, 80, 93, 23);
[Link](this);
[Link]("GREEN");
add(rb3);
[Link](50, 120, 93, 23);
[Link](this);
[Link](rb1);
[Link](rb2);
[Link](rb3);
add(l1);
[Link](190, 10, 180, 30);
add(p1);
[Link](190, 40, 190, 110);
}
public void actionPerformed(ActionEvent e)
{
if([Link]())
{
[Link]("STOP");
[Link]([Link]);
}
else if([Link]())
{
[Link]("READY");
[Link]([Link]);
}
else if([Link]())
{
[Link]("G0");
[Link]([Link]);
}
}
}
public class TrafficLight
{
public static void main(String[] args) {
new Light();
}
}
[Link] to perform operations
import [Link];
class Thrd2 extends Thread
{
int num;
Thrd2(int no)
{
num=no;
}
public void run()
{
if(num%5==0)
{
[Link]("It is divisible by five");
}
}
}
class Thrd1 extends Thread
{
int no,total;
public void run()
{
int num;
[Link]("Enter the no. of numbers:");
Scanner scan= new Scanner([Link]);
no=[Link]();
for(int i=0;i<no;i++)
{
[Link]("Enter the number %d : ",i+1);
num=[Link]();
total+=num;
Thrd2 five = new Thrd2(num);
[Link]();
try
{
[Link](2000);
}
catch(Exception e){}
}
}
}
public class ThreadToPerformOperations
{
public static void main(String[] args)
{
Thrd1 t1=new Thrd1();
[Link]();
try{
[Link]();
}
catch(Exception e){}
new Thread(new Runnable()
{
public void run()
{
int avg = [Link]/[Link];
[Link]("Average : "+avg);
}
}).start();
}
}