im pretty new to OOP in java and im having trouble of changing the output of the email from as it should run from osan@gmail.com to cuscus@gmail.com to Osan.oro@gmail.com,i also did an argument on the setEmail parameter if relations wether if the input email is wrong then it will be Invalid email! Set to unknown and then the EMAIL : Uknown here is my current code:
public class BookTest
{
public static void main(String[] args)
{
Author author1 = new Author("Josanne Oro", "osan@gmail.com", "Male");
author1.print();
Book bk1 = new Book("Java Book", author1, 1499, 10);
bk1.print();
author1.setEmail("cuscus@gmail.com");
author1.print();
bk1.print();
bk1.getAuthor().setEmail("Josanne.oro@gmail.com");
bk1.print();
}
}
public class Author
{
private String author;
private String email;
private String gender;
Author(String author, String email, String gender)
{
this.author=author;
this.email=email;
this.gender=gender;
}
String getAuthor()
{
return author;
}
void setAuthor(String author)
{
this.author=author;
}
String getEmail()
{
return email;
}
void setEmail(String email)
{
if
(email=="osan@gmail.com"||email=="cuscus@gmail.com"||email=="Josanne.oro@gmail.com")
{
this.email=email;
}
else
System.out.println("Invalid email! Set to unknown");
this.email="Uknown";
}
void print()
{
System.out.println("AUTHOR : " + author);
System.out.println("GENDER : " + gender);
System.out.println("E-MAIL : " + email);
}
}
public class Book
{
private String bookTitle;
private Author author;
private double price;
private int stock=0;
public Book(String bookTitle, Author author, double price, int stock)
{
this.bookTitle=bookTitle;
this.author=author;
this.price=price;
this.stock=stock;
}
public Author getAuthor()
{
return this.author;
}
public void print()
{
System.out.println("Book Title : " + bookTitle);
author.print();
}
} ```