- import java.util.*;
- public class RestaurantDemo {
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- int foodId,quantity;
- String name;
- double price;
- int n=sc.nextInt();
- Food []fd=new Food[n];
- for(int i=0;i<n;i++)
- {
- foodId=sc.nextInt();
- name=sc.next();
- price=sc.nextDouble();
- quantity=sc.nextInt();
- fd[i]=new Food(foodId,name,price,quantity);
- }
- System.out.println("Enter quantity");
- int qt=sc.nextInt();
- Food []result=findFoodByQuantity(qt,fd);
- System.out.println("Find food by quantity");
- System.out.println("---------------------------");
- for(int i=0;i<result.length;i++)
- System.out.println(result[i].getFoodId()+" "+result[i].getName()+" "+result[i].getPrice()+" "+result[i].getQuantity());
- Food food=findFoodWithHighestBill(fd);
- System.out.println("Find food with highest bill");
- System.out.println("---------------------------");
- System.out.println(food.getFoodId()+" "+food.getName()+" "+food.getPrice()+" "+food.getQuantity());
- }
- // Method find food by the quantity
- // Implement
- public static Food[] findFoodByQuantity(int qt, Food[] fd) {
- int count=0;
- for(int i=0;i<fd.length;i++)
- {
- if(fd[i].getQuantity()>qt)
- {
- count++;
- }
- }
- Food []result= new Food[count];
- int j=0;
- for(int i=0;i<fd.length;i++)
- {
- if(fd[i].getQuantity()>qt)
- {
- result[j++]=fd[i];
- }
- }
- return result;
- }
- //Method Find food with highest Bill
- //Implement
- public static Food findFoodWithHighestBill(Food[] fd)
- {
- double bill;
- Food max=fd[0];
- double maxbill=fd[0].getPrice()*fd[0].getQuantity();
- for(int i=0;i<fd.length;i++)
- {
- bill=fd[i].getPrice()*fd[i].getQuantity();
- if(bill>maxbill)
- {
- max=fd[i];
- maxbill=bill;
- }
- }
- return max;
- }
- }
- ###### FOOD ###
- public class Food {
- int foodId;
- String name;
- double price;
- int quantity;
- public Food(int foodId, String name, double price, int quantity)
- {
- this.foodId = foodId;
- this.name = name;
- this.price = price;
- this.quantity = quantity;
- }
- public int getFoodId() {
- return foodId;
- }
- public void setFoodId(int foodId) {
- this.foodId = foodId;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- public int getQuantity() {
- return quantity;
- }
- public void setQuantity(int quantity) {
- this.quantity = quantity;
- }
- }
[text] jfood
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: