Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help me please, im stuck!

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me please, im stuck!

    Hi,

    I am struggling to finish off my java program and cannoy solve the errors i am getting. I have two classes left that i am struggling with an would really appriciate any help i would get.

    Class ~ Customer (inherits Person)
    This class describes an object representing one customer, obtaining some of its attributes and methods from its super-class.
    customerPoints has neither a set method nor a get method. It is accessed solely within the Customer class.

    Customer()
    Initialises string attributes as empty strings.

    Customer(firstName : String, surname : String, phoneNo : String, email: String)
    Initialises attributes from parameters where appropriate, creates a new PointsRecord object.

    addPoints(saleValue : double, category : int) : int
    Calls the addPoints(double, int) method in the customer's PointsRecord object and passes the parameters on to that method. The value (representing points added) passed back from that method is returned from this method.

    redeemPoints(points : int) : int
    Calls the redeemPoints method in PointsRecord, passing the number of points. The value returned by that method is passed back from this method. Note that a return of -1 indicates that the redemption was unsuccessful.

    getLifetimePoints() : int
    Calls the corresponding method in PointsRecord to find out the total points earned throughout the customer's membership.

    getCurrentPoints() : int
    Calls the corresponding method in PointsRecord to find out the current points held by the customer.

    Class ~ CustomerList
    Holds a collection of customers who are registered with the loyalty scheme. It has an ArrayList of Customer objects. The ArrayList has neither a set method nor a get method.
    It has three publicly-available class constants.

    CustomerList()
    Initialises the list by creating a new empty ArrayList<Customer>object.

    getCustomerNames() : String[ ]
    Creates a string array containing the full name of each customer.

    getCustomerAt(index : int) : Customer
    Uses the int parameter to retrieve the customer at the given location in the list. The Customer object is returned.

    addCustomer(customer : Customer) : void
    Adds a new Customer object to the end of the list.

    removeCustomerAt(index : int) : int
    Deletes the customer at the position given by the parameter, but only if the customer has a zero points total. The return value can be 0, 1 or 2:
    0 indicates that the deletion was successful,
    1 indicates that the index was out of range, and
    2 indicates that the customer was not deleted because their points total is not zero.
    The class constants reflect these outcomes.

    getTotalPoints() : int
    Iterates through the list of customers summing the total points in order to find out the company's total points liability.
    size() : int
    Returns the number of customers in the list.

    This is the code i have written myself for the both and it needs sorting

    Customer class

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package loyaltyscheme;

    /**
    *
    * @author Warbie
    */
    public class Customer extends Person {
    private PointsRecord customerPoints;

    public Customer() {
    firstName = "";
    surname = "";
    phoneNo = "";

    }


    public Customer(String firstName, String surname, String phoneNo, String email) {

    this.firstName = firstName;
    this.surname = surname;
    this.phoneNo = phoneNo;
    this.emailAddress = new EmailAddress(email);
    this.customerPoints = new PointsRecord();

    }

    public int addPoints(double saleValue, int category){

    return addPoints(saleValue,category) ;


    }

    public int redeemPoints(int points) {

    return redeemPoints(points);

    }

    public int getLifetimePoints () {

    return getLifetimePoints();
    }

    public int getCurrentPoints() {

    return getCurrentPoints();

    }


    @Override
    public String toString() {
    return "Customer{" + "customerPoints=" + customerPoints + '}';
    }


    }

    CustomerList class


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package loyaltyscheme;

    /**
    *
    * @author Warbie
    */

    import java.util.ArrayList;

    public class CustomerList {

    private ArrayList<Customer> list;
    public static int CUSTOMERDELETED = 0;
    public static int INVALIDINDEX = 1;
    public static int POINTSNOTZERO = 2;


    public CustomerList() {
    list = new ArrayList<Customer>();
    }
    public CustomerList(ArrayList<Customer> list) {
    this.list = list;
    }
    public String[] getCustomerNames(){

    String[] names = new String[list.size()];
    int ct = 0;

    for (Customer customer:list) {
    names[ct] = customer.getFullName();
    ct ++;
    }
    return names;
    }

    public Customer getCustomerAt (int index) {
    if (index < 0 || index > list.size())
    return null;
    else
    return list.get(index);
    }

    public void addCustomer(Customer customer) {
    list.add (customer);
    }

    public int removeCustomerAt(int index) {
    if (index < 0 || index > list.size())
    return INVALIDINDEX;
    else if (customerPoints > 0)
    return POINTSNOTZERO;
    else
    return CUSTOMERDELETED;
    }


    public int getTotalPoints() {
    return
    }

    public int size() {
    return list.size();
    }
    }

    Would really appriciate any help!!

    Thank you


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help me please, im stuck!

    You say you have errors- I suggest you post them, along with which lines they're talking about.

    Also, when you post code, it should be in the form of an SSCCE (as short as possible while still demonstrating the behavior). Don't forget the highlight tags.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Help! im stuck!
    By aznguy92 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2011, 09:16 PM
  2. Im stuck, please help
    By bigsmoke101 in forum Loops & Control Statements
    Replies: 3
    Last Post: April 12th, 2011, 04:34 PM
  3. PLEASE PLEASE I AM STUCK...
    By ThejavaBUM in forum Loops & Control Statements
    Replies: 2
    Last Post: April 5th, 2011, 10:16 PM
  4. Stuck help please!
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 5th, 2010, 05:31 PM
  5. Stuck :(
    By hing09 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 17th, 2010, 05:20 PM