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; //

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 laptopProcessorMadeBySameCompany(Query q) /* Returns the set of 3-tuples  such that laptop "lt" is preinstalled with processor "p" and company "c" makes both "lt" and "p". Sort the result by (c.name, lt.modelName). */ { } public static Collection sameProcessor(Query q) /* Returns the collection of all laptops each of which has at least one other laptop preinstalled with the same processor. Sort the result by (madeBy.name, modelName). */ { } public static Collection groupByCompany(Query q) /* Group the laptops by the companies that make them. Then return the set of 4-tuples  where: num = the total number of laptops made by c minSpeed = the minimum clock speed of the processors preinstalled on the laptops made by c maxSize = the maximum memory size of the memories preinstalled on the laptops made by c Sort the result by c.name. */ { } } 

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; } } 

import java.util.*; import javax.jdo.*; import com.objectdb.Utilities; public class Test1 { public static void main(String argv[]) { PersistenceManager pm = Utilities.getPersistenceManager( "laptop1.odb" ); System.out.println( "-- TEST Laptop.find -- " ); Laptop xmp = Laptop.find( "Cyber Force XMP 3009", pm ); Laptop dual = Laptop.find( "Dual Power A554", pm ); System.out.println( xmp ); System.out.println( dual ); System.out.println(); System.out.println( "-- TEST Laptop.HDandHardDrive -- " ); Query q = pm.newQuery(); Collection ll = Laptop.HDandHardDrive(700, q); Utility.printCollection( ll ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Laptop.speedPrice -- " ); q = pm.newQuery(); ll = Laptop.speedPrice(8.0f, 500, 1000, q); Utility.printCollection( ll ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Laptop.hasProcessor -- " ); q = pm.newQuery(); ll = Laptop.hasProcessor("Delion", q); Utility.printCollection( ll ); q.closeAll(); System.out.println(); ll = Laptop.hasProcessor("BBN", q); Utility.printCollection( ll ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Laptop.laptopProcessorMadeBySameCompany -- " ); q = pm.newQuery(); Collection tuples = Laptop.laptopProcessorMadeBySameCompany(q); Utility.printCollectionOfArrays( tuples ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Laptop.sameProcessor -- " ); q = pm.newQuery(); ll = Laptop.sameProcessor(q); Utility.printCollection( ll ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Processor.installedOn -- " ); q = pm.newQuery(); ll = xmp.processor.installedOn(q); Utility.printCollection( ll ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Memory.installedOn -- " ); q = pm.newQuery(); ll = dual.memory.installedOn(q); Utility.printCollection( ll ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Company.memoryProcessor -- " ); q = pm.newQuery(); Collection cc = Company.memoryProcessor(7.5f, 12, q); Utility.printCollection( cc ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Company.differentCompanyProcessor -- " ); q = pm.newQuery(); cc = Company.differentCompanyProcessor(q); Utility.printCollection( cc ); q.closeAll(); System.out.println(); System.out.println( "-- TEST Laptop.groupByCompany -- " ); q = pm.newQuery(); tuples = Laptop.groupByCompany(q); Utility.printCollectionOfArrays( tuples ); q.closeAll(); if ( !pm.isClosed() ) pm.close(); } } 

TEXT 1 OUT PUT:

-- TEST Laptop.find -- Delion Cyber Force XMP 3009; Delion Anoteron M 123 8.0 GHz; SDR 500 11 GB; harddrive: 950 GB BBN Dual Power A554; BBN PXP Dual 599 7.0 GHz; SDR 500 11 GB; harddrive: 900 GB -- TEST Laptop.HDandHardDrive -- ThinkMachine MAX SX 10; Intelli Processor Ultra Pytron X44 9.0 GHz; SDR 500 11 GB; harddrive: 700 GB IMB SuperBusiness 30; ADM Turiaon 9.4 GHz; SDR 500 11 GB; harddrive: 720 GB ThinkMachine MAX SX 20; Intelli Processor Pytron X12 8.5 GHz; Hyper Channel 500 12 GB; harddrive: 750 GB Media Central Media 555; Intelli Processor Pytron X12 8.5 GHz; SDR 500 11 GB; harddrive: 850 GB Delion Cyber Force XMP 3009; Delion Anoteron M 123 8.0 GHz; SDR 500 11 GB; harddrive: 950 GB Delion Cyber Matrix UUV 24; Intelli Processor Ultra Pytron X44 9.0 GHz; Hyper Channel 500 12 GB; harddrive: 1000 GB -- TEST Laptop.speedPrice -- Delion Cyber Force XMP 3009; Delion Anoteron M 123 8.0 GHz; SDR 500 11 GB; harddrive: 950 GB Media Central Media 555; Intelli Processor Pytron X12 8.5 GHz; SDR 500 11 GB; harddrive: 850 GB ThinkMachine MAX SX 20; Intelli Processor Pytron X12 8.5 GHz; Hyper Channel 500 12 GB; harddrive: 750 GB ThinkMachine MAX SX 10; Intelli Processor Ultra Pytron X44 9.0 GHz; SDR 500 11 GB; harddrive: 700 GB IMB SuperBusiness 30; ADM Turiaon 9.4 GHz; SDR 500 11 GB; harddrive: 720 GB -- TEST Laptop.hasProcessor -- Delion Cyber Force XMP 3009; Delion Anoteron M 123 8.0 GHz; SDR 500 11 GB; harddrive: 950 GB BBN Dual Power A554; BBN PXP Dual 599 7.0 GHz; SDR 500 11 GB; harddrive: 900 GB -- TEST Laptop.laptopProcessorMadeBySameCompany -- BBN Dual Power A554; BBN PXP Dual 599 7.0 GHz; SDR 500 11 GB; harddrive: 900 GB BBN PXP Dual 599 7.0 GHz BBN Delion Cyber Force XMP 3009; Delion Anoteron M 123 8.0 GHz; SDR 500 11 GB; harddrive: 950 GB Delion Anoteron M 123 8.0 GHz Delion -- TEST Laptop.sameProcessor -- Delion Cyber Matrix UUV 24; Intelli Processor Ultra Pytron X44 9.0 GHz; Hyper Channel 500 12 GB; harddrive: 1000 GB IMB OfficeBusiness 123; Intelli Processor Pytron X12 8.5 GHz; SDR 300 13 GB; harddrive: 680 GB Media Central Media 555; Intelli Processor Pytron X12 8.5 GHz; SDR 500 11 GB; harddrive: 850 GB Media Central Media 876; Intelli Processor Ultra Pytron X44 9.0 GHz; Hyper Channel 500 12 GB; harddrive: 750 GB ThinkMachine MAX SX 10; Intelli Processor Ultra Pytron X44 9.0 GHz; SDR 500 11 GB; harddrive: 700 GB ThinkMachine MAX SX 20; Intelli Processor Pytron X12 8.5 GHz; Hyper Channel 500 12 GB; harddrive: 750 GB -- TEST Processor.installedOn -- Delion Cyber Force XMP 3009; Delion Anoteron M 123 8.0 GHz; SDR 500 11 GB; harddrive: 950 GB -- TEST Memory.installedOn -- BBN Dual Power A554; BBN PXP Dual 599 7.0 GHz; SDR 500 11 GB; harddrive: 900 GB Delion Cyber Force XMP 3009; Delion Anoteron M 123 8.0 GHz; SDR 500 11 GB; harddrive: 950 GB IMB SuperBusiness 30; ADM Turiaon 9.4 GHz; SDR 500 11 GB; harddrive: 720 GB Media Central Media 555; Intelli Processor Pytron X12 8.5 GHz; SDR 500 11 GB; harddrive: 850 GB ThinkMachine MAX SX 10; Intelli Processor Ultra Pytron X44 9.0 GHz; SDR 500 11 GB; harddrive: 700 GB -- TEST Company.memoryProcessor -- Delion IMB Media Central ThinkMachine -- TEST Company.differentCompanyProcessor -- Delion IMB -- TEST Laptop.groupByCompany -- BBN 1 7.0 11 Delion 2 8.0 12 IMB 2 8.5 13 Media Central 2 8.5 12 ThinkMachine 2 8.5 12 

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 blur-text-image
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!