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 13 of 13

Thread: Project help

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Project help

    I have a project in which I have to add a clients name address,id number, and hours worked
    the second option is to check if the id exists print out the previous information if not to show a message to add client.

    I made a switch statement in the main method.
    in the client class i made a constructor to pass the name,id, address, hours worked and the idsearch

    I created a boolean method for the idsearching.

    I thought that a loop would be helpful after the boolean expressing to print out the information I just dont know how to write it.

    any help?
    import java.util.ArrayList;
     
    public class Monroy_Client 
    {
     
    	private String nam, adrs, num, idSearchNumber;
    	private int hrs;
     
    	public Monroy_Client(String name, String address, String idnumber, String idsearch, int hours)
    	{
    		nam = name;
    		adrs = address;
    		num = idnumber;
    		hrs =hours;
    		idSearchNumber = idsearch;
    	}
    	public void setName(String name)
    	{
    		nam = name;
    	}
    	public void setAddress(String address)
    	{
    		adrs = address;
    	}
    	public void setIdNumber(String idnumber)
    	{
    		num = idnumber;
    	}
    	public void setHours(int hours)
    	{
    		hrs = hours;
    	}
    	public void setIdSearchNumber(String idsearch)
    	{
    		idSearchNumber =idsearch;
    	}
    	public String getName()
    	{
    		return nam;
    	}
    	public String getAddress()
    	{
    		return adrs;
    	}
    	public String getIdNumber()
    	{
    		return num;
    	}
    	public String getIdSearchNumber()
    	{
    		return idSearchNumber;
    	}
     
    	public int getHours()
    	{
    		return hrs;
    	}
     
    	public boolean searchIdNumber(String idnumber, String idsearch )
    	{
    		if(!idsearch.equals(idnumber))
    			{
    				return true;
    			}
    			return false;
     
    }
    }


    import java.util.*;
    import javax.swing.*;
    import java.util.List;
     
    public class Monroy_PP1 
    {
     
     
    	public static void main(String[] args) 
    	{
     
     
    		Scanner keyboard = new Scanner(System.in);
    		String name = null, address = null, id = null, idsearch = null;
    		int hoursWorked = 0;
     
    		Monroy_Client newClient = new Monroy_Client(name, address, id, idsearch, hoursWorked);
    		ArrayList<Monroy_Client> clients = new ArrayList<Monroy_Client>();
    		clients.add(newClient);
     
    		int selection = Integer.parseInt(JOptionPane.showInputDialog("Pick an option"
    				+ "\n1.- Add client"
    				+ "\n2.- Create Invoice"
    				+ "\n3.-Quit"));
    		switch(selection)
    		{
    		case 1:
    		{
    			System.out.println("Enter Client's ID Number");
    			id = keyboard.nextLine();
    			System.out.println("Enter Client's name ");
    			name = keyboard.nextLine();
    			System.out.println("Enter Client's Address");
    			address = keyboard.nextLine();
    			System.out.println("Enter How many Hours Worked");
    			hoursWorked = keyboard.nextInt();
    			break;
     
    		}
    		case 2:
    		{
    			JOptionPane.showInputDialog("Enter Client's ID Number");
    			idsearch = keyboard.next();
    			break;
     
     
    		}
    		case 3:
    		{
    			break;
    		}
    		}
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Project help

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    What part specifically do you need help with? Ask specific questions that give us some idea what help you need.

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Project help

    the second case where it performs the search.
    is the boolean method correctly?
    also if the boolean is true is suppose to print out previous information the name,etc..
    how can i do that?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Project help

    the second case where it performs the search.
    I don't think so, and I'm not sure that a single method that returns a boolean is the best approach. First, A method should take an id number as a parameter, compare that to each existing client's id number, and if the id number exists, return either the corresponding object or the object's index in the collection where it exists. If the id number doesn't already exist, then the program should accept data for that id number.
    also if the boolean is true is suppose to print out previous information
    Use program logic:
    if ( idNumberMatches( idNumber ) )
    {
        // this statement assumes there is a toString() method:
        System.out.println( "" + monroy_ClientInstance );\
    }

  5. The Following User Says Thank You to GregBrannon For This Useful Post:

    anniexd92 (March 8th, 2014)

  6. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Project help

    I see thank you..
    One last question to make the class object and arrayList is that suppose to be before the switch statement or after it.

  7. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Project help

    The client class should include a method that compares an id number and returns true or false. The ArrayList contains all instances of the client class to iterate and check for the desired id number. The method that checks the ArrayList of instances should be part of the tester class. All of this should be setup before the switch statement in the tester class, and then the switch statement reads the user's menu choice and determines what to do.

  8. #7
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Project Not Working

    I'm suppose to create a program with 3 options
    1. add client
    which requires to get name, address, id number, and hours worked

    2.create invoice
    in which it will ask for the id to search and if its stored it will display all information if it doesn't
    it will display a message.

    3.quit

    I cant seem to store the information in the arrayList correctly, and secondly when choose the second option it asks for the id but then doesn't display anything.

    this are my codes

    import java.util.*;
     
    import javax.swing.*;
     
    import java.util.List;
     
    public class Monroy_PP1 
    {
     
     
    	public static void main(String[] args) 
    	{
     
     
    		Scanner keyboard = new Scanner(System.in);
    		String name = null, address = null, id = null, idsearch = null;
    		int hoursWorked = 0;
     
    		Monroy_Client newClient = new Monroy_Client(name, address, id, hoursWorked);
    		ArrayList<Monroy_Client> clients = new ArrayList<Monroy_Client>();
    		clients.add(newClient);	
     
     
    		int selection = Integer.parseInt(JOptionPane.showInputDialog("Pick an option"
    				+ "\n1.- Add client"
    				+ "\n2.- Create Invoice"
    				+ "\n3.-Quit"));
    		switch(selection)
    		{
    		case 1:
    		{
    			System.out.println("Enter Client's ID Number");
    			id = keyboard.nextLine();
    			System.out.println("Enter Client's name ");
    			name = keyboard.nextLine();
    			System.out.println("Enter Client's Address");
    			address = keyboard.nextLine();
    			System.out.println("Enter How many Hours Worked");
    			hoursWorked = keyboard.nextInt();
    			break;
     
    		}
    		case 2:
    		{
    			JOptionPane.showInputDialog("Enter Client's ID Number");
    			idsearch = keyboard.next();
    			newClient.searchIdNumber(id, idsearch);
    			break;
     
     
    		}
    		case 3:
    		{
    			break;
    		}
    		}
     
    }
    }

    import java.util.ArrayList;
     
    import javax.swing.JOptionPane;
     
    public class Monroy_Client 
    {
     
    	private String nam, adrs, num, idSearchNumber;
    	private int hrs;
     
    	public Monroy_Client(String name, String address, String idnumber, int hours)
    	{
    		nam = name;
    		adrs = address;
    		num = idnumber;
    		hrs =hours;
     
    	}
    	public void setName(String name)
    	{
    		nam = name;
    	}
    	public void setAddress(String address)
    	{
    		adrs = address;
    	}
    	public void setIdNumber(String idnumber)
    	{
    		num = idnumber;
    	}
    	public void setHours(int hours)
    	{
    		hrs = hours;
    	}
    	public String getName()
    	{
    		return nam;
    	}
    	public String getAddress()
    	{
    		return adrs;
    	}
    	public String getIdNumber()
    	{
    		return num;
    	}
     
    	public int getHours()
    	{
    		return hrs;
    	}
     
     
     
    	public void searchIdNumber(String idnumber, String idsearch )
    	{
    		if(idsearch.equals(idnumber))
    		{
    			System.out.print(toString());
    		}
    		else 
    		{
    			JOptionPane.showMessageDialog(null, "CLient not found please add Client");
    		}
    	}
     
    	public  String toString()
    	{
    		String output = nam +"\n" + adrs + "\n" + num + "\n" + hrs;
    		return output;
    	}
     
     
     
     
    }

  9. #8
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Project help

    This are the methods I added to search for the ID
    public void searchIdNumber(String idnumber, String idsearch )
    	{
    		if(idsearch.equals(idnumber))
    		{
    			System.out.print(toString());
    		}
    		else 
    		{
    			JOptionPane.showMessageDialog(null, "CLient not found please add Client");
    		}
    	}
     
    	public  String toString()
    	{
    		String output = nam +"\n" + adrs + "\n" + num + "\n" + hrs;
    		return output;
    	}

    in the tester class the 2 case in the switch statement looks like this

    	case 2:
    		{
    			JOptionPane.showInputDialog("Enter Client's ID Number");
    			idsearch = keyboard.next();
    			newClient.searchIdNumber(id, idsearch);
    			break;
     
     
    		}

  10. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Project Not Working

    I cant seem to store the information in the arrayList correctly,
    Can you explain? Are there error messages? Copy the full text and post it here.
    Is the output wrong? Copy the output, paste it here and add comments describing what you want it to be.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #10
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Project Not Working

    There aren't any error messages but when I run the program I type information and when I go and look for the ID number it doesn't display anything its just blank but it keeps running the program.

  12. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Project Not Working

    it keeps running the program.
    Where is the code executing? Add some println() statements to show where the code is executing.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #12
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Project Not Working

    Quote Originally Posted by Norm View Post
    Where is the code executing? Add some println() statements to show where the code is executing.
    That's the thing I dont Know where it is executing. Supposedly it should be doing the searchIDNumber method

  14. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Project Not Working

    I dont Know where it is executing
    Add println statements that print messages when they are executed. That will show you where the code is executing. For example:
    System.out.println("at start of loop1");
    ....
    System.out.println("at start of switch");
    ...
    System.out.println("at end of switch");
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. About the project
    By Mythilyrajaiah in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 3rd, 2013, 06:41 PM
  2. Need some help on my HS Project
    By ntilli in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 12th, 2011, 09:22 PM
  3. Help with Project
    By rawrxeroes in forum Object Oriented Programming
    Replies: 1
    Last Post: October 12th, 2011, 07:12 AM
  4. need help in my project
    By flana in forum The Cafe
    Replies: 4
    Last Post: October 11th, 2011, 06:13 AM
  5. Need Help With Project
    By jstew132 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 11th, 2009, 07:15 PM

Tags for this Thread