Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I set the boolean to where you ask if they want to be on the mailing list

ID: 3733835 • Letter: H

Question

How do I set the boolean to where you ask if they want to be on the mailing list or not?

class Customer extends Person

{

private int cust_number;

private boolean cust_mailinglist;

public Customer(String person_name,String person_address, String person_tele, int cust_number, boolean mailinglist)

{

super(person_name,person_address,person_tele);

setCusNumber(cust_number);

setMailList(mailinglist);

}

public int getCusNumber()

{

return cust_number;

}

public boolean getMailList()

{

return cust_mailinglist;

}

public void setCusNumber(int r)

{

cust_number = r;

}

public void setMailList(boolean m)

{

cust_mailinglist = m;

}

public String toString()

{

return "Customer Name:" + getName() + " Customer ID:" +cust_number+ " Telephone Number:" + getTelephoneNumber()+" Mail List Status:" + cust_mailinglist;

}

}

class Person

{

private String person_name;

private String person_address;

private String person_tele;

public Person(String person_name,String person_address, String person_tele)

{

setName(person_name);

setAddress(person_address);

setTelephoneNumber(person_tele);

}

public String getName()

{

return person_name;

}

public String getAddress()

{

return person_address;

}

public String getTelephoneNumber()

{

return person_tele;

}

public void setName(String n)

{

person_name = n;

}

public void setAddress(String a)

{

person_address = a;

}

public void setTelephoneNumber(String t)

{

person_tele = t;

}

}

public class CusProgram

{

public static void main (String[] args)

{

String name,addr,tele;

int id;

Scanner keyboard= new Scanner(System.in);

System.out.println("Enter Customer Name:");

name=keyboard.nextLine();

System.out.println("Enter Customer Address:");

addr=keyboard.nextLine();

System.out.println("Enter Customer Telephone Number:");

tele=keyboard.nextLine();

System.out.println("Enter Customer ID:");

id=keyboard.nextInt();

boolean val=false;

Customer c = new Customer(name,addr,tele,id,val);

System.out.println(c);

}

}

Explanation / Answer

We can ask his interest of being included in the mailing list when we are collecting his other information itself.

The following lines of code after the line "boolean val = false" in the main function will suffice our answer.

//Additional Code

System.out.println("Enter 1 to be included in mailing List or 0 to be excluded from mailing list");

int k = keyboard.nextInt();

if(k==1){

val = true;}

//Additonal Code Ends

the initial value will be false, when he is interested i.e. when he presses 1 it will be reset to true.

The next line i.e, ' Customer c= new Customer(name, addr,tele,id val) ' will create a customer object with given values as parameters to the constructor function.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote