|
-
Apr 7th, 2003, 12:21 PM
#1
Thread Starter
Junior Member
Can't compile this
I'm trying to help my friend with this java crap cept I have no idea what's going on.
He thinks the problem lies within ShoppingCart.java but I will include everything.
ShoppingCart.java
-------------------------------------------------------
import java.io.*;
import java.util.*;
public class ShoppingCart
{
public static void main(String argv[])
{
// instantiates products to populate the catalog
GolfClub g1 = new GolfClub(59.99, 123456789, 25, "new", "Titleist", "driver");
GolfClub g2 = new GolfClub(69.99, 234567890, 50, "used", "Callaway", "putter");
GolfClub g3 = new GolfClub(79.99, 345678901, 75, "new", "Ping", "9 iron");
TennisBall t1 = new TennisBall(1.99, 987654321, 100, "new", "Penn", "green");
TennisBall t2 = new TennisBall(1.79, 876543210, 125, "new", "Wilson", "orange");
TennisBall t3 = new TennisBall(1.09, 765432109, 150, "used", "Gamma", "yellow");
int choice = 0;
Integer i = new Integer(0);
while(choice != 5) // choosing option 5 exits program
{
// display the menu
displayMenu();
// get input and put it into an Integer object...
try
{
i = new Integer(getString());
}
catch (NumberFormatException e1)
{
System.out.println ("ERROR - This is not a valid menu option!");
}
// ... so we can extract the int value from it
choice = i.intValue();
switch(choice)
{
case 1: // if user chooses option 1
displayCatalog(g1, g2, g3, t1, t2, t3);
break;
case 2: // if user chooses option 2
displayCart();
break;
case 3: // if user chooses option 3
addToCart();
break;
case 4: // if user chooses option 4
deleteFromCart();
break;
case 5: // if you choose 5
System.out.println("Thank you for using Crazy " +
"Larry's Shopping Cart.\n" +
"Did you hear that?\n" +
"Gotta go!\n");
break;
default: // if user chooses an invalid option
System.out.println("Invalid choice. Please try again.");
break;
}
}
}
public static String getString()
{
/**
* Retrieves a line of text from the keyboard
*
* @return A line of text from the keyboard as a String
*/
// initialize String to hold input
String returnString = "";
// creat input object
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
try
{
returnString = input.readLine();
}
catch(IOException e) {;}
return returnString;
}
public static void displayMenu()
{
System.out.println("New Menu");
System.out.println("1. Display products catalog");
System.out.println("2. Display items in cart");
System.out.println("3. Add an item to cart");
System.out.println("4. Delete an item from cart");
System.out.println("5. Exit/Checkout");
}
public static void displayCatalog(GolfClub g1, GolfClub g2, GolfClub g3, TennisBall t1, TennisBall t2, TennisBall t3)
/**
* Method for displaying the products in the catalog
*/
{
System.out.println("It# UPC Code Product Qty Price Brand Name Type/Color\n" +
" 1. " + g1.getUpc() + " golf club "+ g1.getQuantity() + " $" + g1.getPrice() + " " + g1.getBrandName() + " " +g1.getClubType() + "\n" +
" 2. " + g2.getUpc() + " golf club "+ g2.getQuantity() + " $" + g2.getPrice() + " " + g2.getBrandName() + " " +g2.getClubType() + "\n" +
" 3. " + g3.getUpc() + " golf club "+ g3.getQuantity() + " $" + g3.getPrice() + " " + g3.getBrandName() + " " +g3.getClubType() + "\n" +
" 4. " + t1.getUpc() + " tennis ball "+ t1.getQuantity() + " $" + t1.getPrice() + " " + t1.getBrandName() + " " +t1.getBallColor() + "\n" +
" 5. " + t2.getUpc() + " tennis ball "+ t2.getQuantity() + " $" + t2.getPrice() + " " + t2.getBrandName() + " " +t2.getBallColor() + "\n" +
" 6. " + t3.getUpc() + " tennis ball "+ t3.getQuantity() + " $" + t3.getPrice() + " " + t3.getBrandName() + " " +t3.getBallColor() + "\n");
}
public static void displayCart()
/**
* Method for displaying the items in the cart
*/
{
}
public static void addToCart()
/**
* Method for adding items to the cart
*/
{
}
public static void deleteFromCart()
/**
* Method for deleting items from the cart
*/
{
}
}
-------------------------------------------------------
GolfClub.java
-------------------------------------------------------
import java.util.*;
public class GolfClub extends SportingItem2 //indicates inheritance
{
// Additional attributes specific to a golf club
private String brandName;
private String clubType;
//Constructor for a new GolfClub object.
public GolfClub(double p, long u, int q, String n, String bn, String ct)
{
/* Price, UPC, quantity, and neworused are handled by the
* constructor for a SportingItem2 object, invoked with
* the following statement
*/
super(p, u, q, n);
// Attributes specific to a golf club
brandName = bn;
clubType = ct;
}
public String getBrandName()
{
return this.brandName;
}
public void setBrandName(String bn)
{
this.brandName = bn;
}
public String getClubType()
{
return this.clubType;
}
public void setClubType(String ct)
{
this.clubType = ct;
}
public String toString()
{
return "Golf Club Object:\n" +
"Price: " + this.getPrice() + "\n" +
"UPC: " +this.getUpc() + "\n" +
"Quantity: " + this.getQuantity() + "\n" +
"New or Used: " + this.getNeworused() + "\n" +
"Brand Name: " + this.brandName + "\n" +
"Club Type: " + this.clubType;
}
/**
* Method to create a deep copy of a GolfClub object
*/
public GolfClub golfClubCopy()
{
GolfClub gcopy = new GolfClub();
gcopy.price = this.price;
gcopy.upc = this.upc;
gcopy.quantity = this.quantity;
gcopy.neworused = this.neworused;
gcopy.brandName = this.brandName;
gcopy.clubType = this.clubType;
return gcopy;
}
}
-------------------------------------------------------
TennisBall.java
-------------------------------------------------------
import java.util.*;
public class TennisBall extends SportingItem2 //indicates inheritance
{
// Additional attributes specific to a tennis ball
private String brandName;
private String ballColor;
//Constructor for a new TennisBall object.
public TennisBall(double p, long u, int q, String n, String bn, String bc)
{
/* Price, UPC, quantity, and neworused are handled by the
* constructor for a SportingItem2 object, invoked with
* the following statement
*/
super(p, u, q, n);
// Attributes specific to a tennis ball
brandName = bn;
ballColor = bc;
}
public String getBrandName()
{
return this.brandName;
}
public void setBrandName(String bn)
{
this.brandName = bn;
}
public String getBallColor()
{
return this.ballColor;
}
public void setBallColor(String ct)
{
this.ballColor = ct;
}
public String toString()
{
return "Tennis Ball Object:\n" +
"Price: " + this.getPrice() + "\n" +
"UPC: " +this.getUpc() + "\n" +
"Quantity: " + this.getQuantity() + "\n" +
"New or Used: " + this.getNeworused() + "\n" +
"Brand Name: " + this.brandName + "\n" +
"Ball Color: " + this.ballColor;
}
/**
* Method to create a deep copy of a TennisBall object
*/
public TennisBall tennisBallCopy()
{
TennisBall tcopy = new TennisBall();
tcopy.price = this.price;
tcopy.upc = this.upc;
tcopy.quantity = this.quantity;
tcopy.neworused = this.neworused;
tcopy.brandName = this.brandName;
tcopy.ballColor = this.ballColor;
return tcopy;
}
}
-------------------------------------------------------
HELP!!!!!!!!!!!!!!
-
Apr 9th, 2003, 12:08 PM
#2
Lively Member
It's kinda hard to give any useful response if you don't include what kind of error you get and so on.
You don't include all code either. SportItem2 is missing, so it's hard to reconstruct the problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|