0

I created two separate classes, main and leads. The following is from 'leads' , I am trying to apply Leads.primeLead(); if the user answers Yes on the first question, and if not, I'd like to write a different method to add all the necessary information.

My problem is that, I don't quite understand why the primeLead() wont apply on Lead constructor or how am I supposed to define it so it will.

import java.util.ArrayList;
import java.util.Scanner;

public class Lead {

    String nameLead;
    int ageLead;
    int phoneLead;
    String cityLead;
    String email;
    String otherNotes;

    int indexOfLead = 0;
    int i = indexOfLead;

    ArrayList<String> names = new ArrayList<String>();
    ArrayList<Integer> ages = new ArrayList<Integer>();
    ArrayList<Integer> phones = new ArrayList<Integer>();
    ArrayList<String> cities = new ArrayList<String>();
    ArrayList<String> emails = new ArrayList<String>();
    ArrayList<String> notes = new ArrayList<String>();

    Scanner leads = new Scanner(System.in);

    Lead() {
        System.out.println("Is this the first lead? (Y/N) ");
        if (leads.nextLine() == "Y") {
            this.primeLead();
        }
    }

   /* public mainMenuLead(){
        System.out.println("Please choose one of the following options");
    } */


    Lead newLeads = new Lead();

    public void primeLead() {
        i = 0;
        System.out.println("============================================");
        System.out.println("  Please enter by the following order : ");
        System.out.println("     Name, age, phone , city, mail     ");
        System.out.println("============================================");

        System.out.println("Please enter the name of the Lead :  ");
        names.add(leads.nextLine());

        System.out.println("Age? :  ");
        ages.add(Integer.parseInt(leads.nextLine()));

        System.out.println("Phone number? ");
        phones.add(Integer.parseInt(leads.nextLine()));

        System.out.println("Would you like to add ... ");
        System.out.println("1) City? ");
        System.out.println("2) Email? ");
        System.out.println("3) Notes?  ");

        if (leads.nextLine() == "1") {
            System.out.println("Please add City: ");
            cities.add(leads.nextLine());

        } else if (leads.nextLine() == "2") {
            System.out.println("Please add email : ");
            emails.add(leads.nextLine());

        } else if (leads.nextLine() == "3") {
            System.out.println("Please add any other notes you may have:  ");
            notes.add(leads.nextLine());
        }
    }
}
Nowhere Man
  • 19,170
  • 9
  • 17
  • 42
  • perhaps creating a separate class for leads in another file, import it to main and calling it in your main would be better – RAZ_Muh_Taz Jul 10 '20 at 17:22
  • Your code will get into endless loop - because you create new instance of `Lead` here: `Lead newLeads = new Lead();` for each new instance of `Lead`. And the other reason of malfunctioning is comparing String with `==` while you should have used .equals – Nowhere Man Jul 10 '20 at 17:24
  • I did create a separate class for leads, I cant seem to import it properly - wont call primeLead method on Lead. I will fix the problems Alex, much obliged. – ThomasReiner Jul 10 '20 at 17:57
  • Question was closed and compared to a problem that isn't related to the initial question? ... – ThomasReiner Jul 11 '20 at 05:40

0 Answers0