Item - String item; if (name.length() >= 8) item...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// *************************************************************** // Item.java // // Represents an item in a shopping cart. // *************************************************************** import java.text.NumberFormat; public class Item { private String name; private double price; private int quantity; // ------------------------------------------------------- // Create a new item with the given attributes. // ------------------------------------------------------- public Item (String itemName, double itemPrice, int numPurchased) { name = itemName; price = itemPrice; quantity = numPurchased; } // ------------------------------------------------------- // Return a string with the information about the item // ------------------------------------------------------- public String toString () { NumberFormat fmt = NumberFormat.getCurrencyInstance();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: String item; if (name.length() >= 8) item = name + "\t"; else item = name + "\t\t"; return (item + " " + fmt.format(price) + "\t " + quantity + "\t\t" + fmt.format(price*quantity)); } // -------------------------------------------------// Returns the unit price of the item // -------------------------------------------------public double getPrice() { return price; } // -------------------------------------------------// Returns the name of the item // -------------------------------------------------public String getName() { return name; } // -------------------------------------------------// Returns the quantity of the item // -------------------------------------------------public int getQuantity() { return quantity; } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Page1 / 2

Item - String item; if (name.length() >= 8) item...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online