3. Delete a fruit shop
A user is asked to enter an ID of the store to delete. If found, that store is erased from the record with a “Success message”. Otherwise, you must print a “not found” message.
1
Expert's answer
2016-04-08T09:00:43-0400
package javaapplication5; public class FruitShop { public FruitShop(String name,double balance,String ownerName,int age_Of_Owner, int Apples_in_stock, double price) { this.name = name; this.balance = balance; this.ownerName = ownerName; this.age_Of_Owner = age_Of_Owner; this.Apples_in_stock = Apples_in_stock; this.price = price; _id = ID; ID++; } private static int ID = 1; private String name; private double balance; private String ownerName; private int age_Of_Owner; private int Apples_in_stock; private double price; public int _id; public void printInfo() { System.out.println(name+ " "+balance+" "+ownerName+" "+this.age_Of_Owner+ " "+this.Apples_in_stock+" "+price); } }
package javaapplication5; import java.util.*; public class JavaApplication5 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); FruitShop []shop = new FruitShop[4]; for(int i =0;i<4;i++){
System.out.print("Name of fruit shop: "); String name = sc.nextLine(); System.out.print("Current balance: "); double balance = sc.nextDouble(); System.out.print("Owner name: "); String OweName = sc.nextLine(); System.out.print(" Age of owner "); int age = sc.nextInt(); System.out.print("How many apples are in stock "); int apples_in_Stock = sc.nextInt(); System.out.print("The price of each apple "); double price = sc.nextDouble(); shop[i] = new FruitShop(name,balance,OweName,age,apples_in_Stock,price); shop[i].printInfo(); } System.out.print("Enter id :"); int id = sc.nextInt(); for(int i=0;i<4;i++) { if(shop[i]._id==id)System.out.print("Success message"); else System.out.print("not found"); } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment