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

Thread: Possibly a noobish issue

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

    Default Possibly a noobish issue

    Java Class

    package Aula_Teo;
     
    public class Contacto {
     
        private static class string {
     
            public string() {
            }
        }
     
        private int numero;
        private string nome;
        private int telefone;
        private boolean tipo;
     
    private static int numC=0;
     
     
    public Contacto(string nomeC, int telefoneC, boolean tipoT){
        this.numero=++numC;
        this.nome=nomeC;
        this.telefone=telefoneC;
        this.tipo=tipoT;
    }
     
    public int getNumero(){
        return this.numero;
    }
     
    public string getNome(){
        return this.nome;
    }
     
    public int getTelefone(){
        return this.telefone;
    }
     
    public boolean isMovel(){
        return this.tipo;
    }
     
    public void setNome(string nomeCont){
        this.nome=nomeCont;
    }
     
    public void setTelefone(int tel){
        this.telefone=tel;
    }
    public void setTipo(boolean t){
        this.tipo=t;
    }
    }

    Java Main Class

    package Aula_Teo;
     
    import java.util.Scanner;
     
     
    public class Agenda {
     
        static Scanner scan = new Scanner(System.in);
     
        public static void main(String[] args) {
            Contacto[]agenda=new Contacto[50];
     
            int conta=0;
     
            /*
             * agenda[0]=insereContacto();
             * agenda[1]=insereContacto();
             * agenda[2]=insereContacto();
             * agenda[3]=insereContacto();
             * agenda[4]=insereContacto();
            */
     
            for(int i=0;i<5;i++){
                agenda[i]=insereContacto();
                scan.nextLine();
                conta++;
            }
     
            for (int i=0;i<conta;i++)
                imprimeContacto(agenda[i]);
     
            //para inserir a pesquisa
     
            System.out.println("Introduza um número de telefone: ");
            int num=scan.nextInt();
            int pos=pesqTelefone(agenda, conta, num);
            if (pos==-1)
                System.out.println("O número não conta da listagem");
            else
                imprimeContacto(agenda[pos]);
     
        }
     
        private static Contacto insereContacto(){
     
            String nomeCont; int tel; boolean t;
            char op;
     
            System.out.println("Nome: ");
            nomeCont=scan.nextLine();
     
            do{
            System.out.println("Nº telefone: ");
            tel=scan.nextInt();
            }while(tel<100000000||tel>999999999);
     
            do{
                System.out.println("Tipo (movel/fixo): ");
                op=scan.nextLine().charAt(0);
            }while(op!='m'||op!='M'||op!='f'||op!='F');
     
            if (op=='m'||op=='M')
                t=true;
            else
                t=false;
     
            return new Contacto(nomeCont,tel,t);
        }
     
        private static void imprimeContacto(Contacto c){
     
            System.out.println("Numero:"+c.getNumero());
            System.out.println("Nome:"+c.getNome());
            System.out.println("Telefone:"+c.getTelefone());
            if (c.isMovel()==true)
                System.out.println("Movel");
            else
                System.out.println("Fixo");
        }
     
        //alínea ii
     
        private static int eliminaContacto(Contacto[] v,int pos,int nElem){
     
     
            v[pos]=v[nElem-1];
     
            return --nElem;
        }
     
        private static int pesqTelefone(Contacto[]v, int nElem, int numT){
     
            int i=0;
            while(i<nElem && numT!=v[i].getTelefone())
                i++;
            if (i<nElem)
                return i;
            else return -1;
        }
     
        private static int pesqNome(Contacto[]v, int nElem, String nomeP){
     
            int i=0;
            while(i<nElem && !nomeP.equalsIgnoreCase(v[i].getNome()))
                i++;
            return i;
        }
     
    }

    In the Java Main Class, where: return new Contacto(nomeCont,tel,t); appears I get an error which says:

    cannot find symbol
    symbol: constructor Contacto(java.lang.String,int,boolean)
    location: class Aula_Teo.Contacto

    which also causes an error here: while(i<nElem && !nomeP.equalsIgnoreCase(v[i].getNome()))

    I think this might be a noobish question, but hey, I'm just starting so...
    Thank you for any help you might give me


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Possibly a noobish issue

    Your inner class string does nothing.

    Does tipo mean type?

    conta was never defined as a variable in the main method, at least not before you used it, so it won't know what to do with it.

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Possibly a noobish issue

    scan.nextLine();

    This scans but doesn't set it to anything.

    String str = "";

    and then later

    str = scan.nextLine(); will at least set it to something

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Possibly a noobish issue

    for(int i=0;i<5;i++){
    agenda[i]=insereContacto();
    scan.nextLine();
    conta++;
    }

    do you mean i < 50?

    Otherwise, there will be 50 agenda, but only 5 will have values.

    if (pos==-1)

    should be replaced by

    if (pos >=0 && pos < agenda.length)

    else
    imprimeContacto(agenda[pos]);

    this won't work unless you have all 50 values as my if statement above will let it work and not get a compiler error,

    but if they enter like 30, you've got nothing in index 30 so it'll throw a Null Pointer Exception.

  5. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Possibly a noobish issue

    Java already has a class called String, with a capital S. You don't need to write your own, unless you have to.

  6. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Possibly a noobish issue

    if (c.isMovel()==true)

    Actually, boolean method can be written

    if (c.isMovel())

    if checking to see if true

    and

    if (!c.isMovel())

    if checking to see if false

  7. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Possibly a noobish issue

     

    cannot find symbol
    symbol: constructor Contacto(java.lang.String,int,boolean)
    location: class Aula_Teo.Contacto




    I think this means that you had an inner class called string, and maybe you called it.

    You forgot to capitalize String.

    When it pass it a String,

    it expected a type of type "string".

  8. #8
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: Possibly a noobish issue

    javapenguin is correct.... Delete your inner string class.... and then change the type in the constructor from string to String

Similar Threads

  1. Port issue?
    By Brt93yoda in forum Java Theory & Questions
    Replies: 3
    Last Post: October 13th, 2010, 04:28 PM
  2. [SOLVED] Calendar Issue
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 11th, 2010, 01:19 PM
  3. i do not know how to solve this issue
    By javastupi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 20th, 2010, 08:28 PM
  4. url pattern issue - please help me...
    By bharathik in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: November 9th, 2009, 04:28 AM
  5. Issues with Tomcat 6.0
    By sanyog24681 in forum Java Servlet
    Replies: 0
    Last Post: October 21st, 2008, 07:55 AM