Java Codes for Retail

Only available on StudyMode
  • Download(s) : 100
  • Published : May 9, 2013
Open Document
Text Preview
Customer Class

import java.util.*; // used for Scanner and ArrayList

public class Customer
{
private String name;
private String email;
private ShoppingCart cart = new ShoppingCart();
private ArrayList transactionList = new ArrayList();

public Customer()
{
name = null;
email = null;
}

public Customer (String n, String e)
{
name = n;
email = e;
}

public void setName (String n) { name = n; }
public String getName() { return name; }
public void setEmail (String e) { email = e; }
public String getEmail() { return email; }
public void setCart(ShoppingCart c) { cart = c; }
public ShoppingCart getCart() { return cart; }

public void addTransaction (Transaction t)
{
transactionList.add(t);
}

public ArrayList getTransactionList() {return transactionList;}

//toString method
public String toString()
{
return "Name: " + name + "Email: " + email;
}
}

Fruit Class

import java.util.*; // used for Scanner and ArrayList

public abstract class Fruit
{
//attributes
private String name;
private double price;

//behaviours
public Fruit()
{
name = null;
price = 0.0;
}
public Fruit (String n, double p)
{
name = n;
price = p;
}
//set and get methods
public void setName (String n) { name = n; }
public String getName() { return name; }
public void setPrice (double p) { price = p; }
public double getPrice() { return price; }

//calculate amount for grape and apple
public abstract double calculateAmount();

//toString method
public String toString()
{
return "Name: " + name + "Price: " + price;
}
}

Grape Class

public class Grape extends Fruit
{
private double weight;

public Grape()
{
super();
weight = 0.0;
}

public Grape (String n, double p, double w)
{
super (n,p);
weight = w;
}

public void setWeight (double w) { weight = w; }
public double getWeight() { return weight; }

//calculate amount
public double calculateAmount() { return getPrice() * weight; }

//toString method
public String toString()
{
return super.toString() + "Weight: " + weight;
}

Apple Class

import java.util.*; // used for Scanner and ArrayList

public class Apple extends Fruit
{
//attributes
private int quantity;

//behaviours
public Apple()
{
super();
quantity = 0;
}
public Apple (String n, double p, int q)
{
super (n,p);
quantity = q;
}

//set and get methods
public void setQty (int q) { quantity = q; }
public int getQty() { return quantity; }

//calculate amount
public double calculateAmount() { return getPrice() * quantity; }

//toString method
public String toString()
{
return super.toString() + "Quantity: " + quantity;
}
}

Transaction Class

import java.util.*; // used for Scanner and ArrayList
import java.text.*;

public class Transaction
{
private int transactionNo;
private String date;
private double amount;

public Transaction()
{
transactionNo = 0;
amount = 0.00;
}

public Transaction (int n, String d, double amt)
{
transactionNo = n;
date = d;
amount = amt;
}

public void setTransactionNo (int n) { transactionNo = n; } public int getTransactionNo() { return transactionNo; }
public void setDate (String d) { date = d; }
public String getDate() { return date;}
public void setAmount (double amt) { amount = amt; }
public double getAmount() { return amount; }

//toString method
public String toString()
{
return "Transaction(#): " + transactionNo + "Date: " + date + "Amount($): " + amount; }
}

ShoppingCart Class

import java.util.*; // used for Scanner and ArrayList
import java.text.*;

public class ShoppingCart
{
private ArrayList itemList = new...
tracking img