Results 1 to 6 of 6
  1. #1
    iamamyth is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default Need some help with java coding

    So I worked on this program called SpyRing

    requirement:

    1. Create 3 classes: Spy, SpyRing, and SpyRingMaker. The last class will be the driver.
    Each Spy HAS-A spy number (String), name (String), and ArrayList (of Strings) for aliases. The constructor should set the spy number and name and create the empty ArrayList for aliases. You will need accessor methods, a toString() method, and a method for adding aliases.
    Each SpyRing HAS-A country (String) and an ArrayList (of Spys). The constructor should set the country and create this empty ArrayList. You will need an accessor method for the ArrayList and a method for adding Spys.
    The SpyRingMaker class should prompt the user for a country and create a new SpyRing. A menu (in a loop) should offer the user the following choices:
    (1) Enter a spy for your spy ring
    (2) Print Spy Ring
    (3) Quit.
    If the user chooses option 1, the user should be prompted for the spy number and name, and a Spy should be added to the SpyRing. Under option 1, another menu (in another loop) should then be presented with the following choices:
    (1) Enter an alias for this spy
    (2) Done with this spy
    When printing the SpyRing, you’ll probably want to use the “For Each” syntax.

  2. #2
    iamamyth is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default Re: Need some help with java coding

    And here's what i got so far

    import java.util.*;
    import cs1.Keyboard;
    public class SpyRingMaker
    {
    public static void main(String[]args)
    {
    boolean con=true;
    boolean cont =true;

    ArrayList<Spy> newspy= new ArrayList<Spy>();
    SpyRing sr=new SpyRing("America",newspy);

    while(cont)
    {
    con=true;
    System.out.println("enter 1 to enter a spy for spy ring");
    System.out.println("enter 2 to pring spy ring ");
    System.out.println("enter 3 to quit");
    int op=Keyboard.readInt();


    switch(op)
    {
    case 1:
    System.out.println("enter the spy's name");
    String newname=Keyboard.readString();
    System.out.println("enter the spy's number");
    String newnum=Keyboard.readString();





    while(con)
    {
    System.out.println("enter 1 to enter an alias for this spy");
    System.out.println("enter 2 to exit this spy");
    int sc=Keyboard.readInt();
    if(sc==1)
    {
    System.out.println("enter one alias");
    String alia=Keyboard.readString();
    new Spy(newname,newnum).addAli(alia);

    }
    else
    con=false;
    }
    SpyRing.addSpy(new Spy(newnum,newname));

    break;
    case 2:

    for(Spy each:newspy)
    {
    System.out.println(each);
    }



    break;
    case 3:
    cont=false;

    }
    }
    }
    }

  3. #3
    iamamyth is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default Re: Need some help with java coding

    import java.util.*;
    public class SpyRing
    {
    String con;
    public static ArrayList<Spy> aspy=new ArrayList<Spy>();
    public SpyRing(String inCon, ArrayList<Spy> inSpy)
    {

    con=inCon;
    aspy=inSpy;
    }

    public ArrayList getSpy()
    {
    return aspy;
    }

    public static void addSpy(Spy spy)
    {
    aspy.add(aspy.size(),spy);
    }
    }


    And this :


    import java.util.*;
    public class Spy
    {
    String num,name;
    ArrayList<String> ali;

    public Spy(String inNum, String inName)
    {
    num=inNum;
    name=inName;
    ali=new ArrayList<String>();

    }

    public String getName()
    {
    return name;
    }

    public String getNum()
    {
    return num;
    }

    public ArrayList getAli()
    {
    return ali;
    }
    public String toString()
    {
    return num+" "+ name+" " +ali;
    }

    public void addAli(String adal)
    {
    ali.add(ali.size(),adal);
    }


    }

  4. #4
    iamamyth is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default Re: Need some help with java coding

    Each spy is suppose to have its own alias, but my program displays same aliases for all the spies.
    would someone please help me find the mistakes
    thank you all in advance

  5. #5
    iamamyth is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default Re: Need some help with java coding

    Could someone please help me

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Need some help with java coding

    First, go through the Forum Rules, particularly the third paragraph.

    Then go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your posts accordingly.

    To change the subject line, click 'Go Advanced' after clicking 'Edit Post'

    db
    Last edited by DarrylBurke; 01-05-2013 at 10:48 AM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Coding sms in java?
    By strictlydivine.elite in forum Advanced Java
    Replies: 2
    Last Post: 11-18-2010, 03:10 PM
  2. Replies: 4
    Last Post: 10-25-2010, 04:49 PM
  3. help with java coding
    By helpisontheway in forum New To Java
    Replies: 4
    Last Post: 11-14-2009, 08:00 AM
  4. java coding
    By zawad in forum Suggestions & Feedback
    Replies: 1
    Last Post: 07-07-2009, 02:55 PM
  5. Coding Java on a Mac
    By Menre in forum New To Java
    Replies: 5
    Last Post: 05-06-2008, 06:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •