Question

In: Computer Science

User ADT: Describes and manipulates user information. You must track the following information about a user / provide the following methods:



User ADT: Describes and manipulates user information. You must track the following information about a user / provide the following methods:

o username
o firstName
o lastName
o a list of the 10 most recently purchased items

o A user can bid on and purchase Items

The User class should have a default constructor, as well as one accepting all parameters. It should also provide accessor (getter) and mutator (setter) methods for appropriate methods. By default, a user is able to buy products only (not sell them).

• Item ADT: Describes a single item being sold. An item object keeps track of the current high bid for that item in addition to information about the object itself. You must track the following information about an item:

o name
o description
o highBid (currentBid) o buyNowPrice
o location
o dateBiddingComplete

The Item class should have a default constructor, as well as one accepting all parameters. In addition, this class contains functions for retrieving information about the item.

• Seller ADT: Seller is a specialization of user. You should implement it as such. In addition to all user attributes, sellers also have:

o Seller is a specific type of User that has a list of up to 20 items for sale

Note that for each ADT, you will define both an interface and a class. For example, you will create an ItemADT interface that will include methods such as getItemName, among others. The Item class implements this interface and implements all methods defined in the interface.

Provide a test class and the output from running your own test cases on all aspects of your program.

Solutions

Expert Solution

//Test.java

import java.io.*;

class Test

{

public static void main(String[] arg) throws IOException

{

  

System.out.println("\nCREATING TEST USERS...");

  

UserADT u1 = new User(); // Creates a user using the default constructor

u1.setUserName("jdoe");

u1.setRealName("Jane Doe");

u1.setPassword("jane_password");

u1.setEmail("[email protected]");

  

UserADT u2 = new User("jsmith", "Joe Smith", "password", "[email protected]");

SellerADT s1 = new Seller("rnelson", "Ron Nelson", "password", "[email protected]", "Visa", "Cool Stuff for Sale");

s1.addItem("bike", "2006 Huffy", 0, 85);

System.out.println("Here is the info for " + u1.getUserName() + ": " + u1.printInfo());

System.out.println("Here is the info for " + u2.getUserName() + ": " + u2.printInfo());

System.out.println(u2.printInfo());

System.out.println("Here is the info for " + s1.getUserName() + "and their store" + s1.getAuctionStoreName() + ": \n" + s1.printInfo());

ItemADT i1 = new Item("laptop", "MacBook Pro", 0, 400);

s1.addItem(i1);

  

//Adding items to seller's account to reach max.

for (int i = 0; i < 8; i++){

i1 = new Item("test " + i, "This is a test", 0, 100);

s1.addItem(i1);

}

  

//Should print out a list of 10 items.

System.out.println(s1.printInfo());

  

//Should stop me from adding anymore items.

try{

i1 = new Item("Another item", "This is a test", 0, 100);

s1.addItem(i1);

} catch (ArrayIndexOutOfBoundsException aioob){

System.out.println(aioob.getMessage());

}

System.out.println(s1.printInfo());

  

//Should remove item 5 from the list.

s1.removeItem(5);

System.out.println(s1.printInfo());

  

//This should remove al1 items from list.

for (int i = 9; i > 0; i--)

s1.removeItem(i);

System.out.println(s1.printInfo());

  

//Testing to see if I can still remove.

try{

s1.removeItem(1);

} catch (ArrayIndexOutOfBoundsException aioob){

System.out.println(aioob.getMessage());

}

System.out.println(s1.printInfo());

  

try{

i1.setName("This is a name");

i1.setDescription("This is a description");

i1.setHighBid(20);

i1.setBuyNowPrice(10);

} catch (Exception e){

System.out.println(e.getMessage());

}

i1.setBuyNowPrice(50);

System.out.println(i1.getName() + " | " + i1.getDescription() + " | " + i1.getHighBid() + " | " + i1.getBuyNowPrice());

  

  

  

  

  

}

}

==============================================================================

//Item.java

public class Item implements ItemADT {

private String name;

private String description;

private int highBid;

private int buyNow;

/**

*

*/

public Item(){

this.name = "";

this.description = "";

this.highBid = 0;

this.buyNow = 0;

}

public Item(String name, String description, int highBid, int buyNow){

this.name = name;

this.description = description;

this.highBid = highBid;

this.buyNow = buyNow;

}

public void setName(String name) {

this.name = name;

}

public void setDescription(String description) {

this.description = description;

}

public void setHighBid(int highBid) {

if (highBid < 0)

throw new NumberFormatException("Value must be greater than or equal to 0");

this.highBid = highBid;

}

public void setBuyNowPrice(int buyNowPrice) {

if (buyNowPrice < 0)

throw new NumberFormatException("Value must be greater than or equal to 0");

if (buyNowPrice < this.highBid)

throw new NumberFormatException("The high bid of the item must be greater than or equal to the high price.");

this.buyNow = buyNowPrice;

}

public String getName() {

return name;

}

public String getDescription() {

return description;

}

public int getHighBid() {

return highBid;

}

public int getBuyNowPrice() {

return buyNow;

}

}

===========================================================================

//ItemADT.java

public interface ItemADT {

public void setName(String name);

public void setDescription(String description);

public void setHighBid(int highBid);

public void setBuyNowPrice(int buyNowPrice);

public String getName();

public String getDescription();

public int getHighBid();

public int getBuyNowPrice();

}

============================================================================

//Seller.java

public class Seller extends User implements SellerADT {

final int MAX_COUNT = 10;

private String auctionStoreName;

private String preferredPaymentMethod;

private ItemADT[] itemSelling;

private int count;

/**

* Default constructor, sets defaults

*/

public Seller(){

super();

setAuctionStoreName("");

setPreferredPaymentMethod("");

this.itemSelling = new ItemADT[MAX_COUNT];

this.count = 0;

}

public Seller(String userName, String realName, String password, String email, String preferredPaymentMethod, String auctionStoreName){

super(userName, realName, password, email);

setAuctionStoreName(auctionStoreName);

setPreferredPaymentMethod(preferredPaymentMethod);

this.itemSelling = new ItemADT[MAX_COUNT];

this.count = 0;

}

public void setPreferredPaymentMethod(String paymentMethod) {

this.preferredPaymentMethod = paymentMethod;

}

public void setAuctionStoreName(String storeName) {

this.auctionStoreName = storeName;

}

public String getPreferredPaymentMethod() {

return preferredPaymentMethod;

}

public String getAuctionStoreName() {

return auctionStoreName;

}

public void addItem(String name, String description, int highBid, int buyNow) {

testSize();

itemSelling[count] = new Item(name, description, highBid, buyNow);

count++;

}

public void addItem(ItemADT item) {

testSize();

itemSelling[count] = item;

count++;

}

private void testSize(){

if (count >= MAX_COUNT)

throw new ArrayIndexOutOfBoundsException("You have reached your max items being sold.");

}

public ItemADT removeItem(int number){

if (number > count || number < 1)

throw new ArrayIndexOutOfBoundsException("There are no items to be removed there.");

ItemADT item = itemSelling[(number - 1)];

ItemADT itemMoved = itemSelling[(count - 1)];

itemSelling[(number - 1)] = itemMoved;

itemSelling[(count - 1)] = null;

count--;

return item;

}

public String printInfo() {

String output = super.printInfo() + "Auction Store: " +

getAuctionStoreName() + "\nPreferred Payment: " +

getPreferredPaymentMethod() + "\n";

ItemADT item;

for (int i = 0; i < count; i++){

item = itemSelling[i];

output = output + "\nItem " + (i+1) + " for sale\nItem Name: " +

item.getName() + "\nDescription: " + item.getDescription() +

"\nHigh Bid: " + item.getHighBid() + "\nBuy Now Price: " +

item.getBuyNowPrice() + "\n";

}

return output;

}

}

============================================================================

//SellerADT.java

public interface SellerADT extends UserADT {

public void setPreferredPaymentMethod(String paymentMethod);

public void setAuctionStoreName(String storeName);

public String getPreferredPaymentMethod();

public String getAuctionStoreName();

public void addItem(String name, String description, int highBid, int buyNow);

public void addItem(ItemADT item);

public ItemADT removeItem(int number);

}

==============================================================================

//User.java

public class User implements UserADT {

private String userName;

private String realName;

private String password;

private String email;

/**

* Default constructor, sets the default values.

*/

public User(){

setUserName("");

setRealName("");

setPassword("");

setEmail("");

}

public User(String userName, String realName, String password, String email){

setUserName(userName);

setRealName(realName);

setPassword(password);

setEmail(email);

}

/**

* Sets the user's user name.

*/

public void setUserName(String userName){

this.userName = userName;

}

/**

* Sets the user's real name.

*/

public void setRealName(String realName){

this.realName = realName;

}

/**

* Sets the user's password.

*/

public void setPassword(String password){

this.password = password;

}

/**

* Sets the user's email.

*/

public void setEmail(String email){

this.email = email;

}

/**

* Returns a string representation of the user's user name.

*/

public String getUserName(){

return userName;

}

public String getRealName(){

return realName;

}

public String getPassword(){

return password;

}

public String getEmail(){

return email;

}

public String printInfo(){

return ("\nUser Name: " + getUserName() + "\nReal Name: " + getRealName() + "\nPassword: " + getPassword() + "\nEmail: " + getEmail() + "\n");

}

}

=============================================================================

//UserADT.java

public interface UserADT {

public void setUserName(String userName);

public void setRealName(String realName);

public void setPassword(String password);

public void setEmail(String email);

public String getUserName();

public String getRealName();

public String getPassword();

public String getEmail();

public String printInfo();

}

============================================================================

sample output


Related Solutions

Create a program that keeps track of the following information input by the user: First Name,...
Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, Age Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns. You should be able to add, display and remove contacts in the array. In Java
You will implement the MyList ADT according to the following: 1. MyList must implement the List...
You will implement the MyList ADT according to the following: 1. MyList must implement the List interface. It will look something like below: public class MyList<E> implements List<E> { ... } Note: As said in the class, when implementing an interface, you have to implement each method in it. There are a lot of methods in the List interface. We are going to address this issue below. 2. The initial capacity of MyList must be 2. This is not an...
Question 1: Why is it important to provide detailed information about the methods used in an...
Question 1: Why is it important to provide detailed information about the methods used in an experiment? Question 2: Convert 0.75 lb to mg? For the calculation show all the steps in the calculation and final answer.
The following information describes the requirements for your response: It must be at least three paragraphs...
The following information describes the requirements for your response: It must be at least three paragraphs long (more is usually better), grammatically correct, and demonstrate that you understand and can apply the concepts covered in the second competency module. When writing your response, follow the steps listed below in the order that they appear. Step One: Begin by describing the process for calculating price elasticity of demand. Then, using fictitious numbers, calculate the price elasticity of demand for donuts at...
A law firm proposed the following table to keep track the information about cases and the...
A law firm proposed the following table to keep track the information about cases and the lawyers who handle the cases: CASE (caseNumber, caseDescription, lawyerInCharge, caseAssistant, beginningdate, endingDate, lawyerRate, accumulatedHours, clientsName., clientPhone, clientAdress, clientType, laywerPhone, caseResultDescription, clientCurrentPayment, paymentMethod, salary, bonus) Among above attributes, caseNumber, is the ID of the case lawyerInCharge is the name of the lawyer (a single person) who in charge of the case. NOTE : There may be also several staffs in the firm serve as the...
How would you track a budget? Discuss three different methods to track a budget.
How would you track a budget? Discuss three different methods to track a budget.
For the following commands you must be logged in as user “system”. You will need to...
For the following commands you must be logged in as user “system”. You will need to do some research on the commands CREATE USER; GRANT CREATE SESSION; GRANT CREATE…..; GRANT ALTER …., GRANT SELECT….; REVOKE ……; and EXECUTE ….. 5. Create two database users:  The first is a concatenation of your first and last name (e.g. johndoe).  The second is a concatenation of your instructors first and last name (e.g. sallysmith) 6. Assign the two users privileges to...
You must prompt the user to enter a menu selection. The menu will have the following...
You must prompt the user to enter a menu selection. The menu will have the following selections (NOTE: all menu selections by the user should not be case sensitive): 1. ‘L’ – Length a. Assume that a file containing a series of names is called names.txt and exists on the computer’s disk. Read that file and display the length of each name in the file to the screen. Each name’s middle character or characters should be displayed on a line...
3. Which statement about methods in an interface is true? A.)All methods in an interface must...
3. Which statement about methods in an interface is true? A.)All methods in an interface must be explicitly declared as private or public. B.)All methods in an interface are automatically public. C.)All methods in an interface are automatically private. D.)All methods in an interface are automatically static.
• 2. Get all the information from the user using methods Java • B. if the...
• 2. Get all the information from the user using methods Java • B. if the inputs are not given in the proper format the program should prompt user to give the proper input (eg. Name cannot be numbers, age cannot be String)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT