Answer to Question #253498 in Python for shishi

Question #253498

Write a java application using the concepts of multithreading for a flower

shop where flowers are delivered based on order.


1
Expert's answer
2021-10-21T16:07:45-0400
import java.util.Scanner;
public class Main 
{ 
 public static void main(String args[]) 
 { 
 Flower thread1=new Flower(); 
 Flower thread2=new Flower(); 
 thread1.start();  
 thread2.start();
 } 
} 




class Flower extends Thread 
{ 
 private int num;
 private String address;
 private int stock;
 
 public void getData(){
 Scanner input=new Scanner(System.in);
 System.out.println("Enter the number of flowers remaining in the stock: ");
 stock=input.nextInt();
 System.out.println("Enter the number of flowers to deliver: ");
 num=input.nextInt();
 System.out.println("Enter the destination address: ");
 address=input.next();
 }
 
 public void deliver(){
 if (stock<=0 || num>stock){
 System.out.println("There are no enough flowers to deliver!");
 }
 else{
 stock-=num;
 System.out.println(num+" has been delived to "+address+"\nRemaining number of flowers in the stockis "+stock);
 
 }
 }
 public void run() 
 { 
 
 try 
 { 
 Thread.sleep(500); 
 }catch(InterruptedException e){System.out.println(e);} 
 getData(); 
 deliver();
 
 }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS