Can someone tell what\'s wrong with this part of the program. It\'s giving me an
ID: 3673223 • Letter: C
Question
Can someone tell what's wrong with this part of the program. It's giving me an error on the 1st line saying the string literal is not properly closed by a double quote. When I do have a double quote..
Explanation / Answer
public class RetailItem {
String description;
int units;
double price;
public RetailItem() {
// TODO Auto-generated constructor stub
}
/**
* @param description
* @param units
* @param price
*/
public RetailItem(String description, int units, double price) {
super();
this.description = description;
this.units = units;
this.price = price;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @return the units
*/
public int getUnits() {
return units;
}
/**
* @return the price
*/
public double getPrice() {
return price;
}
/**
* @param description
* the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @param units
* the units to set
*/
public void setUnits(int units) {
this.units = units;
}
/**
* @param price
* the price to set
*/
public void setPrice(double price) {
this.price = price;
}
public static void main(String[] args) {
String str = "Shirt";
// RetailItem with the three objects
RetailItem r1 = new RetailItem("Jacket", 12, 59.95);
RetailItem r2 = new RetailItem("Designer Jeans", 40, 34.95);
RetailItem r3 = new RetailItem();
// function call to set value
r3.setDescription(str);
r3.setUnits(20);
r3.setPrice(24.95);
System.out.println("_________________________ _____________________");
System.out.println(" Description Units on Hand Price");
System.out.println("__________________________ _____________________");
// accessor function calls
System.out.println("Item #1 " + r1.getDescription() + " "
+ r1.getUnits() + " " + r1.getPrice());
System.out.println("Item #2 " + r2.getDescription() + " "
+ r2.getUnits() + " " + r2.getPrice());
System.out.println("Item #3 " + r3.getDescription() + " "
+ r3.getUnits() + " " + r3.getPrice());
}
}
OUTPUT:
_________________________ _____________________
Description Units on Hand Price
__________________________ _____________________
Item #1 Jacket 12 59.95
Item #2 Designer Jeans 40 34.95
Item #3 Shirt 20 24.95
NOTE: please check the constructors and setter and getters
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.