Question: Java: Please help modify code according to instructions. Thank you. Instructions: Bot Class Subclass of Account class. A class that stores information about an application
Java: Please help modify code according to instructions. Thank you.
Instructions:
- Bot Class
- Subclass of Account class.
- A class that stores information about an application that performs an automated task.
- Instance Variables
- botFileName String representing the file name of the bot
- category String providing the Bot category which will be either IDS, SysAdm, or HelpDesk.
- dateUpdated GregorianCalendar object (from the Java API) that shows the date the Bot was last updated.
- createdBy String representing the creator name or handle.
- Methods
- Default constructor sets all instance variables to a default value
- Call the super class constructor passing appropriate parameters to it.
- Set the rest of the variables
- Parameterized Constructor
- Takes in all parameters required to set the instance variables.
- Call the super class constructor passing appropriate parameters to it
- Set the rest of the variables to the remaining parameters
- Date is a String in the format mm/dd/yyyy.
- Convert the date to a format compatible with creating GregorianCalendar object.
- Create the GregorianCalendar object
- Accessor and mutator methods for all variables in this class.
- toString
- Calls super class methods as needed
- Returns a nicely formatted String representing the Bot to include Bot file name, purpose, date updated, creator name, accountID number, clearPassword, encryptPassword and key
- Default constructor sets all instance variables to a default value
Code:
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar;
public class Bot extends Account {
private Calendar dateUpdated = new GregorianCalendar(); private DateFormat dateForm = new SimpleDateFormat("MM/dd/yyyy"); private Date date = new Date(); private String botFileName; private String category; private String createdBy; /** * Constructor to initialize variables. */ public Bot() { super("", ""); setBotFileName(""); setCategory(""); setCreatedBy(""); dateUpdated.setTime(null); }
/** * Constructor to set variables of the Bot Class. */ public Bot(String newBotFileName, String newCategory, String newDate, String newCreatedBy, String newClearPassword, String newKey) { super(newClearPassword, newKey); setBotFileName(newBotFileName); setCategory(newCategory); setCreatedBy(newCreatedBy); setDateUpdated(newDate); }
/** * Method to return the bot's file name */ public String getBotFileName() { return botFileName; }
/** * Method to set the bot file name */ public void setBotFileName(String newBotFileName) { botFileName = newBotFileName; }
/** * Method to return the category of the bot */ public String getCategory() { return category; }
/** * Method to set the bot category * @param newCategory Input category name */ public void setCategory(String newCategory) { category = newCategory; }
/** * Method to return the date the bot file was updated in the Gregorian Calendar format. */ public String getDateUpdated() { return (dateUpdated.get(GregorianCalendar.MONTH) + 1) + "/" + dateUpdated.get(GregorianCalendar.DAY_OF_MONTH) + "/" + dateUpdated.get(GregorianCalendar.YEAR); }
/** * Method to set the date the bot file was updated. * @param newDate Input date of the bot file update */ public void setDateUpdated(String newDate) { try { date = dateForm.parse(newDate); } catch (ParseException e) { e.printStackTrace() ; } dateUpdated.setTime(date); } /** * Method to return the creator of the bot */ public String getCreatedBy() { return createdBy; }
/** * Method to set the name of the person who created the bot * @param newCreatedBy Input name of the person who created the bot */ public void setCreatedBy(String newCreatedBy) { createdBy = newCreatedBy; }
/** * Returns the information for the user. */ public String toString() { String info; info = String.format("%-5s %s %s %s %s ", getBotFileName(), getCategory(), getDateUpdated(), getCategory(), getCreatedBy()); info += super.toString(); return info;
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
