Answer to Question #245628 in Java | JSP | JSF for ram

Question #245628

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-03T04:01:29-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 no_of_flowers;
    private String destination_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: ");
        no_of_flowers=input.nextInt();
        System.out.println("Enter the destination address: ");
        destination_address=input.next();
    }
    
    public void deliver(){
        if (stock<=0 || no_of_flowers>stock){
            System.out.println("There are no enough flowers to deliver!");
        }
        else{
            stock-=no_of_flowers;
            System.out.println(no_of_flowers+" has been delived to "+destination_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