public class Store {
// instance fields
String productType;
double price;
// constructor method
public Store(String product, double initialPrice) {
productType = product;
price = initialPrice;
}
// increase price method
public void increasePrice(double priceToAdd){
double newPrice = price + priceToAdd;
price = newPrice;
}
// get price with tax method
public double getPriceWithTax(){
double totalPrice = price+price *0.08;
return totalPrice;
}
// main method
public static void main(String[] args) {
Store lemonadeStand = new Store("Lemonade", 3.75);
double lemonadePrice = lemonadeStand.getPriceWithTax();
System.out.println(lemonadePrice);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter