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

Thread: please help me to solve my code. i am using vector and there is some errors

  1. #1
    Junior Member stevierasilim's Avatar
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help me to solve my code. i am using vector and there is some errors

    import java.util.*;
    public class steviarasilimvector
    {
    	public static void main (String[]args)
    	{
    		Scanner scan = new Scanner (System.in);
    		int choose = 0;
    		int phnumber = 0;
    		String address = "";
    		String name = "";
    		String phnumber3 = "";
    		String deletename = "";
     
    		Vector<String> name2 = new Vector<String>();
    		Vector<String> address2 = new Vector<String>();
    		Vector<Integer> phnumber2 = new Vector<Integer>();
     
    		do
    		{
    		System.out.println("================");
    		System.out.println("| Contact Book |");
    		System.out.println("================");
    		System.out.println("1. Add a contact");
    		System.out.println("2. List all contacts");
    		System.out.println("3. Delete a contact");
    		System.out.println("4. Exit");
    		do
    		{
    		System.out.print("Choose [1..4] : ");
    		choose = scan.nextInt();scan.nextLine();
    		}while (choose<1 || choose>4);
     
    		switch (choose)
    		{
    			case 1 :
    			System.out.println("====================");
    			System.out.println("| 1. Add a contact |");
    			System.out.println("====================");
    			do
    			{
    				System.out.print("Input the name [3..20] : ");
    				name = scan.nextLine();
    				name2.add(name);
    			}while (name.length()<3||name.length()>20);
    			do
    			{
    				System.out.print("\nInput the phone number [must be numeric and max. 10 digits] : ");
    			try
    			{
    				phnumber = scan.nextInt();scan.nextLine(); //int
    				phnumber2.add(phnumber); //vector
    				phnumber3 = ""+phnumber; //string
    			}catch (Exception e)
    			{
    				System.out.println("Sorry, the phone number must be numeric and max. 10 digits...");
    				scan.nextLine();
    			}
    			}while (phnumber3.length()<1||phnumber3.length()>10);
    			do
    			{
    				System.out.print("\nInput the address [must be start with \"street\" : ");
    				address = scan.nextLine();
    				address2.add(address);
    			}while(address.startsWith("street")==false);
     
    			break;
     
    			case 2 :
    			{
    			System.out.println("========================");
    			System.out.println("| 2. List all contacts |");
    			System.out.println("========================");
    			for (int i=0;i<address2.size();i++)
    			{
    			System.out.println("No      :  "+(i+1));
    			System.out.println("Name    :  "+name2.get(i));
    			System.out.println("Phone   :  "+phnumber2.get(i));
    			System.out.println("Address :  "+address2.get(i));
    			System.out.println("-----------------------------------------");
    			System.out.println("Press ENTER to back to Menu...");
    			}
    			}	break;
     
    			case 3 :
    			System.out.println("=======================");
    			System.out.println("| 3. Delete a contact |");
    			System.out.println("=======================");
    			System.out.println("Input the name [3..20] : ");
    			deletename = scan.nextLine();
    			for (int i=0;i<name2.size();i++)
    			{
    				if(deletename.equals(name2.get(i)))
    				{
    					name2.remove(i);
    					address2.remove(i);
    					phnumber2.remove(i);
    					System.out.println("Deleting "+deletename+" succesfully");
    					break;
    				}
    			}
    		}
    		}while (choose !=4);
    	}
    }


    --- Update ---

    here is the error :
    G:\stevia\algo algo\steviarasilimvector.java:14: cannot access Vector
    bad class file: .\Vector.java
    file does not contain class Vector
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    Vector<String> name2 = new Vector<String>();
    ^
    1 error

    Tool completed with exit code 1

    anyone please help, this is an assignment. thank you


  2. #2
    Junior Member
    Join Date
    May 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help me to solve my code. i am using vector and there is some errors

    What inputs did you include or does it execute like that? I executed in Eclipse with little problem.

    Reverse

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help me to solve my code. i am using vector and there is some errors

    The code is fine, Maybe your file is in a bad sector, try c:\

  4. #4
    Junior Member stevierasilim's Avatar
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help me to solve my code. i am using vector and there is some errors

    Quote Originally Posted by reverse View Post
    What inputs did you include or does it execute like that? I executed in Eclipse with little problem.

    Reverse
    Noo i didnt Include Any input :/

    --- Update ---

    Quote Originally Posted by deitynitros View Post
    The code is fine, Maybe your file is in a bad sector, try c:\
    Thanks For Helping i'll Try To Move it to C:\

Similar Threads

  1. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  2. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  3. can anyone help me solve this code
    By sudeep22 in forum Other Programming Languages
    Replies: 1
    Last Post: September 25th, 2011, 10:18 PM
  4. Replies: 4
    Last Post: August 10th, 2011, 11:16 AM
  5. help me out with the following code to solve the error
    By romilc in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 11th, 2009, 03:45 AM

Tags for this Thread