DEV Community

AmalaReegan
AmalaReegan

Posted on

Day 11 Today class:

class Supermarket
{
int price, discount; //global variables - non-static
String product_name; //global variables - non-static

public Supermarket(String product_name, int price, int discount) // parameterized constructor
{
this.price = price; //price = i1
this.discount = discount; 
this.product_name = product_name; 
}
public Supermarket(String product_name, int price)
{
this.price = price; //price = i1
this.product_name = product_name; 
}
public static void main(String[] args)
{
Supermarket product1 = new Supermarket("Good Day",10,2); 
Supermarket product2 = new Supermarket("Rice",55); 
//product1.product_name = "Good Day"; 
//product1.price = 10; //Assignment Operator
//product1.discount = 2; 
//product2.product_name = "rice"; 
//product2.price = 55; 

System.out.println(product1.product_name);
System.out.println(product2.product_name);

product1.buy(); //Method Calling Statement
product1.return_product(); 

}
public void buy()//Method Body / Definition
{
System.out.println("Buying "+product_name + " "+ (price-discount));
}
public void return_product()
{
System.out.println("Returning "+ product_name + " "+ price);
}


}
Enter fullscreen mode Exit fullscreen mode

Image description

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay