Design and implement a class that represents an email entry. It should have an a
ID: 3644380 • Letter: D
Question
Design and implement a class that represents an email entry. It should have an attribute for the person's name (which can be a class Name)and attributes for the user name and address portions of the email address. for example:
Catherine Mahoney
cmahoney
gwebcast.com
The class should provide an observer for each attribute, and it should provide a method that returns the email address in the usual form.
in the case of the example, this would be
cmahoney@gwebcast.com
Develop a driver that tests this class.
Explanation / Answer
class Flight{
private String airline, origin, destination;
private int flightNumber;
public Flight (String airline,int flightNumber, String origin, String destination){
this.airline = airline;
this.flightNumber = flightNumber;
this.origin = origin;
this.destination = destination;
}
public String getAirline ()
{
return airline;
}
public int getFlightNumber ()
{
return flightNumber;
}
public String getOrigin ()
{
return origin;
}
public String getDestination ()
{
return destination;
}
public void setAirline (String airline)
{
this.airline = airline;
}
public void setFlightNumber (int flightNumber)
{
this.flightNumber = flightNumber;
}
public void setOrigin (String origin)
{
this.origin = origin;
}
public void setDestination (String destination)
{
this.destination = destination;
}
public String toString ()
{
return airline + ", " + flightNumber + " -- From: " + origin +", To: " + destination;
}
}
class FlightTest{
public static void main (String[] args)
{
Flight f1 = new Flight ("US Air",111, "Boston", "Los Angeles" );
Flight f2 = new Flight ("Indian Airlines",222, "New Delhi", "New York" );
Flight f3 = new Flight ("Jet Airways", 333,"New Delhi", "Singapore" );
Flight f4 = new Flight ("Kingfisher Airlines", 444,"New Delhi", "Paris" );
Flight f5 = new Flight ("Deccan Airlines", 555,"New Delhi", "Chicago" );
System.out.println (f1);
System.out.println (f2);
System.out.println (f3);
System.out.println (f4);
System.out.println (f5);
System.out.println();
System.out.print("Flight 1 old flight number: " + f1.getFlightNumber());
f1.setFlightNumber(101);
System.out.println (" New flight number: " + f1.getFlightNumber());
System.out.print("Flight 5 old destination place: " + f5.getDestination());
f5.setDestination("Moscow");
System.out.println (" New destination place: " + f1.getDestination());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.