Wednesday, 26 July 2017

Write a program to generate multiplication table regular interval of time on the bases of user input (there should be more than one table) using the concept of thread priority. 

==============================================

class Table
{
synchronized void printTable(int n)
{
for(int i=1;i<=10;i++)
{
System.out.println(n + "*" +i+ "=" + n*i);
try
{
Thread.sleep(500);
}
catch(InterruptedException ie)
{
}
}
}
}

class Thread1 extends Thread
{
Table t;
Thread1(Table t)
{
this.t=t;
}
public void run()
{
t.printTable(5);
}
}

class Thread2 extends Thread
{
Table t;
Thread2(Table t)
{
this.t=t;
}
public void run()
{
t.printTable(10);
}
}


class Pr1_6
{
public static void main(String args[])
{
Table t=new Table();
Thread1 t1=new Thread1(t);
Thread2 t2=new Thread2(t);
t1.setPriority(6);
t2.setPriority(3);
t1.start();
t2.start();
}

}

Write a console application to create Restaurant time management system. Which displays menu as follows: 

Menu:  
1. Veg Berger, 45 Rs. (1 minutes)  
2. Italian Pasta, 100 Rs. (2 minutes)  
3. Pizza Margareta, 120 Rs. (5 minutes)  
4. Pizza Thine Crust, 140 Rs. (5 minutes)  

Enter your choice: 
1  Veg Berger, 45 Rs. (1 minutes) 
 Continue (Y/N) : Y  
Enter your choice: 4  
Pizza Thine Crust, 140 Rs. (5 minutes)  
Continue (Y/N) : N 

=====================================================================

import java.util.*;
import java.time.*;
class Order extends Thread
{
int t;
String name;
public void run()
{
synchronized(System.out)
{
try{
Thread.sleep(t);
}
catch(Exception e)
{
}
System.out.print("\n"+name+" :"+LocalDateTime.now()+"\n");
}

}
}
class Pr1_5
{
public static void main(String a[])
{
int ti[]=new int[10],count=0;
String name[]=new String[10];
Scanner sc=new Scanner(System.in);
int time=0;
double amt=0.0;
String ch="Y";
while(ch.equals("Y"))
{
System.out.print("\n1. Veg Berger, 45 Rs. (1 minutes)\n2. Italian Pasta, 100 Rs. (2 minutes)\n3. Pizza Margareta, 120 Rs. (5 minutes)\n4. Pizza Thine Crust, 140 Rs. (5 minutes)\nEnter Your Choise:");
int menu;
menu=sc.nextInt();
switch(menu)
{
case 1:
{
System.out.print("\nVeg Berger, 45 Rs. (1 minutes)");
time=time+1;
amt=amt+45.0;
ti[count]=1;
name[count]="Veg Burger is ready";
count++;
}
break;
case 2:
{
System.out.print("\nItalian Pasta, 100 Rs. (2 minutes)");
time=time+2;
amt=amt+100.0;
ti[count]=2;
name[count]="Italian Pasta is ready";
count++;
}
break;
case 3:
{
System.out.print("\nPizza Margareta, 120 Rs. (5 minutes)");
time=time+5;
amt=amt+120.0;
ti[count]=5;
name[count]="Pizza Margareta is ready";
count++;
}
break;
case 4:
{
System.out.print("\nPizza Thine Crust, 140 Rs. (5 minutes)");
time=time+5;
amt=amt+140.0;
ti[count]=5;
name[count]="Pizza Thine Crust is ready";
count++;
}
break;
default:
System.out.print("\nplease enter valid choise");
}
System.out.print("\nContinue (Y/N) :");
ch=sc.next();
}
System.out.println("please pay Rs. "+amt+" and wait for "+time+" minutes :"+LocalDateTime.now());

Order []o=new Order[count];
for(int i=0;i<count;i++)
{
o[i]=new Order();
o[i].t=(ti[i]*60)*1000;
o[i].name=name[i];
o[i].start();
}
}

}

Monday, 24 July 2017

Python practical - 3 pattern

==============================
        @
      $  $ 
   @ @ @ 
  $   $   $  $




n = input("Enter the Number : ")
p=n
for i in range(1,n+1):
print " "
for j in range(p):
print " ",
n=n-1
p=p-1
for j in range(i):
if(i % 2 == 1):
print " @ ",
else:
print " $ ",
print " "


====================================

      @ 
    @ @ 
   @ $ @ 
  @ $ $ @

n = input("Enter the Value : ")
p=n

for i in range(1,n+1):
for j in range(p):
print " ",
p=p-1
for j in range(i):
if(i <= 2):
print " @ ",
else:
if(j==0 or j == i-1):
print " @ ",
else:
print " $ ",
print "\n"


==================================

** 
***
******** 
        ***
        ** 
        *


n = input("Enter the Value : ")
p=n
k=n

for i in range(1,n+n+2):
if(i <= n):
for j in range(i):
print " * ",
elif(i == n+1):
for j in range(1,n+n+1):
print " * ",
else:
#print "i : ",i,
for j in range(k):
print "   ",
k = k + 1
for j in range(p):
print " * ",
p = p - 1
print "\n"





(P - 1 - 4)
Write a Java program to create five threads with different priorities. Send 1st two highest priority thread to sleep mode and check the aliveness of the threads and check which thread is long lasting. 

=========================================

import java.lang.*;

class ThreadPriority extends Thread
{
    public static void main(String[]args) throws InterruptedException 
    {
        ThreadPriority t1 = new ThreadPriority();
        ThreadPriority t2 = new ThreadPriority();
        ThreadPriority t3 = new ThreadPriority();
ThreadPriority t4 = new ThreadPriority();
        ThreadPriority t5 = new ThreadPriority();

        t1.setPriority(9);
        t2.setPriority(8);
        t3.setPriority(5);
t4.setPriority(3);
        t5.setPriority(2);

t1.sleep(1000); 
if (t1.isAlive()) 
System.out.println("Thread 1 is alive"); 
else 
System.out.println("Thread 1 is not alive"); 
 
t2.sleep(1000); 
if (t2.isAlive()) 
System.out.println("Thread 2 is alive"); 
else 
System.out.println("Thread 2 is not alive"); 
 
t3.start();  
if (t3.isAlive()) 
System.out.println("Thread 3 is alive"); 
else 
System.out.println("Thread 3 is not alive"); 
 
t4.start(); 
if (t4.isAlive()) 
System.out.println("Thread 4 is alive"); 
else 
System.out.println("Thread 4 is not alive"); 
 
t5.start(); 
if (t5.isAlive()) 
System.out.println("Thread 5 is alive"); 
else 
System.out.println("Thread 5 is not alive"); 
    }

}

(P-1-2) Single user accounting system help user for transfer money and deposit amount in particular account. Generate class namely Accounting with accountNumber and accountBalance as a parameter and transferMoney() and depositMoney() as a member function. 

1. Account number should have 7 digits.   
2. Minimum balance in account must be 1500 rupees.   
3. Allow only one thread to perform operation on a single account

==============================================

import java.io.*;

class Accounting extends Thread
{
String acn = "";
double accountNumber = 0.0;
float accountBalance = 0.0f;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
void transferMoney(double an,float ab)
{
if(accountNumber == an)
{
if(accountBalance > 0)
{
if(accountBalance + 1500 >= ab)
{
accountBalance = accountBalance - ab;
System.out.println("Account Balance : " + accountBalance);
System.out.println("Withdrawal Successfully Done");
}
else
{
System.out.println("Minimum 1500$ is Required!");
}
}
else
{
System.out.println("Withdrawal Balance Minimum is more then 0");
}
}
else
{
System.out.println("Account Number is Invalid...");
}
}
void dipositeMoney(double an,float ab)
{
if(accountNumber == an)
{
if(accountBalance > 0)
{
accountBalance = accountBalance + ab;
System.out.println("Account Balance : " + accountBalance);
System.out.println("Diposit Successfully Done");
}
else
{
System.out.println("Diposit Balance Minimum is more then 0");
}
}
else
{
System.out.println("Account Number is Invalid...");
}
}
void newAccount() throws Exception
{
while(acn.length() != 8)
{
System.out.print("Enter Account Number (8 Digit): ");
acn = br.readLine();
}
accountNumber = Double.valueOf(acn);
while(accountBalance <= 1500)
{
System.out.print("Enter the Account Balance(min 1500) : ");
accountBalance = Float.valueOf(br.readLine());
}
}
}

class MainAccount
{
public static void main(String args[]) throws Exception
{
int no;
double an = 0.0;
float ab = 0.0f;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Accounting a = new Accounting();
do{
System.out.println("1. Create Account ");
System.out.println("2. Money Transfer ");
System.out.println("3. Diposit ");
System.out.println("4. Exit");
no = Integer.valueOf(br.readLine());
switch(no)
{
case 1:
a.newAccount();
break;
case 2:
try{
System.out.print("Enter Account Number : " );
an = Double.valueOf(br.readLine());
System.out.print("Enter Account Balance : " );
ab = Float.valueOf(br.readLine());
}catch(Exception ex)
{
System.out.println("input time error...");
}
a.transferMoney(an,ab);
break;
case 3:
try{
System.out.print("Enter Account Number : " );
an = Double.valueOf(br.readLine());
System.out.print("Enter Account Balance : " );
ab = Float.valueOf(br.readLine());
}catch(Exception ex)
{
System.out.println("input time error...");
}
a.dipositeMoney(an,ab);
break;
}
}while(no != 4);
}
}

          2).Employee’s details are maintained by organization and that contains parameter namely name, designation, salary, department and experience. Create individual thread for each employee and display information of them at a regular interval. [Assume that there are four employees in the company].

===============================================

import java.io.*;
class Employee extends Thread{ String name,desig,salary,dept,exp; synchronized public void display() { synchronized(System.out) { System.out.println("Name        : " + name); try{ Thread.sleep(1000); }catch(InterruptedException ex){} System.out.println("Designation : " + desig); try{ Thread.sleep(1000); }catch(InterruptedException ex){} System.out.println("salary      : " + salary); try{ Thread.sleep(1000); }catch(InterruptedException ex){} System.out.println("Department  : " + dept); try{ Thread.sleep(1000); }catch(InterruptedException ex){} System.out.println("Experience  : " + exp); try{ Thread.sleep(1000); }catch(InterruptedException ex){} } } void getData() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Employee Name : "); name = br.readLine(); System.out.print("Employee Designation : "); desig = br.readLine(); System.out.print("Employee Salary : "); salary = br.readLine(); System.out.print("Employee Department : "); dept = br.readLine(); System.out.print("Employee Experience : "); exp = br.readLine();
} public void run() { display(); }}

class EmployeeMain{ public static void main(String Args[]) throws Exception { Employee e1 = new Employee(); Employee e2 = new Employee();
                Employee e3 = new Employee();                Employee e4 = new Employee(); 
e1.getData(); e2.getData();
e3.getData(); e4.getData();
e1.start(); e2.start(); e3.start();
                                e4.start();
}}

Know us

Our Team

Translate

Contact us

Name

Email *

Message *