Answer to Question #58915 in Java | JSP | JSF for Nithya

Question #58915
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");
}
}

}

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
APPROVED BY CLIENTS