Research Designs
Researchers were interested in learning the effects of trans fats on levels of cholesterol in the blood. Two different research designs were constructed.
Part I: Between-Groups Design
In the between-groups design, researchers were interested in whether cholesterol levels would differ depending on diet. Twenty participants were randomly assigned to one of two different groups. Group A was assigned a diet rich in fruits and vegetables and with no trans fats. Group B participants were asked to follow their normal diets, which contained varying levels of trans fats depending on the individual. After one month, blood samples were drawn and the following levels of cholesterol were obtained:
|
Participant |
Blood Cholesterol |
Diet |
|
1 |
129 |
Healthy |
|
2 |
98 |
Healthy |
|
3 |
150 |
Healthy |
|
4 |
75 |
Healthy |
|
5 |
135 |
Healthy |
|
6 |
175 |
Healthy |
|
7 |
115 |
Healthy |
|
8 |
103 |
Healthy |
|
9 |
156 |
Healthy |
|
10 |
143 |
Healthy |
|
11 |
239 |
Normal |
|
12 |
500 |
Normal |
|
13 |
350 |
Normal |
|
14 |
468 |
Normal |
|
15 |
198 |
Normal |
|
16 |
213 |
Normal |
|
17 |
225 |
Normal |
|
18 |
175 |
Normal |
|
19 |
560 |
Normal |
|
20 |
289 |
Normal |
In 2 to 3 sentences in a Microsoft Word document, answer the following questions:
What is the independent variable in this study?
What are the levels of that independent variable?
What is the dependent variable?
Submission Details:
Name this document SU_PSY2008_W5_A_LastName_FirstInitial
Create a data file that will enable you to conduct a between-groups analysis of this data.
Name your worksheet SU_PSY2008_W5_A_worksheet_LastName_FirstInitial
Part II: Within-Subjects Design
In the within-subjects design, researchers were interested in whether participants could lower their cholesterol levels by changing from a diet higher in trans fats to one with no trans fats. Ten research participants were selected. A baseline measure of cholesterol was taken from each. They were then put on a diet rich in fruits and vegetables and devoid of trans fats for one month. At the end of that month, blood cholesterol was again measured and the following results were obtained:
|
Participant |
Blood Cholesterol |
Diet |
|
1 |
129 |
Baseline |
|
1 |
98 |
Healthy |
|
2 |
150 |
Baseline |
|
2 |
75 |
Healthy |
|
3 |
175 |
Baseline |
|
3 |
135 |
Healthy |
|
4 |
115 |
Baseline |
|
4 |
103 |
Healthy |
|
5 |
156 |
Baseline |
|
5 |
143 |
Healthy |
|
6 |
500 |
Baseline |
|
6 |
450 |
Healthy |
|
7 |
468 |
Baseline |
|
7 |
350 |
Healthy |
|
8 |
198 |
Baseline |
|
8 |
213 |
Healthy |
|
9 |
225 |
Baseline |
|
9 |
175 |
Healthy |
|
10 |
560 |
Baseline |
|
10 |
481 |
Healthy |
In 2 to 3 sentences in a Microsoft Word document, answer the
following questions:
What is the independent variable in this study?
What are the levels of that independent variable?
What is the dependent variable?
In: Statistics and Probability
The management of Bar.Co have asked for your assistance in deciding whether to continue manufacturing a component or buy it from an outside supplier. The component in question is the Sicio that is used as a component on many of the finished products produced by Bar.Co. You have been provided with the following information:
Bar.Co’s normal annual requirement is for 5,000 Sicios per year.
Bar.Co’s purchasing department has asked external suppliers to quote for the supply of Sicios. The lowest quotation they have received is for a price of £10 per Sicio for a supply of between 4,000 and 6,000 Sicios per year.
Sicios are currently manufactured by Bar.Co’s precision engineering department, using specialised machinery. If Sicios are purchased from outside this machinery, which is in the last year of its useful life and not in a condition to be sold, will be scraped at a cost of £200. The net book value of this machinery is £1,000.
The costs of the precision engineering department, including those associated with the manufacturing of Sicios are estimated to be:
£
Direct materials 67,500
Direct labour 50,000
Indirect labour 26,500
Light and heat 5,500
Power 3,000
Depreciation (specialised machinery) 1,000
Depreciation (other machinery) 9,000
Other fixed departmental overheads 5,000
The cost accountant of Bar.Co has estimated that the cost of manufacturing Sicios by the precision engineering department is £16.50 per Sicio made up as follows:
£
Direct materials 3.50
Direct labour 5.60
Departmental overheads 4.60
Company overheads 2.80
The departmental overheads and the company overheads are not
specific to Sicio and have been allocated to the component based on
direct labour cost.
The impact on the precision engineering department of ceasing to
produce Sicios internally, other than the savings in direct costs
specifically associated with manufacturing Sicios, is estimated to
be:
Savings of £6,500 in indirect labour; savings of £1,000 in light and heat costs. No savings are expected for power costs and depreciation of other machinery;
An increase in other departmental fixed overheads of £4,000
because of increased activity in goods reception and
inspection.
Based on this information the cost accountant is in favour of
discontinuing the in-house manufacturing of Sicios.
Required:
a) Prepare a report that identifies, showing any necessary
calculations, the total cost for the precision engineering
department when Sicios are produced in-house and when they are
purchased from an outside supplier, highlighting any difference in
each cost item. You are also required to provide your advice
regarding the proposed change in the sourcing of Sicios.
b) Discuss any non-financial issues you think should be taken into
account in making this decision. Word limit: 400 words.
c) When a business seeks to understand what costs are relevant for
a decision, it may have to identify sunk costs and opportunity
costs. Explain what you understand by relevant costs, sunk costs
and opportunity costs, providing examples. Word limit: 400
words.
In: Accounting
Variables typically included in a multivariate demand function (other than the price and quantity of the item the demand function represents) are consumer tastes and preferences, the number of buyers, spendable (disposable) income, prices of substitute goods, prices of complementary goods, advertising expenditures, weather, and expectations. Recalling that the price of the item being considered is placed on the vertical axis, and the quantity on the horizontal axis, the other variables are termed demand shifters. Please answer the following questions about the affect changes in other variables might have on the demand for the item. These changes will either cause demand to increase (shift right) or decrease (shift left). Use either word as applicable, for the short answer.
If the demand for a specific brand of a good (for which many substitutes exist) decreases and there is no decrease in the demand for this type of good, then the demand for a substitute _____________ .
If the number of potential consumers for the good being considered decreases, then the demand for the good being considered likely:
If the demand for Lattes increases, then the demand for biscotti (a complementary good) should:
Suppose new antioxidant properties for broccoli are discovered. Antioxidant properties supposedly help prevent cancer. As a result of this discovery, the demand for broccoli can be expected to:
5. The Organic Light Emitting Diode (OLED) is a new and promising display technology. It promises to permit display screens to be thin, flexible, and bright. It is currently available only in small size. This technology works somewhat like a firefly, utilizing electroluminescence. However its competitor, the Liquid Crystal Display (LCD), can now be produced as one piece panels up to six feet tall. The OLED is its own light source, requiring no backlighting as does a LCD. Assuming the LCD and OLED have the same sized screen, future demand for the older LCD display can probably be expected to __________ .
Variables typically included in a multivariate supply function (other than the price and quantity of the item the supply function represents) are prices of other goods that use similar input resources for production, the number of suppliers, techniques of production, taxes and subsidies, prices of input resources, weather, and expectations. Please answer the following questions about the affect changes in other variables might have on the supply of the item. These changes will either cause supply to increase (shift right) or decrease (shift left). Use either word as applicable, for the short answer.
If the market price of gasoline returns to the near $4.00 per gallon level then demand for gas-gulping large autos is likely to decrease and manufacturers of these autos are likely to _____________ their supply:
A relative increase in the productivity of the technology used to produce the item being considered is likely to _____________________ its supply.
Hailstorms have pelted south central Texas grape vineyards, spoiling acres of grapes. This is likely to ______________ the supply of grapes for Texas wine.
A manufacturer, operating with a fixed production budget, discovers that the cost of input resources is increasing. The manufacturer is likely to ___________________ the quantity of the product produced.
The six-spotted evil weevil has attacked California’s broccoli crops. Their supply of broccoli is thus likely to:
In: Economics
Background
You are the owner of AAA Landscaping, a small company in Orlando, Florida, that specializes in resodding and maintenance of lawns. Much of your business is through word-of-mouth advertising. Once a contract is negotiated, portions of it are subcontracted out to other companies (e.g., sprinkler system repair and pesticide services). Recently, you went to the home of Stu Murphy to bid on resodding his lawn. He obtained several other bids, but yours was the lowest. You arranged for work to begin to remove old grass and replace it with the St. Augustine grass sod that he requested. As part of the contract, Stu also asked that some basic maintenance be done (e.g., hedge and tree trimming, hauling away of old decorative wooden logs from around flower beds, and general sprucing up of the front area of the house). In addition, fertilizer and pesticide were to be applied within two weeks. Stu signed the contract on Wednesday and the work was to be completed by Saturday, when he had planned a party.
Your Role
You were pleased to get the contract, worth over S 1,200. This is actually the third or fourth contract in the same subdivision because of word-of-mouth advertising. Your employees completed the initial sod removal and replacement, weeding, and pruning on Friday, and you received full payment on Monday. You received a call from Stu on Tuesday afternoon stating that several trees were not trimmed to his satisfaction, debris covering decorative
rocks along hedges was not removed as agreed, and bags of clippings had been left behind. Because of other commitments, it was only on Friday that you sent someone out to finish the job. On Saturday, Stu left another message on your answering machine stating that there was still an untrimmed tree, the debris remained, and the clippings were still in the side yard. You did not get around to returning his call. Stu called again Monday, repeating the message he had left before and reminding you that the contract called for pesticide and fertilizer to be
applied to the lawn. You called back and said that someone would be out the next day. Again, other commitments kept you from following through. Stu called on Wednesday and left a fourth message on your answering machine. He said that he was getting irritated at not getting callbacks and action on his needs. Without returning Stu's call, you responded by sending someone out on Thursday to take care of the outstanding work. It has been several days since the work was completed, and you assume that Stu is now satisfied since you have heard nothing else from him.
Critical Thinking Questions
1. Based on information in this chapter, how have you done on providing service to Stu? Explain.
2. What were Stu's needs in this case?
3. Could you have done anything differently?
4. Are you sure that Stu will give a good recommendation to neighbors or friends in the future? Why or why not?
In: Operations Management
Variables typically included in a multivariate demand function (other than the price and quantity of the item the demand function represents) are consumer tastes and preferences, the number of buyers, spendable (disposable) income, prices of substitute goods, prices of complementary goods, advertising expenditures, weather, and expectations. Recalling that the price of the item being considered is placed on the vertical axis, and the quantity on the horizontal axis, the other variables are termed demand shifters. Please answer the following questions about the affect changes in other variables might have on the demand for the item. These changes will either cause demand to increase (shift right) or decrease (shift left). Use either word as applicable, for the short answer.
1. In an effort to reduce congestion in central London, vehicle owners must now purchase expensive passes to drive there. As a result, the demand for public transportation (busses, the tube) _________ .
2. When the price of gasoline broke the magic $4.00 per gal, makers of large vehicles suddenly faced a ___________ demand for them.
3. Automobiles are an example of a normal good. This designation means that as per capita income increases, the demand for automobiles ______________.
4. Recently an outbreak of E.coli (which causes intestinal distress, liver damage, and sometimes death) was attributed to contaminated Romaine lettuce grown in Yuma, Arizona. As a result, the demand for other varieties of lettuce (not infected by the virus) ________________.
5. If research ever shows conclusively that increased cell phone use is linked to the increased incidence of brain tumors, then the demand for cell phone might ______________ .
Variables typically included in a multivariate supply function (other than the price and quantity of the item the supply function represents) are prices of other goods that use similar input resources for production, expectations, the number of suppliers, techniques of production, taxes and subsidies, and prices of input resources, weather. Please answer the following questions about the affect changes in other variables might have on the supply of the item. These changes will either cause supply to increase (shift right) or decrease (shift left). Use either word as applicable, for the short answer.
1. The production of Ethanol is being significantly subsidized by increasing the tax on “real gas” (which contains no Ethanol). Therefore, land devoted to growing corn is increasing and that devoted to growing wheat is decreasing. Thus it is likely that the supply of wheat will ______________.
2. Productivity is a key variable in the supply of items. An increase in productivity translates into a ____________ in the supply of the items.
3. Jet fuel prices are soaring. Therefore an economist would not be surprised to learn that airlines are _________________ the number of planes they are flying, hoping to more completely fill the remaining flights.
4. American automobile manufactures are responding to the increased demand for SUV and Crossover styles by ____________ the supply of them and ________________ the supply of unpopular Sedan styles..
5. Think of highways as a resource used in the production of highway transportation. Thus building more and better highways is likely to _______________ the supply of vehicles using them.
In: Economics
Write a C++ program to calculate the time to drain a cylindrical water tank for an initial water height ranging from 1 to 10 feet (specifically for 1, 2, 4, 6, 8, and 10 ft). The tank has a radius (rt) of 2 feet and the drain radius (rd) is 0.3 inch. The gravitational constant (g) is 32.2 feet/sec2.
The formula for time to drain the tank is
time=(rtrd)2h/vavg
where, average velocity, vavg=0.5(2gh).5
In your program, assign the values to the variables rt, rd, and g. Prompt user to enter the value of h. The program should calculate the value of vavg, and then display time in hours.
Using MS Visual Studio, create a project folder called tank and a source code file tank.cpp.
Use the function pow() in the formulas and NOT sqrt().
Set up the output statements (cout) such that the one line display looks like the following:
Initial water height (ft.) = 1; Time to drain (hrs.) = 0.44
STEP 1: Analyze the Problem –
There is only one required output (time in hour of data type double) and one input (initial water height in ft of data type int). All intermediate variables will be assigned a data type of double.
STEP 2: Develop a Solution –
Pseudo code is shown below.
Convert all input data to the same unit (ft)
Display a prompt to enter initial height of water
Read a value for the height
Calculate average velocity, using the given formulas
Display the calculated time
Hand calculation for h = 1 ft, rt = 2 ft, rd = 0.3 inch, and g = 32.2 ft/sec2:
time = ?
STEP 3: Code the Solution -
You can start the program as shown below:
// Filename:
// C++ program to calculate time to drain water tank
// Written by: Your Name ON: Date
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int h;
double rt = 2.0, rd = 0.3, g = 32.2;
double vavg, time;
// Input initial water height (h)
//---
// Set output formats
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);// Calculate average velocity in ft/hr
//---
// Calculate time in hrs to drain
// NOTE: The function pow(double a, int n) returns an
//---
// Display results in the specified format
//---
return 0;
}
STEP 4: Test and Correct the Program -
If the program shows the correct output, copy and paste the output into MS Word. Also copy and paste the source code to the word processor as well. To copy the display window contents, click on the small black box in the upper left corner, select Edit -> Select All, then click again on the box and select Edit -> Copy.
Test the code by changing initial heights to 2, 4, 6, 8, and 10 feet.
In: Computer Science
JAVA Program
Write a program that prompts the user for data until the user wishes to stop (you must have a while loop)
(You must read in at least 8 to 10 sets of voter data using dialog boxes)
The data to read in is:
You will then print the following statistics:
Design help with this assignment:
First, make sure you can read in all data. Then take one requirement at a time and print that result. For example, count the number of people for Trump and the number of people for Biden and print that out. Then move on to the next requirement.
Again, thanks in advance. I need to check my work with an expert's help before the following Tuesday. Virtual schooling leaves me no choice but to post on here to learn my mistakes. Please post the java code, and output, as well as a screenshot of both.
In: Computer Science
Case 2 Running Free Dog owners constitute a large target market. Most members share something in common: the desire to let the pet run free and unfettered. If other friendly dogs are nearby and want to play—all the better. The Running Free Dog Park was created to meet this need for owners in the greater Atlanta area. Out-of-home advertising can be the critical component of an IMC program and, in some cases, the primary medium. To help launch the new venture, a local advertising agency created a feeling of expectancy and mystery with a “Running Free Dog Park” campaign. The first billboard displayed a dog tied up with a leash; however, it was only a partial picture. The unfinished nature of the image helps capture interest. Next, the same dog is shown with an unfastened leash and the word “running” appears beneath the pet. In the final billboard, the dog appears unfetters, the leash is gone, and the message “Running Free Dog Park” appears. The billboard displays the services offered, the website address of the park, and the location of the park. In addition to billboards, street kiosks and bus wraps were used to get the message out. Three unleashed dogs in the grass of a park. A dog park can be marketed as a place for pets to run free. The early results of the campaign were positive. Many dog owners became aware of the new park. What followed represented common challenges in marketing communications: sustaining initial interest, moving consumers to action, and building repeat business. In this next phase, dog owners needed to be encouraged to try the facility. They should be led to believe that the price of entry was a value. Then, over time, they can be enticed to make return visits and to offer word-of-mouth referrals to other pet owners. Only if these objectives can be attained will the initial success of the Running Free campaign become validated. 7-48.Define the marketing goals for the second phase of the Running Free Dog Park promotional efforts.
7-49.How would the three-exposure hypothesis or recency theory apply to this advertising program in its initial stages? What about the second campaign after consumers are aware of the dog park?
7-50.Which traditional advertising media should the marketing team use for the second campaign? Discuss the pros and cons of each in terms of the Running Free Dog Park campaign and the desire to stimulate trial usage.
7-51.How could social media and nontraditional media be used to supplement a traditional media campaign in this circumstance?
7-52.Design a newspaper ad and an out-of-home ad that will be placed at Little League baseball parks in the area. Explain why having these two ads in different media is better than having two ads within the same media.
In: Operations Management
Total Quality Management Sec-2 with Dr. Alamelumangai Raman for Sem
2 2020
Home
My courses
BS BAHR3102-2 AM 2020-2
Final Online Assignment - BAHR3102 - TOTAL QUALITY MANAGEMENT
Final Online Assignment Questions
Question 1
Not yet answered
Marked out of 10.0
Not flaggedFlag question
Question text
A1.
1.Al Raffa Company reported the following costs for a month.
S.no
Activity
Amount In OMR
1
Quality Planning
1000
2
Service Audit
1500
3
Cost of Rework
2000
4
Cost of Retesting
2500
5
Customer Complaints
3000
Answer the following:( 5*2=10 Marks)
A. How much amount is spent on external failure costs and explain how the company can overcome the cost?
B. How much amount is spent on internal failure costs and explain how the company can overcome cost?
C. How much amount is spent on appraisal costs and explain how the company can overcome cost?
D. How much amount is spent on preventive costs and explain how the company can overcome cost?
E. What were the total quality costs of Al Raffa
Company for the month and explain the total quality cost?
Answer in the Word document (ANSWER SHEET) and Upload as attachment below
Question 2
Not yet answered
Marked out of 10.0
Not flaggedFlag question
Question text
B1.
Case Let Analysis:
Oman Commercial Vehicle Manufacturer Company is one of the largest companies in the Sultanate of Oman. It is the third-largest manufacturer of passenger cars. Extensive quality enhancement and cost reduction task was initiated in September 2018. The outcome of this task helped the company to reach a profit of 28 million while the loss in the year ended March 2017 was 500 million.
The company followed the cost cutting system and saved more than 300 million of the company’s expenses over the last two years. The positive turnaround of the cost-cutting resulted in huge money gain, which does not even go beyond the projection. The vice president of the company Mr. Ahmed, who is at the manufacturing, was given the title of “Cost-cutting champion”, and he oversee the entire initiative.
Four Specific Areas Were Identified
· Direct material costs (which constitute roughly 65 per cent of all costs);
· Variable conversion costs (power, fuel, water, tools, etc.);
· Fixed costs- (labour, marketing, corporate expenses, plant operations, research, and development).
· Financial restructuring (working capital, debt restructuring, balance sheet, etc.).
In order to implement, drive and monitor the across the organization, three teams are formed namely— members, leaders and champions. The teams focused on cost-cutting measures, getting back the company to financially stable. For better communication across the company, employees were co-opted.
In order to achieve quality management project goals and cost-cutting exercise, which go simultaneously, employees helped each other. More importantly, the message conveyed to the employees was cost cutting measures were no way cutting corners. The employees in the same teams were involved in both exercises. This resulted in many win-win situations.
Answer the Following Questions:
1. List and explain the roles of teams in the above case. Any four
2. Identify and explain the four specific areas that Mr. Ahmed identified and how this cost plays essential roles in reducing the expenses for the organization.
3. List and explain the roles of top management related to the above case. Any two.
Answer in the Word document (ANSWER SHEET) and Upload as attachment below
Question 3
Not yet answered
Marked out of 10.0
Not flaggedFlag question
Question text
C1.
The organization must adopt necessary tools and strategies for the
support development, and advance a process of continuous
improvement – Keeping this mind
Answer the Following Questions:
A. Select any three quality management tools that are necessary for a service organization and explain in detail.
B. State the advantages of this three tools and explain how it can be used in the service organization.
C. What are the challenges that you will be facing
when you are using this tools? Any four
Answer in the Word document (ANSWER SHEET) and Upload as attachment below
Question 4
Not yet answered
Marked out of 10.0
Not flaggedFlag question
Question text
D1.
Answer the following questions:(5*2 =10
Marks)
D1
A. Identify the name of the chart and explain the related concept.
B. When should we use this chart?
C. What are the problems should be attempted on priority? Justify. Any two.
D. Is there any rule to be followed in the chart? Justify
E. What are the advantages of
using this chart? List and explain any two.
Answer in the Word document (ANSWER SHEET) and Upload as attachment below
Question 5
Not yet answered
Marked out of 10.0
Not flaggedFlag question
Question text
E1.
Case Let Analysis :
Al Ayan Company is one of the medium level company producing play toys for children in Sultanate of Oman. Since last year, the company has been receiving increasing complaints on the quality and durability of toys. The company wanted to address this issue very seriously. The company benchmarked with another play toy company and planned to concentrate on Quality aspects such as the material used, cost of the material, no of defects, scrap items etc. The company wants to improve the image in public and make sure that the company manufacture toys with high quality.
Answer the following questions
A. Identify and explain the level of benchmarking used by Al Ayan Company. Any three points.
B. Link the case related to the four phases of benchmarking and explain in detail.
C. If Al Ayan adapts Deming’s Principles, will it improve the image of the company in public? Justify with any two principles.
In: Accounting
INSERT STRING INTO SEPARATE CHAIN HASHTABLE & ITERATE THROUGH HASHTABLE: JAVA
_________________________________________________________________________________________________________________
import java.util.*;
public class HashTable implements IHash {
// Method of hashing
private HashFunction hasher;
// Hash table : an ArrayList of "buckets", which store the actual
strings
private ArrayList<List<String>> hashTable;
/**
* Number of Elements
*/
private int numberOfElements;
private int numberOfBuckets;
/**
* Initializes a new instance of HashTable.
* <p>
* Initialize the instance variables. <br>
* Note: when initializing the hashTable, make sure to allocate each
entry in the HashTable
* to a new a HashBucket or null, your choice.
* @param numberOfBuckets the size of the hashTable
* @param hasher the type of hashing function
*/
public HashTable(int numberOfBuckets, HashFunction hasher) {
this.hasher = hasher;
this.numberOfBuckets = numberOfBuckets;
this.hashTable = new ArrayList<>();
for (int i = 0; i < numberOfBuckets; i++) {
hashTable.add(null);
}
this.numberOfElements = 0;
}
public boolean insert(String key) { // THIS METHOD NEEDS
HELP
int bucketToPlaceIn = hasher.hash(key) %
numberOfBuckets;
List<String> bucketContents =
hashTable.get(bucketToPlaceIn);
// if bucketToPlaceIn is null
// initialize bucketContents
// set hashTable at bucketToPlaceIn
equal to bucketContents
// if bucketContents doesn't contain the key
// add it
// return true
return false;
}
public boolean remove(String key) {
for (int i = 0; i < hashTable.size(); i++) {
for (int j = 0; j <
hashTable.get(i).size(); j++) {
if
(hashTable.get(i).get(j) == key) {
hashTable.get(i).remove(j);
return true;
}
}
}
return false;
}
public String search(String key) {
for (int i = 0; i < hashTable.size(); i++) {
for (int j = 0; j <
hashTable.get(i).size(); j++) {
if
(hashTable.get(i).get(j) == key) {
return key;
}
}
}
return null;
}
public int size() {
int returnSize = 0;
for (int i = 0; i < hashTable.size(); i++) {
returnSize +=
hashTable.get(i).size();
}
return returnSize;
}
public int size(int index) {
int returnSize = hashTable.get(index).size();
return returnSize;
}
// Return iterator for the entire hashTable,
// must iterate all hashBuckets that are not empty
public class HashIterator implements Iterator<String> {
// The current index into the hashTable
private int currentIndex;
// The current iterator for that hashBucket
private Iterator<String> currentIterator = null;
HashIterator() { // THIS METHOD NEEDS HELP
// YOUR CODE HERE
}
public String next() { // THIS METHOD NEEDS HELP
// YOUR CODE HERE
return null;
}
public boolean hasNext() { // THIS METHOD NEEDS HELP
// YOUR CODE HERE
return false;
}
}
// Return an iterator for the hash table
public Iterator<String> iterator() { // THIS METHOD NEEDS
HELP
// YOUR CODE HERE
return null;
}
/**
* Does not use the iterator above. Iterates over one bucket.
*
* @param index the index of bucket to iterate over
* @return an iterator for that bucket
*/
public Iterator<String> iterator(int index) {
List<String> bucket = hashTable.get(index);
return bucket != null ? bucket.iterator() : null;
}
// Prints entire hash table.
// NOTE: This method is used extensively for testing.
public void print() {
Debug.printf("HashTable size: " + size());
for (int index = 0; index < hashTable.size(); index++)
{
List<String> list = hashTable.get(index);
if (list != null) {
Debug.printf("HashTable[%d]: %d entries", index,
list.size());
for (String word : list) {
Debug.printf("String: %s (hash code %d)", word,
hasher.hash(word));
}
}else {
Debug.printf("HashTable[%d]: %d entries", index, 0);
}
}
}
}
FOR REFERENCE
// HashInterface.java - interface for hashing assignment
import java.util.Iterator;
public interface IHash {
/** Add a key to the hash table, if it is not currently in the
table
* @param key - the key to add
* @return true on success, false on failure (duplicate)
*/
public abstract boolean insert(String key);
/** Remove a key from the hash table
* @param key - the key to remove
* @return true on success, false on failure (not in table)
*/
public abstract boolean remove(String key);
/** Search for a key in the hash table
* @param key - the key to search for
* @return the key on success, null on failure (not in table)
*/
public abstract String search(String key);
/** Get the number of elements in the hash table
* @return the number of elements in the table
*/
public abstract int size();
/** Get the number of elements in the hash table at the given
index
* @param i the index in the hash table (0 to size-1)
* @return the size of the list in the i<sup>th</sup>
bucket
*/
public abstract int size(int i);
/** Get an iterator that return the Strings stored in
* the hash table one at a time. The order should be in order of
entries in
* the hash table itself and for a given bucket, the order in that
list.
* @return an Interator
*/
public abstract Iterator<String> iterator();
/** Get an iterator for the i<sup>th</sup>
bucket
* @param i the index in the hash table (0 to size-1)
* @return null if the bucket is empty, otherwise an iterator for
the bucket
*/
public abstract Iterator<String> iterator(int i);
/** Print the entire hash table.
*/
public abstract void print();
}
@FunctionalInterface
interface HashFunction {
int hash(String key);
}
public class Hasher {
// Hashing algorithms, see specification
/**
* Hashing algorithms, see provided documentation in
assignment
* @param hashFunction FIRST, SUM, PRIME, OR JAVA
* @return the corresponding HashFunction
*/
public static HashFunction make(String hashFunction) {
switch (hashFunction) {
case "FIRST":
return (String key) -> {
return
Math.abs(key.charAt(0));
};
case "SUM":
return (String key) -> {
int sumReturn = 0;
for (int i = 0; i <
key.length(); i++) {
sumReturn +=
Math.abs(key.charAt(i));
}
return sumReturn;
};
case "PRIME":
return (String key) -> {
int sumReturn = 7;
for (int i = 0; i <
key.length(); i++) {
sumReturn = (31*sumReturn) +
Math.abs(key.charAt(i));
}
return sumReturn;
};
case "JAVA":
return (String key) -> {
return key.hashCode();
};
default:
usage();
}
return null;
}
// Usage message
private static void usage() {
System.err.println("Usage: java Hasher <FIRST|SUM|PRIME|JAVA>
<word>");
System.exit(1);
}
// Test code for hasher
public static void main(String[] args) {
args = Debug.init(args);
if (args.length != 2)
usage();
HashFunction sh = make(args[0]);
int hashCode = sh != null ? sh.hash(args[1]) : 0;
System.out.printf("'%s' hashes to %d using %s\n", args[1],
hashCode, args[0]);
}
}
In: Computer Science