Java Programming - Please Help Your task as a developer is to create an applicat
ID: 3918771 • Letter: J
Question
Java Programming - Please Help
Your task as a developer is to create an application using one of the data structures discussed in class this semester (EXCLUDING ARRAYS). An array can be a part of your data structure but cannot be the data structure.
You will be developing a simple database with two different objects holding nodes with data items. You will create an insert method to place the data in to the node data items. You will also give the user the ability to search for data and display all relevant data from both objects using the key value of object one below. After your program is complete write a paragraph or two describing why you chose the data structure you selected and whether it was the correct data structure.
The data being held in each node object is as follows:
Object One
Object Two
Model Number (Key)
Customer ID (Key)
Description
Model Number
Cost
Quantity Ordered
Price
Order Total ($)
Quantity On Hand
It is HIGHLY suggested that you stump out the code or hand draw a flow chart for your program before you start to code your program (2 extra points if you hand that in).
Sample Output:
No Model Number mno123 Found.
Model
Number Description Cost Price On Hand
--------------------------------------------------------------------------------
abc123 Mother Board 4 bit $49.99 $59.99 5
Order: MATC, abc123, 4, $239.96
Order: SCC, abc123, 2, $119.98
Model
Number Description Cost Price On Hand
---------------------------------------------------------------------------------
jkl123 Mother Board 32 bit $79.99 $89.99 4
Order: MCW, jkl123, 3, $269.97
Any advice or ideas whatsoever would be appreciated
Object One
Object Two
Model Number (Key)
Customer ID (Key)
Description
Model Number
Cost
Quantity Ordered
Price
Order Total ($)
Quantity On Hand
Explanation / Answer
import java.util.HashMap;
import java.util.Map;
public class SimpleDatabase
{
public static void main(String args[])
{
//* Here we instantiated ObjectOneMap with key as String(ex: modelNumber - abc4) and value as ObjectOne and
//* ObjectTwoMap with key as String(ex: customerId - customerId1) and value as ObjectTwo
Map<String, ObjectOne> objectOneMap = new HashMap<>();
Map<String, ObjectTwo> objectTwoMap = new HashMap<>();
insertIntoObjectOne(objectOneMap);
insertIntoObjectTwo(objectTwoMap);
fetchRecordsFromObjectOne(objectOneMap);// Will fetch by key
fetchRecordsFromObjectTwo(objectTwoMap);// Will fetch by key
}
private static void insertIntoObjectOne(Map<String, ObjectOne> objectOneMap)
{
//new ObjectOne(String description,double price, double cost, int quantityOnHand)
ObjectOne record1 = new ObjectOne("Mother Board 4bit", 49.99, 39.99, 4);
ObjectOne record2 = new ObjectOne("Mother Board 5bit", 59.99, 49.99, 5);
ObjectOne record3 = new ObjectOne("Mother Board 6bit", 69.99, 59.99, 6);
// Inserting ObjectOne records into objectOneMap with key(modelNumber) and value(record1...)
objectOneMap.put("abc4", record1);// Key is "abc4" and Value is record1
objectOneMap.put("abc5", record2);
objectOneMap.put("abc6", record3);
}
private static void insertIntoObjectTwo(Map<String, ObjectTwo> objectTwoMap)
{
//new ObjectTwo(String modelNumber, long quantityOrdered, long orderTotal)
ObjectTwo record1 = new ObjectTwo("abc4", 1, 1);
ObjectTwo record2 = new ObjectTwo("abc5", 2, 2);
ObjectTwo record3 = new ObjectTwo("abc6", 3, 3);
// Inserting ObjectTwo records into objectTwoMap with key(customerId) and value(record1...)
//* Object put(Object key, Object value) -- key is String Object; value is record1(ObjectOne - object)
//* This method is used to add key-value pair to the map
objectTwoMap.put("CustomerId1", record1); // Key is "CustomerId1" and Value is record1
objectTwoMap.put("CustomerId2", record2);
objectTwoMap.put("CustomerId3", record3);
}
private static void fetchRecordsFromObjectOne(Map<String, ObjectOne> objectOneMap)
{
//Will fetch records from objectOneMap based on key.
//* for record1 key is abc4
//* for record2 key is abc5
//* for record3 key is abc6
//* Object get(key) -- key is String Object, in our case it is modelNumber ex : abc4
//* Returs the value associcate with the key.
ObjectOne record1 = objectOneMap.get("abc4");
System.out.println("ObjectOne record1 : "+record1);
ObjectOne record2 = objectOneMap.get("abc5");
System.out.println("ObjectOne record2 : "+record2);
ObjectOne record3 = objectOneMap.get("abc6");
System.out.println("ObjectOne record3 : "+record3);
}
private static void fetchRecordsFromObjectTwo(Map<String, ObjectTwo> objectTwoMap)
{
//Will fetch records from objectTwoMap based on key.
//* for record1 key is CustomerId1
//* for record2 key is CustomerId2
//* for record3 key is CustomerId3
ObjectTwo record1 = objectTwoMap.get("CustomerId1");
System.out.println("ObjectTwo record1 : "+record1);
ObjectTwo record2 = objectTwoMap.get("CustomerId2");
System.out.println("ObjectTwo record2 : "+record2);
ObjectTwo record3 = objectTwoMap.get("CustomerId3");
System.out.println("ObjectTwo record3 : "+record3);
}
}
class ObjectOne
{
String modelNumber; // Key
String description;
double price;
double cost;
int quantityOnHand;
//Constructor
ObjectOne(String description,double price, double cost, int quantityOnHand)
{
this.description = description;
this.price = price;
this.cost = cost;
this.quantityOnHand = quantityOnHand;
}
//*String() is present in java.lang.Object class
//* We can use this method to find String representation of an Object
//* Whenever we are trying to print any object reference internally toString() method will be executed.
//* java.lang.Objec class has toString() definition like this getClass().getName+"@"+Ingeger.toHexString(hashCode());
//* To provide our ow String representation we have overridden toString() method in our classes ObjectOne and ObjectTwo.
public String toString()
{
return "ObjectOne [description = " +description+ ", price = " +price+ ", cost = " +cost+ ", quantityOnHand = " +quantityOnHand +"]";
}
}
class ObjectTwo
{
String customerId; // Key
String modelNumber;
double quantityOrdered;
double orderTotal;
//Constructor
ObjectTwo(String modelNumber, double quantityOrdered, double orderTotal){
this.modelNumber = modelNumber;
this.quantityOrdered = quantityOrdered;
this.orderTotal = orderTotal;
}
public String toString()
{
return "ObjectTwo [modelNumber = " +modelNumber+ ", quantityOrdered = " +quantityOrdered+ ", orderTotal = " +orderTotal+ "]";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.