Академический Документы
Профессиональный Документы
Культура Документы
import java.io.*;
public class Division
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
class TwoVehicles
{
static String t1;
static String t2;
try
{
if(!t1.equals(t2))
throw new Collision("Collision About to Happen!!");
else
System.out.println("No Collision!!");
}
catch(Collision c)
{
System.out.println(c.getMessage());
t2=t1;
}
finally
{
System.out.println("Direction of Vehicle 1 is: "+t1);
System.out.println("Direction of Vehicle 2 is: "+t2);
}
}
}
class List_Collection
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String name;
String id;
String salary;
String temp="";
System.out.println("Copies of Employee:-");
Iterator itr=empCopies.iterator();
while (itr.hasNext())
System.out.println(itr.next());
System.out.println("Copies of Temp:");
itr = tempCopies.iterator();
while (itr.hasNext())
System.out.println(itr.next());
}
}
5a.public class Thread_Main
{
public static void main()throws InterruptedException
{
Thread t1,t2,t3,t4,t5;
t1=new Thread("Thread 1");
t2=new Thread("Thread 2");
t3=new Thread("Thread 3");
t4=new Thread("Thread 4");
t5=new Thread("Thread 5");
t1.setPriority(10);
t2.setPriority(4);
t3.setPriority(6);
t4.setPriority(8);
t5.setPriority(2);
t1.start();
t1.sleep(10);
if(t1.isAlive())
{
System.out.println("Thread is Alive");
}
else
{
System.out.println("Thread is Not Alive");
}
t2.start();
//t2.sleep(10);
if(t2.isAlive())
{
System.out.println("Thread is Alive");
}
else
{
System.out.println("Thread is Not Alive");
}
t3.start();
t3.sleep(3000);
if(t3.isAlive())
{
System.out.println("Thread is Alive");
}
else
{
System.out.println("Thread is Not Alive");
}
t4.start();
if(t4.isAlive())
{
System.out.println("Thread is Alive");
}
else
{
System.out.println("Thread is Not Alive");
}
t5.start();
if(t5.isAlive())
{
System.out.println("Thread is Alive");
}
else
{
System.out.println("Thread is Not Alive");
}
}
}
6.
import java.io.*;
str.trim();
str=str+" ";
revstr=reverseWordByWord(str);
System.out.println("The Sentence in Reversed Words is: "+revstr);
}
public static String reverseWordByWord(String s)
{
int strleng=s.length();
String reverse="", temp="";
int i,j;
char ch;
for(i=0;i<strleng;i++)
{
ch=s.charAt(i);
if(ch!=' ')
{
temp=temp+ch;
}
else
{
for(j=temp.length()-1;j>=0;j--)
{
reverse=reverse+temp.charAt(j);
}
temp=" ";
reverse=reverse+" ";
}
}
return reverse.trim();
}
}
5b.
import java.util.*;
// t1 finishes before t2
t1.join();
t2.join();
}
System.out.println("Producer produced-"
+ value);
System.out.println("Consumer consumed-"
+ val);
// and sleep
Thread.sleep(1000);
}
}
}
}
}
2a.
import java.io.*;
class Player
{
String name;
int age;
Player()
{
name="";
age=0;
}
Player(String nm,int a)
{
name=nm;
age=a;
}
class Player_Main
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
cp.show();
fp.show();
hp.show();
}
}
3b.
import java.io.*;
interface Stackop
{
void push(int item);
int pop();
}
class Dynstack implements Stackop
{
int tos;
int stk[];
int size;
Dynstack(int s)
{
tos=-1;
size=s;
stk=new int[size];
}
class Dynamic_Stack
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int size,i,n;
System.out.println("**************STACK 1*****************");
System.out.print("Enter the Number of Elements: ");
size=Integer.parseInt(br.readLine());
System.out.println("**************STACK 2*****************");
System.out.print("Enter the Number of Elements: ");
size=Integer.parseInt(br.readLine());
Stackop mystk;
Dynstack dyn=new Dynstack(size);
mystk=dyn;
float rate()
{
if(type.equalsIgnoreCase("urgent"))
return 4.5f;
else if(type.equalsIgnoreCase("lightning"))
return 3.5f;
else
return 3f;
}
}
void calculate()
{
if(super.dur<1.5)
amount=super.rate()*super.dur+1.5f;
else if(super.dur<3)
amount=super.rate()*super.dur+2.5f;
else if(super.dur<5)
amount=super.rate()*super.dur+4.5f;
else
amount=super.rate()*super.dur+5f;
}
void print()
{
System.out.println("The Call Details are:-");
System.out.println("Type: "+super.type);
System.out.println("Duration: "+super.dur);
System.out.println("Amount: "+amount);
}
}
class Trunk_Calls
{
public static void main(String args[])throws IOException
{
Bill bl=new Bill();
bl.read();
bl.calculate();
bl.print();
}
}