
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Write a program that will sort a prmiitive array of data using the following guidelines - DO NOT USE
- Create a helper function called 'RecurInsSort' such that:
- It is a standalone function not part of any class from the prior lab or any new class you feel like creating here,
- Takes in the same type of parameters as any standard Insertion Sort with recursion behavior, i.e.
- void RecurInsSort(Currency arr[], int size)
- Prints out how the array looks every time a recursive step returns back to its caller
- The objects in the array should be Money objects added or manipulated using Currency references/pointers.
- It is OK to print out the array partially when returning from a particular step as long as the process of sorting is clearly demonstrated in the output.
- In the 'main', first ask the user for the number of elements, not to exceed SORT_MAX_SIZE = 16 (put appropriate input validation)
- Then ask the user to provide Money objects similar to the previous lab. Try to use your Currency and Money classes as-is without making any changes. If you do make changes to be able to complete this lab, clearly mention what has been changed, otherwise there will be a small penalty if I have to compare your class files to the prior lab.
- Based on the input, create an appropriate array for the data to be entered.
- Then sort the array using your sort function of step 1. Take screenshots to be uploaded with the project.
- Make sure that the output is being written to console as well as an output file at the same time. Use an additional helper function if that makes things easier. Do not copy and paste text from your console to create the output file.
- Ensure input and any other data validations as needed and provide descriptive prompts with emphasis on usability.
- The image below are code used for the assignment
![Currency.java:
// abstract base class called Currency with two integer attributes
public abstract class Currency{
protected int noteValue;
protected int coinValue;
/**
* Default Construction
*/
public Currency() {
this.noteValue = 0;
this.coinValue = 0;
}
/**
* Construction based on parameters for all attributes
* @param noteValue
@param coinValue
*/
public Currency(int noteValue, int coinValue) {
this.noteValue = noteValue;
this.coinValue = coinValue;
}
/**
Copy Constructor
* @param currency
*/
public Currency(Currency currency) {
this.noteValue = currency.noteValue;
this.coinValue = currency.coinValue;
}
/**
* Getter for noteValue
* @return the noteValue
*/
public int getNoteValue() {
return noteValue;
}
/**
* Setters for noteValue
@param noteValue the noteValue to set
*/
public void setNoteValue(int noteValue) {
this.noteValue = noteValue;
}
/**
* Getter for coinValue
@return the coinValue
*/
public int getCoinValue() {
return coinValue;
}
/**
* Setter for coinValue
* @param coinValue the coinValue to set
*/
public void setCoinValue(int coinValue) {
this.coinValue = coinValue;
}
// Adding two objects of the same currency
public abstract Currency addCurrency(Currency c);
// Subtracting one object from another object of the same currency
public abstract Currency subtractCurrency(Currency c);
/* Comparing two objects of the same currency for equality/inequality Comparing
* two objects of the same currency to identify which object is larger or
* smaller*/
public abstract int compareCurrency(Currency c);
// Print method to print details of a currency object
public abstract void printCurrency();
}
Money.java:
// derived class - Money
public class Money extends Currency {
// two non-public attributes
private String currencyName;
private String coinName;
public Money() {
super();
this.currencyName = "Dollar";
this.coinName = "Cent";
}
/**
* @param noteValue
* @param coinValue
*/
public Money(int noteValue, int coinValue) {
super(noteValue, coinValue);
this.currencyName = "Dollar";
this.coinName = "Cent";
}
/**
* Adding two objects of the same currency
* @param currency
*/
public Currency addCurrency(Currency currency) {
// Cast the currency to be Money
Money other = (Money) currency;
// get notes and coins value
int notes = super.getNoteValue() + other.getNoteValue();
int coins = super.getCoinValue() + other.getCoinValue();
// if coins is greater than 100
if (coins >= 100) {
// increment the notes count
notes++;
// decrement 100 from coins
coins -= 100;
}
return new Money(notes, coins);
}
/**
* Subtracting one object from another object of the same currency
* @param currency
*/
*/
public Currency addCurrency(Currency currency) {
// Cast the currency to be Money
Money other = (Money) currency;
// get notes and coins value
int notes = super.getNoteValue() + other.getNoteValue();
int coins = super.getCoinValue() + other.getCoinValue();
// if coins is greater than 10O
if (coins >= 100) {
// increment the notes count
notes++;
// decrement 100 from coins
coins -= 100O;
}
return new Money(notes, coins);
}
/**
* Subtracting one object from another object of the same currency
@param currency
*/
public Currency subtractCurrency(Currency currency) {
// Cast the currency to be Money
Money other = (Money) currency;
// get notes and coins value
int notes = super.getNoteValue() - other.getNoteValue();
int coins = super.getCoinValue() - other.getCoinValue();
// if no coins
if (coins < 0) {
// increment the notes count
notes--;
// decrement 100 from coins
coins += 100;
}
return new Money(notes, coins);
}
/**
* Comparing two objects of the same currency for equality/inequality Comparing
* two objects of the same currency to identify which object is larger or
* smaller
*/
public int compareCurrency(Currency currency) {
Money other = (Money) currency;
if (this.getNoteValue() > other.getNoteValue())
return 1;
else if (this.getNoteValue() < other.getNoteValue())
return -1;
else if (this.getCoinValue() > other.getCoinValue())
return 1;
else if (this.getCoinValue() < other.getCoinValue())
return -1;
else
return 0;
}
/**
* Print method to print details of a currency object
*/
public void printCurrency() {
// coin value is greater than 10 cents
if (super.getCoinValue() > 10) {
System.out.print(super.getNoteValue() + " " + currencyName + " " + super.getCoinValue() + "" + coinName);
} else {
System.out.print(super.getNoteValue() + ".O " + currencyName +
+ super.getCoinValue() + "" + coinName);
}
}
}
labimain.java:
import java.util.Scanner;
public class lab1main {
public static void main(String[] args) {
// Create currency objects
Currency[] currencies = new Currency[5];
Scanner scanner = new Scanner(System.in);
// iterate to get 5 currencies
for (int currencyltem = 0; currencyltem < 5; currencyltem++) {
System.out.print("Enter currency "+ (currencyltem + 1) + " value: ");
%3D
String val = scanner.nextLine();
// split the string to notes and coins
int noteValue = Integer.valueOf(val.split("\\,")[0]);
int coinValue = Integer.valueOf(val.split("\\.")[1]);
// check if coin value is less than 10, multiply the coin vlaue by 10
if(coinValue < 10) {
coinValue *= 10;
}
// create a money instance
currencies[currencyltem] = new Money(noteValue, coinValue);
}
System.out.printIn("\n***** List of Money Objects created*****");
// Iterate through the currencies
for (Currency currency : currencies) {
// print the currency
currency.printCurrency();
System.out.println();
}
// adding first money object to second and print the result
System.out.println("\n*** Adding the first Money object to the second *** ");
currencies[0].addCurrency(currencies[1]).printCurrency();
// Subtract the first Money object from the third and print the result
System.out.println("\n\n** Subtract the first Money object from the third ***");
currencies[2].subtractCurrency(currencies[0]).printCurrency();
// compare the first and fourth money object
System.out.printin("\n\n*** Comparing first and fourth Money Object ***");
if (currencies[0].compareCurrency(currencies[3]):
0) {
==
currencies[0].printCurrency();
System.out.print(" is equal to ");
currencies[3].printCurrency();
} else {
currencies[0].printCurrency();
System.out.print(" is not equal to ");
currencies[3].printCurrency();
}
// Compare the first Money object to the fifth
System.out.printin("\n\n*** Comparing first and fifth Money Object ***");
if (currencies[0].compareCurrency(currencies[4]) :
1) {
==
currencies[0].printCurrency();
System.out.print(" is greater than ");
currencies[4].printCurrency();
} else if (currencies[0].compareCurrency(currencies[4]) ==
-1) {
currencies[4].printCurrency();
System.out.print(" is greater than ");
currencies[0].printCurrency();
}
scanner.close();
}
}](https://content.bartleby.com/qna-images/question/53635f3d-ce04-4168-bacc-0df54500922b/e736f74e-89cc-4bf4-94e2-3b2aacc59564/r86jbjm_thumbnail.png)
Transcribed Image Text:Currency.java:
// abstract base class called Currency with two integer attributes
public abstract class Currency{
protected int noteValue;
protected int coinValue;
/**
* Default Construction
*/
public Currency() {
this.noteValue = 0;
this.coinValue = 0;
}
/**
* Construction based on parameters for all attributes
* @param noteValue
@param coinValue
*/
public Currency(int noteValue, int coinValue) {
this.noteValue = noteValue;
this.coinValue = coinValue;
}
/**
Copy Constructor
* @param currency
*/
public Currency(Currency currency) {
this.noteValue = currency.noteValue;
this.coinValue = currency.coinValue;
}
/**
* Getter for noteValue
* @return the noteValue
*/
public int getNoteValue() {
return noteValue;
}
/**
* Setters for noteValue
@param noteValue the noteValue to set
*/
public void setNoteValue(int noteValue) {
this.noteValue = noteValue;
}
/**
* Getter for coinValue
@return the coinValue
*/
public int getCoinValue() {
return coinValue;
}
/**
* Setter for coinValue
* @param coinValue the coinValue to set
*/
public void setCoinValue(int coinValue) {
this.coinValue = coinValue;
}
// Adding two objects of the same currency
public abstract Currency addCurrency(Currency c);
// Subtracting one object from another object of the same currency
public abstract Currency subtractCurrency(Currency c);
/* Comparing two objects of the same currency for equality/inequality Comparing
* two objects of the same currency to identify which object is larger or
* smaller*/
public abstract int compareCurrency(Currency c);
// Print method to print details of a currency object
public abstract void printCurrency();
}
Money.java:
// derived class - Money
public class Money extends Currency {
// two non-public attributes
private String currencyName;
private String coinName;
public Money() {
super();
this.currencyName = "Dollar";
this.coinName = "Cent";
}
/**
* @param noteValue
* @param coinValue
*/
public Money(int noteValue, int coinValue) {
super(noteValue, coinValue);
this.currencyName = "Dollar";
this.coinName = "Cent";
}
/**
* Adding two objects of the same currency
* @param currency
*/
public Currency addCurrency(Currency currency) {
// Cast the currency to be Money
Money other = (Money) currency;
// get notes and coins value
int notes = super.getNoteValue() + other.getNoteValue();
int coins = super.getCoinValue() + other.getCoinValue();
// if coins is greater than 100
if (coins >= 100) {
// increment the notes count
notes++;
// decrement 100 from coins
coins -= 100;
}
return new Money(notes, coins);
}
/**
* Subtracting one object from another object of the same currency
* @param currency
*/
*/
public Currency addCurrency(Currency currency) {
// Cast the currency to be Money
Money other = (Money) currency;
// get notes and coins value
int notes = super.getNoteValue() + other.getNoteValue();
int coins = super.getCoinValue() + other.getCoinValue();
// if coins is greater than 10O
if (coins >= 100) {
// increment the notes count
notes++;
// decrement 100 from coins
coins -= 100O;
}
return new Money(notes, coins);
}
/**
* Subtracting one object from another object of the same currency
@param currency
*/
public Currency subtractCurrency(Currency currency) {
// Cast the currency to be Money
Money other = (Money) currency;
// get notes and coins value
int notes = super.getNoteValue() - other.getNoteValue();
int coins = super.getCoinValue() - other.getCoinValue();
// if no coins
if (coins < 0) {
// increment the notes count
notes--;
// decrement 100 from coins
coins += 100;
}
return new Money(notes, coins);
}
/**
* Comparing two objects of the same currency for equality/inequality Comparing
* two objects of the same currency to identify which object is larger or
* smaller
*/
public int compareCurrency(Currency currency) {
Money other = (Money) currency;
if (this.getNoteValue() > other.getNoteValue())
return 1;
else if (this.getNoteValue() < other.getNoteValue())
return -1;
else if (this.getCoinValue() > other.getCoinValue())
return 1;
else if (this.getCoinValue() < other.getCoinValue())
return -1;
else
return 0;
}
/**
* Print method to print details of a currency object
*/
public void printCurrency() {
// coin value is greater than 10 cents
if (super.getCoinValue() > 10) {
System.out.print(super.getNoteValue() + " " + currencyName + " " + super.getCoinValue() + "" + coinName);
} else {
System.out.print(super.getNoteValue() + ".O " + currencyName +
+ super.getCoinValue() + "" + coinName);
}
}
}
labimain.java:
import java.util.Scanner;
public class lab1main {
public static void main(String[] args) {
// Create currency objects
Currency[] currencies = new Currency[5];
Scanner scanner = new Scanner(System.in);
// iterate to get 5 currencies
for (int currencyltem = 0; currencyltem < 5; currencyltem++) {
System.out.print("Enter currency "+ (currencyltem + 1) + " value: ");
%3D
String val = scanner.nextLine();
// split the string to notes and coins
int noteValue = Integer.valueOf(val.split("\\,")[0]);
int coinValue = Integer.valueOf(val.split("\\.")[1]);
// check if coin value is less than 10, multiply the coin vlaue by 10
if(coinValue < 10) {
coinValue *= 10;
}
// create a money instance
currencies[currencyltem] = new Money(noteValue, coinValue);
}
System.out.printIn("\n***** List of Money Objects created*****");
// Iterate through the currencies
for (Currency currency : currencies) {
// print the currency
currency.printCurrency();
System.out.println();
}
// adding first money object to second and print the result
System.out.println("\n*** Adding the first Money object to the second *** ");
currencies[0].addCurrency(currencies[1]).printCurrency();
// Subtract the first Money object from the third and print the result
System.out.println("\n\n** Subtract the first Money object from the third ***");
currencies[2].subtractCurrency(currencies[0]).printCurrency();
// compare the first and fourth money object
System.out.printin("\n\n*** Comparing first and fourth Money Object ***");
if (currencies[0].compareCurrency(currencies[3]):
0) {
==
currencies[0].printCurrency();
System.out.print(" is equal to ");
currencies[3].printCurrency();
} else {
currencies[0].printCurrency();
System.out.print(" is not equal to ");
currencies[3].printCurrency();
}
// Compare the first Money object to the fifth
System.out.printin("\n\n*** Comparing first and fifth Money Object ***");
if (currencies[0].compareCurrency(currencies[4]) :
1) {
==
currencies[0].printCurrency();
System.out.print(" is greater than ");
currencies[4].printCurrency();
} else if (currencies[0].compareCurrency(currencies[4]) ==
-1) {
currencies[4].printCurrency();
System.out.print(" is greater than ");
currencies[0].printCurrency();
}
scanner.close();
}
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Python only** define the following function: 1. This function must add a task to a checklist, setting its initial value to False. It will accept two parameters: the checklist object to add to, and the task name to add. In addition to adding the task, it must return the (now modified) checklist object that it was given. There is one issue, however: a task cannot be added to a checklist if the name requested is already being used by another task in that checklist. In that case, this function must print a specific message and must return None Define addTask with 2 parameters Use def to define addTask with 2 parameters Use a return statement Within the definition of addTask with 2 parameters, use return _ in at least one place. Do not use any kind of loop Within the definition of addTask with 2 parameters, do not use any kind of loop.arrow_forwardTopical Information Use C++. This lab will help you practice with dynamic memory (NOT mixed with classes). Program Information Heat flow through a rod can be simulated fairly easily in a computer program. We can simulate the rod using an array of temperatures. The rod begins all at the same temperature (user determined), but holding some position(s) of the rod at constant temperature (holding a match or ice cube to the rod) provides a [set of] heat source(s) (or sink(s)). To update the temperature at each time step (second?), you take the average of the positions on each side from the previous time step (and at the current position). For instance, if the following was the initial state of the rod: +------+------+------+------+------+------+------+------+ | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | +------+------+------+------+------+------+------+------+ And then the user specifies that there is a heat source at the left end of 100 degrees:…arrow_forwardPlease use easy logic with proper indentations and comments for understanding!. Coding should be in C++. 3. Define a class which stores up to 10 integer values in an array. The class should also define the following 4 public methods: setNumber – accepts an integer value to store in the array. The value is stored in the next available element of the array (first call to the method stores the value in element 0 with the second call storing the value in element 1.) The method returns true if there is room in the array and the integer was successfully stored. Returns false otherwise. clear – removes all values from the array so that the array can be reused. displayNumbers – displays the values currently stored in the array. getStats – determines the largest, smallest, and average of the values currently stored in the array. These values are returned to the caller via reference parameters. All methods should produce correct results regardless of the order in which…arrow_forward
- Write a simple trivia quiz game using c++ Start by creating a Trivia class that contains information about a single trivia question. The class should contain a string for the question, a string for the answer to the question, and an integer representing the dollar amount the question is worth (harder questions should be worth more). Add appropriate constructor and accessor functions. In your main function create either an array or a vector of type Trivia and hard-code at least five trivia questions of your choice. Your program should then ask each question to the player, input the player’s answer, and check if the player’s answer matches the actual answer. If so, award the player the dollar amount for that question. If the player enters the wrong answer your program should display the correct answer. When all questions have been asked display the total amount that the player has won.arrow_forwardWrite a findSpelling Function -PHP Write a function findSpellings($word, $allWords) that takes a string and an array of dictionary words as parameters. The function should return an array of possible spellings for a misspelled $word. One way to approach this is to use the soundex() Words that have the same soundex are spelled similarly. Return an array of words from $allWords that match the soundex for $word. I have most of the code. How do I append the $sound to the $mathcing array?arrow_forwardcreate using c++ One problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector . This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have the following A private member variable called dynamicArray that references a dynamic array of type string. A private member variable called size that holds the number of entries in the array. A default constructor that sets the dynamic array to NULL and sets size to 0. A function that returns size . A function named addEntry that takes a string as input. The function should create a new dynamic array one element larger than dynamicArray , copy all elements from dynamicArray into the new array, add the new string onto the end of the new array, increment size, delete the…arrow_forward
- Write in c++arrow_forwardarray of Payroll ObjectsDesign a PayRoll class that has data members for an employee’shourly pay rate and number of hours worked. Write a program withan array of seven PayRoll objects. The program should read thenumber of hours each employee worked and their hourly pay ratefrom a file and call class functions to store this information in theappropriate objects. It should then call a class function, once foreach object, to return the employee’s gross pay, so this informationcan be displayed.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education