** * Test Food class */ public class FoodTester { public static void main(String[] args) { Food berries = new Food("Strawberries", 4.95, 10); Food cheese = new Food("String Cheese", 5.50, 1); Food spinach = new Food("Spinach",3.95, 0.2); Food cucumber = new Food("Cucumber", 1.50, 0.9); Food rice = new Food("Rice", 4.95, 45.0); System.out.println(rice.getCarbs()); System.out.println("Expected: 45"); System.out.println(spinach.getCarbs()); System.out.println("Expected: 0.2"); System.out.println(cheese.isZeroCarb()); System.out.println("Expected: false"); System.out.println(berries.isZeroCarb()); System.out.println("Expected: false"); System.out.println(spinach.isZeroCarb()); System.out.println("Expected: true"); System.out.println(cucumber.isZeroCarb()); System.out.println("Expected: true"); System.out.println(spinach.getDescription()); System.out.println("Expected: Spinach carbs=0.2"); System.out.println(cheese.getDescription()); System.out.println("Expected: String Cheese carbs=1.0"); } } Product.java /** * Models a product wih a price and description */ public class Product { private double price; private String description; /** * Constructs a Product with a price and description * @param thePrice the price of this product * @param theDescription the description of this * product */ public Product(String theDescription, double thePrice ) { price = thePrice; description = theDescription; } /** * Gets the price of this Product * @return the price of this object */ public double getPrice() { return price; } /** * Gets the description of this Product * @return the description of this Product */ public String getDescription() { return description; } /** * Reduce the price by the given percent * @param percent the pecentage to reduce the price by */ public void reducePrice(double percent) { price = price - price * percent/100; } /** * Increase the price of the Product by the * given percent * @param percent the percentage to increase the * price by */ public void increasePrice(double percent) { price = price * (1.0 + percent/100); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

/** * Test Food class */ public class FoodTester { public static void main(String[] args) { Food berries = new Food("Strawberries", 4.95, 10); Food cheese = new Food("String Cheese", 5.50, 1); Food spinach = new Food("Spinach",3.95, 0.2); Food cucumber = new Food("Cucumber", 1.50, 0.9); Food rice = new Food("Rice", 4.95, 45.0); System.out.println(rice.getCarbs()); System.out.println("Expected: 45"); System.out.println(spinach.getCarbs()); System.out.println("Expected: 0.2"); System.out.println(cheese.isZeroCarb()); System.out.println("Expected: false"); System.out.println(berries.isZeroCarb()); System.out.println("Expected: false"); System.out.println(spinach.isZeroCarb()); System.out.println("Expected: true"); System.out.println(cucumber.isZeroCarb()); System.out.println("Expected: true"); System.out.println(spinach.getDescription()); System.out.println("Expected: Spinach carbs=0.2"); System.out.println(cheese.getDescription()); System.out.println("Expected: String Cheese carbs=1.0"); } }

Product.java

/** * Models a product wih a price and description */ public class Product { private double price; private String description; /** * Constructs a Product with a price and description * @param thePrice the price of this product * @param theDescription the description of this * product */ public Product(String theDescription, double thePrice ) { price = thePrice; description = theDescription; } /** * Gets the price of this Product * @return the price of this object */ public double getPrice() { return price; } /** * Gets the description of this Product * @return the description of this Product */ public String getDescription() { return description; } /** * Reduce the price by the given percent * @param percent the pecentage to reduce the price by */ public void reducePrice(double percent) { price = price - price * percent/100; } /** * Increase the price of the Product by the * given percent * @param percent the percentage to increase the * price by */ public void increasePrice(double percent) { price = price * (1.0 + percent/100); } }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education