Results 1 to 4 of 4
- 11-28-2012, 06:44 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
- 11-28-2012, 06:57 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Text User Interface, can't get a method which adds a customer to work
your (commented-out) method call is wrong
Customer customer = new Customer(fName, lName, acctNumber, street, town, postcode);
//customerList.addCustomer = new Customer(fName, lName, acctNumber, street, town, postcode);
This is not compilable!
customerList.addCustomer(new Customer.......));
Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
and it should be working :)
- 11-28-2012, 10:57 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Re: Text User Interface, can't get a method which adds a customer to work
works like a treat - many thanks eRaaaa
- 11-29-2012, 05:33 AM #4
Re: Text User Interface, can't get a method which adds a customer to work
In future, don't edit a post that has a response, as that removed the context of the reply.
This is what was originally posted. I have added code tags for readability.
db
THREAD CLOSED
-
this isssignment i'm having a bit of trouble with
i'm given the class called HW4CustomerList, i have to make a Text Based User Interface
the class (below) CustomerTUI contains a method called addCustomer which adds a new object to an arraylist - i'm not particularly sure what is wribg with it
The class specification says that I cannot take any parameters (i.e. a no-args method). we have used the BlueJ 'method box' to interact with objects and put them in array lists, I do not know if this can be used in this particular instance.
below is my CustomerTUI, HW4CustomerList and Customer classes
CustomerTUI class
Java Code:import java.util.Scanner; /** * Provides a text based user interface application to be used to manage the use of HW4CustomerList * */ public class CustomerTUI { //attributes private HW4CustomerList customerList; private Scanner myScanner; /** * Constructor for objects of class CustomerTUI */ public CustomerTUI() { customerList = new HW4CustomerList(); myScanner = new Scanner(System.in); } public void menu() { int command = -1; while (command != 0) { displayMenu(); command = getCommand(); execute(command); } } /** * add a customer to the collection * @param details of the customer to add */ private void addCustomer() { Scanner myScanner = new Scanner(System.in); System.out.println("Enter the first name of the Customer "); String fName = myScanner.nextLine(); System.out.println("Enter the last name of the Customer"); String lName = myScanner.nextLine(); System.out.println("Enter the account number of the Customer"); String acctNumber = myScanner.nextLine(); System.out.println("Enter street name of the Customer's address: "); String street = myScanner.nextLine(); System.out.println("Enter the town name of the Customer's address: "); String town = myScanner.nextLine(); System.out.println("Enter post code of the Customer's address: "); String postcode = myScanner.nextLine(); Customer customer = new Customer(fName, lName, acctNumber, street, town, postcode); //customerList.addCustomer = new Customer(fName, lName, acctNumber, street, town, postcode); System.out.println("Customer successfully added to the collection"); } /** * Displays the Text User Interface * @param tells the user what key to press to access which function */ private void displayMenu() { System.out.println("¦------------------------------------------------------------¦"); System.out.println("¦Please enter the number of the function you would like to ¦"); System.out.println("¦carry out from the list below ¦"); System.out.println("¦------------------------------------------------------------¦"); System.out.println("¦ Function ¦Option # ¦"); System.out.println("¦Add a Customer to the collection ¦ 1 ¦"); System.out.println("¦Get the number of Customers in the collection ¦ 2 ¦"); System.out.println("¦Show all Customer details ¦ 3 ¦"); System.out.println("¦Remove a Customer from the collection ¦ 4 ¦"); System.out.println("¦Display the details of a customer (Account Number)¦ 5 ¦"); System.out.println("¦quit the application ¦ 6 ¦"); System.out.println("¦------------------------------------------------------------¦"); } /** * */ private int getCommand() { System.out.println("\n" + "Enter command: "); return myScanner.nextInt(); } private void execute(int command) { if (command == 1) { addCustomer(); System.out.println(""); } else if (command == 2) { getNumberOfCustomers(); System.out.println(""); } else if (command == 3) { showAllCustomers(); System.out.println(""); } else if (command == 4) { removeCustomer(); System.out.println(""); } else if (command == 5) { showCustomer(); System.out.println(""); } else if (command == 6) { quitCommand(); System.out.println(""); } else { unknownCommand(command); System.out.println(""); } } private void getNumberOfCustomers() { if (customerList.getNumberOfCustomers() == 0) { System.out.println("There are no customers to display"); } else if (customerList.getNumberOfCustomers() == 1) { System.out.println("We have:" + customerList.getNumberOfCustomers() + " customer"); } else { System.out.println("We have:" + customerList.getNumberOfCustomers() + " customers"); } } private void showAllCustomers() { if (customerList.getNumberOfCustomers() == 0) { System.out.println("There are no customers to display"); } else { customerList.getAllCustomers(); } } private void removeCustomer() { String acctNo; System.out.print("Enter the account number of the Customer to be removed from the collection"); acctNo = myScanner.next(); if (customerList.removeCustomer(acctNo) == true) { System.out.println("Customer with account number: " + acctNo + ", was removed successfully"); } else { System.out.println("Removal of the Customer with account number: " + acctNo + ", was not successful, no such customer"); } } private void showCustomer() { String acctNo; System.out.println("Enter the account number of the customer to be displayed: "); acctNo = myScanner.next(); if (customerList.getCustomer(acctNo) == false) { System.out.println("Customer with account number: " + acctNo + "was not found"); System.out.println("Please try again"); } else { return; } } private void quitCommand() { System.out.println("This application is now closing"); System.exit(0); } private void unknownCommand(int command) { System.out.println("Command #" + command + " is not valid, Please enter an integer between 1-6"); } } // end classWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
How to set background color in User Interface?
By rachyrach in forum New To JavaReplies: 2Last Post: 04-16-2011, 05:42 PM -
Java user interface problem
By eevaa in forum New To JavaReplies: 4Last Post: 05-23-2010, 02:52 PM -
User Interface
By swikar.java in forum Advanced JavaReplies: 16Last Post: 12-09-2008, 02:37 PM -
user interface development using JSP
By pradeep1_mca@yahoo.com in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 06-02-2008, 01:48 PM -
Help user interface
By carl in forum New To JavaReplies: 1Last Post: 07-31-2007, 07:58 PM


LinkBack URL
About LinkBacks


Bookmarks