Question: import javax.jdo.*; @javax.jdo.annotations.PersistenceCapable public abstract class Product { String modelName; // key public String toString() { return modelName; } } import java.util.*; import javax.jdo.*; @javax.jdo.annotations.PersistenceCapable
import javax.jdo.*; @javax.jdo.annotations.PersistenceCapable public abstract class Product { String modelName; // key public String toString() { return modelName; } }
import java.util.*; import javax.jdo.*; @javax.jdo.annotations.PersistenceCapable public class Laptop extends Product { int price; // in dollars boolean hasHDScreen; // has a high-definition screen? int hardDriveCapacity; // in GB Processor processor; // the preinstalled processor Memory memory; // the preinstalled memory Company madeBy; // the inverse of Company.makeLaptops public Laptop(String mn, int p, boolean hd, int hdc) { modelName = mn; price = p; hasHDScreen = hd; hardDriveCapacity = hdc; } public String toString() { return madeBy.name+" "+modelName+"; "+ processor.toString()+"; "+ memory.toString()+"; "+ "harddrive: "+hardDriveCapacity+" GB"; } public static Laptop find(String mName, PersistenceManager pm) /* Returns the laptop with the given model name "mName"; returns null if no such laptop exists. The function is applied to the database held by the persistence manager pm. */ { } public static Collection HDandHardDrive(int x, Query q) /* Returns the collection of all laptops that have an HD screen and at least x GB of harddrive. Sort the result by (hardDriveCapacity, modelName). */ { } public static Collection speedPrice(float c, int p1, int p2, Query q) /* Returns the collection of all laptops that have a processor clock speed of at least "c" GHz and a price of at least "p1" and at most "p2" dollars. Sort the result by (processor.clockSpeed, price, modelName). */ { } public static Collection hasProcessor(String cName, Query q) /* Returns the collection of all laptops that have processors made by the company with the name "cName". Sort the result by (madeBy.name, modelName). */ { } public static Collection
import java.util.*; import javax.jdo.*; @javax.jdo.annotations.PersistenceCapable public class Processor extends Product { float clockSpeed; // in gigahertz (GHz) Company madeBy; // the inverse of Company.makeProcessors public Processor(String mn, float cs) { modelName = mn; clockSpeed = cs; } public String toString() { return madeBy.name+" "+modelName+" "+clockSpeed+" GHz"; } public Collection installedOn(Query q) /* Returns the collection of all laptops on which the target processor is preinstalled. Represents the inverse of Laptop.processor. Sort the result by (madeBy.name, modelName). */ { } }
import java.util.*; import javax.jdo.*; @javax.jdo.annotations.PersistenceCapable public class Memory extends Product { int size; // memory size in GB public Memory(String mn, int s) { modelName = mn; size = s; } public String toString() { return modelName+" "+size+" GB"; } public Collection installedOn(Query q) /* Returns the collection of all laptops on which the target memory is preinstalled. Represents the inverse of Laptop.memory. Sort the result by (madeBy.name, modelName). */ { } }
import java.util.*; import javax.jdo.*; @javax.jdo.annotations.PersistenceCapable public class Company { String name; // key HashSet makeLaptops = new HashSet(); // The set of laptops this company makes HashSet makeProcessors = new HashSet(); // The set of processors this company makes public Company(String s) { name = s; } public String toString() { return name; } public static Collection memoryProcessor(float c, int s, Query q) /* Returns the collection of all companies that make laptops that have a processor clock speed of at least "c" GHz and a memory size of at least "s" GB. Sort the result by name. */ { } public static Collection differentCompanyProcessor(Query q) /* Returns the collection of all companies that make at least two laptops preinstalled with processors made by different companies. Sort the result by name. */ { } }
import java.util.*; public class Utility { public static void printCollection(Collection c) { for (T x: c) System.out.println( x ); /*The above is equivalent to: Iterator it = c.iterator(); while ( it.hasNext() ) System.out.println( it.next() ); */ } public static void printCollectionOfArrays(Collection c) { for (Object[] x: c) { System.out.println(); for ( int i =0; i T extract(Collection c) /* Returns the last element of collection c, "last" according to the order of the iteration of the for-loop. In particular, if c contains only one element, that element is returned. If c is empty, null is returned. */ { T x = null; for (T e: c) x = e; return x; } }
This project deals with the following classes for a laptop database: Product, Laptop, Processor, Memory, Company. Utility has generic functions to print collections and to extract the element from a singleton collection; this class will be compiled with the above five but will not be transformed into a persistent class. For each of the following functions, you are to provide code of its body correctly implementing the specification given in the comment: 1. Processor.installedOrn 2. Memory.installedOn 3. Company.memoryProcessor 4. Company.differentCompanyProcessor 5. Laptop.find 6. Laptop.HDandHardDrive 7. Laptop.speedPrice 8. Laptop.hasProcessor 9. Laptop.laptopProcessorMadeBySameCompany 10. Laptop.sameProcessor 11. Laptop.groupByCompany All these functions are to use JDOQL queries. It may be advantageous to start with relevant JDOQL queries in set form. For visualization, it may be helpful to draw a UML diagram of the database. Do not change anything in the given class definitions and the function headers. Place all the classes in one folder, the default package. Test1 and Test2 are programmed to do some testing with example laptop1.odb and laptop2.odb database files, respectively. To test your function code by these, download them to the same folder that has your laptop class files, and run the main functions. The correct output should be identical to Test1 output and Test2 output. The contents of these databases can be inspected by Explorer. You might do your own testing by adding test code to the main function
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
Students Have Also Explored These Related Databases Questions!