In: Math
PYTHON: The following puzzle is known as The Big Cross-Out Swindle.“Beginning with the word ‘NAISNIENLGELTETWEORRSD,’ cross out nine letters in such a way that the remaining letters spell a single word”. Write a program that creates variables named startingWord, crossedOutLetters, andremainingLetters. The program should assign to startingWord the string given in the puzzle, assign tocrossedOutLetters a list containing every other letter of startingWordbeginning with the initial letter N, and assign to remainingLetters a list containing every other letter of startingWord beginning with the second letter, A. The program should then display the values of the three variables.
Program:
Sample output:
Code to copy:
/**Author.java**/
public class Author
{
protected String name;
protected String email;
protected char gender;
//Constructor
public Author(String name, String email, char gender)
{
this.name = name;
this.email = email;
this.gender = gender;
}
//returns name
public String getName()
{
return name;
}
//returns email
public String getEmail()
{
return email;
}
//returns gender
public char getGener()
{
return gender;
}
//sets email
public void setEmail(String email)
{
this.email = email;
}
//returns a string with name and email
public String toString()
{
return ( name + "(" + gender + ") at " + email);
}
}
/**Book.java**/
public class Book
{
private String name;
private Author author;
private double price;
private int qtyInStock = 0;
//Constructors
public Book(String name, Author author,Double price)
{
this.author = author;
this.name = name;
this.price = price;
}
public Book(String name, Author author, double price, int qtyInStock)
{
this.name = name;
this.author = author;
this.price = price;
this.qtyInStock = qtyInStock;
}
//returns name
public String getName()
{
return name;
}
//returns auther
public Author getAuthor()
{
return author;
}
//returns price of the book
public double getPrice()
{
return price;
}
//Returns the quantity
public int getQtyInStock()
{
return qtyInStock;
}
//sets the price of the book
public void setPrice(double price)
{
this.price = price;
}
//sets the quantity
public void setQtyInStock(int qtyInStock)
{
this.qtyInStock = qtyInStock;
}
//returns a string with name of the book and author details
public String toString()
{
return (name + " by "+author);//Automatically author.toString() is called
}
}
/**TestBook.java**/
public class TestBook
{
public static void main(String[] args)
{
//Test Book class constructors
Author oneAuthor=new Author("Tan Ah Teck","[email protected]",'m');
Book book1=new Book("Introduction to authors",oneAuthor,15.50,300);
System.out.println(book1.toString());
Book book2=new Book("Introduction to authoring",new Author("James philip","[email protected]",'m'),15.50,330);
System.out.println(book2.toString());
}
}