[Solved] Stall Revenue with Java

Stall Revenue: The Accounting department of the fair committee wants a console application that can estimate the total revenue by the rent from an exhibition. So write a program that accepts the stall details of an exhibition that includes the stallArea which is used for computing the stallCost. Using threads, calculate the stallCost of each stall and in the main method, print the consolidated data.

Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, attribute names, and method names should be the same as specified in the problem statement.
 

Create a class Stall which implements Runnable interface with the following private attributes,

AttributesDatatype
stallNameString
detailsString
stallAreaDouble
ownerString
stallCostDouble

Create default constructor and a parameterized constructor with arguments in order Stall(String stallName, String details, Double stallArea, String owner). Create appropriate getters and setters.

Override the following methods in the Stall class,

MethodDescription
public void run()In this method, using the stall area calculate stall cost and assign the value to stall cost.
Stall cost = stall area * 150.0

Get the number of stalls and stall details and calculate the total revenue of all the stalls. Calculate the stall cost for each stall, each cost will be calculated by separate thread. Total revenue is the total cost of all the stalls. Calculate the total revenue display the same.

Create a driver class Main to test the above requirements.

Input Format
The first line of the input corresponds to the total number of stalls ‘n’.
The next ‘n’ line of input contains stall details (stallName,details,stallArea,owner) separated by comma [ , ].

Output Format
The output consists of the total revenue.
Refer sample output for formatting specifications.

[All text in bold corresponds to input and rest corresponds to output]
Sample Input and Output:


Enter the number of stalls:
3
Book stall,Stall for books,25,John
Food stall,Stall for foods,60,Peter
Snack stall,Stall for snack,30,Adam

The total revenue is 17250.0

Solution

import java.util.*;
import java.io.*;
public class Main 
{
public static void main(String[] args) throws IOException, InterruptedException
{

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter the number of stalls:");
      int n = Integer.parseInt(br.readLine());
      Double sum = 0D;
      String str ;
      for(int i=0;i<n;i++)
      {
   
      str = br.readLine();
      String []st = str.split(",");
      Stall s = new Stall(st[0],st[1],Double.parseDouble(st[2]),st[3]);
      Thread t = new Thread(s);
      t.start();
      t.join();
      sum=sum+s.getStallCost();


      }
      System.out.println("The total revenue is "+sum);

}

}
public class Stall implements Runnable 
{  

private String stallName;
private String details;
private String owner;
private Double stallCost;
private Double stallArea;

public Stall()
{
}

public Stall(String stallName,String details,Double stallArea,String owner)
{
this.stallName=stallName;
this.details=details;
this.stallArea=stallArea;
this.owner=owner;

}

public void setStallName(String stallName)
{
 this.stallName=stallName;
}
public void setStallArea(Double stallArea)
{
 this.stallArea=stallArea;
}
public void setDeatils(String details)
{
 this.details=details;
}
public void setOwner(String owner)
{
 this.owner=owner;
}
public String getStallName()
{
  return stallName;
}
public Double getStallArea()
{
  return stallArea;
}
public String getDetails()
{
  return details;
}
public String getOwner()
{
  return owner;
}
public void setStallCost(Double stallCost)
{
  this.stallCost=stallCost;
}
public Double getStallCost()
{
  return stallCost;
}
 
public void run() 
{
this.setStallCost(this.getStallArea()*150);
}

}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *