Question: How can I amend this code so that the quantity is the total number of fruits, which is 450, not the number 3 CODING: public

How can I amend this code so that the quantity is the total number of fruits, which is 450, not the number 3

CODING:

public class Fruit { static int count; String name; String country; int quantity; double price; Fruit() { name=""; country=""; quantity=0; price=0; count=0; } Fruit(String S1,String S2,int N,double D) { name=S1; country=S2; quantity=N; price=D; count++; } void setname(String S) { name=S; } void setcountry(String S) { country=S; } void setprice(double D) { price=D; } void setquantity(int N) { quantity=N; } String getname() { return name; } String getcountry() { return country; } double getprice() { return price; } int getquantity() { return quantity; } public static void main(String args[]) { //Creating 3 objects of class Fruit Fruit Mango=new Fruit("Mango","India",100,0.95); Fruit Apple=new Fruit("Apple","Italia",150,0.8); Fruit Orange=new Fruit("Orange","Tunisia",200,1.1); System.out.println("Displaying the instance varaibles of orange"); System.out.println(Orange.getname()); System.out.println(Orange.getcountry()); System.out.println(Orange.getprice()); System.out.println(Orange.getquantity()); Mango.setprice(1.5);//updating the price of Mango System.out.println("Displaying Total Fruit Objects"); System.out.println("Total Fruits:"+Fruit.count); System.out.println("Displaying the instance varaibles of Mango"); System.out.println(Mango.getname()); System.out.println(Mango.getcountry()); System.out.println(Mango.getprice()); System.out.println(Mango.getquantity()); } }

the output must to be like this

How can I amend this code so that the quantity is the

Name: Orange Country: Tunisia Price: 1.1 Quantity: 280 Total number of fruit: 458 Name: Mango Country: India Price: 1.5 Quantity: 190 un OG Problems Build TODO O Terra completed successfully in 30 s 153 ms 12 minutes ago

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!