The problem is
Design a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods.
Next design a class named Customer, that extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Demonstrate an object of the Customer class in a simple program.
Ok so for this program, I believe that I am doing everything correctly, however, I am really confused with the boolean field set up. Ive tried and it doesnt work. Also in the telephone number, how to write with the dashes in between. I first tried it as an int field but changed to double but when I put in the number 7705642593 the output gives me 7.705642593E9. I dont know how it gets that. The address field is the same. I want to input the number of the city and the name of it but since its a String field, it doesnt let me give the number. I am sorry that post is so long, but any help would be highly aprreciated.
Thank you and here is what I have so far:
public class Person
{
private String name;
private String address;
private double phonenumber;
public Person(String name, String address, double phonenumber)
{
this.name = name;
this.address = address;
this.phonenumber = phonenumber;
}
public void setName(String name)
{
this.name = name;
}
public void setAddress(String address)
{
this.address = address;
}
public void setNumber(int phonenumber)
{
this.phonenumber = phonenumber;
}
public String getName()
{
return name;
}
public String getAddress()
{
return address;
}
public double getNumber()
{
return phonenumber;
}
}
the customer class
public class Customer extends Person
{
private int idnumber;
private boolean onlist = true;
public Customer(int idnumber, boolean onlist, String name, double phonenumber, String address)
{
super(name, address, phonenumber);
this.idnumber = idnumber;
this.onlist = onlist;
}
public void setIdNumber(int idnumber)
{
this.idnumber = idnumber;
}
public void setToBeOnList(boolean onlist)
{
if(onlist)
{
System.out.println("The customer wants to be on the mailing list.");
}
}
public int getIdNumber()
{
return idnumber;
}
public boolean getToBeOnList()
{
return onlist;
}
}
the customer demo class
import java.util.Scanner;
public class CustomerDemo
{
public static void main(String[] args)
{
String name;
String address;
double phonenumber;
int idnumber;
boolean onlist = false;
String letter;
Scanner kb = new Scanner(System.in);
System.out.println("Name: ");
name = kb.nextLine();
System.out.println("Address: ");
address = kb.nextLine();
System.out.println("Phonenumber: ");
phonenumber = kb.nextDouble();
System.out.println("IdNumber: ");
idnumber = kb.nextInt();
System.out.println("Would you like to be on the mailing list? y/n: ");
letter = kb.nextLine();
if(letter.equalsIgnoreCase("Y"))
{
onlist = true;
}
else
{
onlist = false;
}
Customer cm = new Customer(idnumber, onlist, name, phonenumber, address);
System.out.println("Here is some information about the customer.");
System.out.println("Name: " + cm.getName());
System.out.println("Address: " + cm.getAddress());
System.out.println("Phone Number: " + cm.getNumber());
System.out.println("IdNumber: " + cm.getIdNumber());
System.out.println("Would you like to be on the mailing list: " + cm.getToBeOnList());
}
}
again sorry its going to take a while to read :)