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

JAVA 1. write a class NameCard.java which has •Data fields: name (String), age(i

ID: 3794556 • Letter: J

Question

JAVA

1. write a class NameCard.java which has

•Data fields: name (String), age(int), company(String)

•Methods:

•Public String getName();

•Public int getAge();

•Public String getCom();

•Public void setName(String n);

•Public void setAge(int a);

•Public void setCom(String c);

•toString(): \ can be used to output information on this name card

2.write a class DoublyNameCardList.java, which is a doubly linked list and each node of the list a name card.

In the DoublyNameCardList.java:

•Data field:

•Reference data type: head, which always references the first node of the doubly linked list

•Reference data type: tail, which aways references the last node of the doubly linked list

•int count, which is used to record the number of name cards in the list

•Method:

•public DoublyNameCardList(); // A constructor which can initialize the list:

•public void addEnd(NameCard x); // A method that allows you to place a value at the end of the list

•public void addHead(NameCard x); // A method that allows you to place a value at the begin of the list

•public void add(int index, NameCard x); //A method that allows you to place a name card after the given location

• public NameCard get(int index); //A method that allows you to retrieve a name card from a given location

•public int size(); // A method that allows you to return the number of elements that is currently in the list

•public void delete (index n); //A method that will remove a name card at the given index

•Public boolean exist(NameCard n); // test if there has a name card in the list which has same content with n

3. Now, write a driver program (the class with the public static void main(String[] args) method) name test.java to test the data structure you just created:

•   Fill in the list with 5 name card objects

•   print the list on the screen two times:

•From head to tail

•From tail to head

•    Call the method in the DoublyNameCardList class one by one, each method you called,

•Print out a message to show what have you done

•print out all the name cards in the list

Thank you!!

  

Explanation / Answer

class Bank implements java.io.Serializable
{
   private long accNo;
   private String accHName;
   private String username;
   private transient String password;
   private transient double balance;

   static double minBalance = 5000;

   Bank()
   {
       System.out.println("Bank Constructor");
   }
  
   public void setAccNo(long accNo)
   {
       this.accNo = accNo;
   }
   public long getAccNo()
   {
       return accNo;
   }

   public void setAccHName(String accHName)
   {
       this.accHName = accHName;
   }
   public String getAccHName()
   {
       return accHName;
   }

   public void setUsername(String username)
   {
       this.username = username;
   }
   public String getUsername()
   {
       return username;
   }

   public void setPassword(String password)
   {
       this.password = password;
   }
   public String getPassword()
   {
       return password;
   }

   public void setBalance(double balance)
   {
       this.balance = balance;

       minBalance = balance;
   }
   public double getBalance()
   {
       return balance;
   }

   public String toString()
   {
       return "accNo: "+accNo +" " +
                   "accHName: "+accHName +" " +
                   "username: "+username+" " +
                   "password: "+password+" "+
                   "balance: "+balance+" "+
                   "minBalance: "+minBalance+" ";
   }
}