Getting Started
Create a class called Lab8. Use the same setup for setting up your class and main method as you
did for the previous assignments. Be sure to name your file Lab8.java. Additionally, make
another file called Arrays.java. This file will be an object, so simply start it off by declaring an
Arrays class. You can copy the following skeleton and fill in the appropriate code below each of
the comments:
public class Arrays {
/ Instance Variables
// Constructors
// findMin 1
// findMax
// calcSum
// calcAverage
// toString
}
Task Overview
Your task for this lab is to create a class called Arrays with some array processing methods. This
class will maintain an array and the number of elements present in it. Additionally, methods will
be available to display the current min and max elements along with the average of all of them.
Finally, a toString() method will be available to cleanly display all the array elements. Finally,
you will write a simple driver class to test out the above Arrays class.
Part 1: Instance Variables for Arrays
The first thing to do for the Arrays class is to set up its instance variables. Declare the following
(private) instance variables:
• An int array called array ? this will be the array we will be writing methods for.
• An int called count - this represents the number of valid elements in the array.
Part 2:
Constructors for Arrays The Arrays class will have two constructors. The first constructor takes
the maximum size of the array as input as a parameter and initializes the array instance variable
appropriately. It also sets count to size. Finally, it will initialize all of the array elements to some
values between 0 and 10, inclusive. To create this constructor, follow these steps:
• Import java.util.Random to make use of the random number generator.
• Create a constructor with the following header: public Arrays(int size)
• Initialize your array variable and set its size to size (see the chart on page 252 for reference on
initializing arrays). Be very careful that you are setting the value of your array instance variable,
as opposed to creating a new variable called array.
• Set the value of the count variable to size because we will be populating the entire array.
• Copy the following code to the constructor in order to generate random values between 0 and
10, inclusive:
Random rand = new Random();
for (int i = 0; i < count; i++)
{
array[i] = (rand.nextInt(10));
}
Next, create another constructor with the following header: public Arrays(int[] arr). This
constructor will initialize the class by using the passed arr argument in order to fill its instance
variables. The following things need to be done inside of this constructor:
• Set the array variable equal to arr.
• Set the count variable equal to the length of the array.
Part 3: Displaying the Output findMin()
The first method of this class will search the array for the minimum element. Copy the following
code for the findMin method. Note how the count i.
java I am trying to run my code but it is not letting me .pdfadinathassociates
java
I am trying to run my code but it is not letting me i dont know what i should do or fix. Thank you so
much for your help. This is the problem and my code will be on the bottom.
Problem #1 and Only
Dynamic Array of Integers Class
Create a class named DynamicArray that will have convenient functionality similar to JavaScripts
Array object and Javas ArrayList class. The class allows to store array of integers that can grow
and shrink as needed, search for values, remove elements, etc.
You are not allowed to use ArrayList object as well as any methods from java.util.Arrays
class.
Please see the list of required features and methods below.
private int array[] You MUST store the data internally in a regular partially-filled array of integers.
Please DO NOT USE ArrayList. The size of the allocated array is its capacity and will be
discussed below.
private int size. This variable stores the number of occupied elements in the array. Set to 0 in the
constructor.
Constructor with parameter. The parameter defines the capacity (length) of initial array. Allocates
array of given capacity (length), sets size field to 0. In case the parameter given to constructor is 0
or negative, IllegalArgumentException is being thrown.
No-argument constructor. Allocates array of length 3, assigns it to the array field, sets size field to
0.
Copy constructor. The constructor takes an object of type DynamicArray as a parameter and
copies it into the object it creates. The constructor throws IllegalArgumentException if the object
that was passed to copy from is null.
int getSize() returns the number of occupied elements in the array.
int getCapacity() returns the actual size (length) of the partially-filled array
int [] getArray() accessor returns the entire partially-filled array. Make sure you DO NOT return the
private array field, make a copy of it.
int [] toArray() accessor returns an occupied part of the partially-filled array. Make sure you DO
NOT return the private array field. Instead, allocate memory for the new array, copy the occupied
portion of the field into that new object, and return the new array.
public void push(int num) adds a new element to the end of the array and increments the size
field. If the array is full, you need to increase the capacity of the array:
Create a new array with the size equal to double the capacity of the original one.
Copy all the elements from the array field to the new array.
Add the new element to the end of the new array.
Use new array as an array field.
Make sure your method works well when new elements are added to an empty DynamicArray.
public int pop() throws RuntimeException removes the last element of the array and returns it.
Decrements the size field. If the array is empty a RuntimeException with the message Array is
empty must be thrown. At this point check the capacity of the array. If the capacity is 4 times larger
than the number of occupied elements (size), it is time to shrink the array:
Create a new array wi.
An Introduction to Programming in Java: ArraysMartin Chapman
An Introduction to Programming in Java: Arrays. Last delivered in 2012. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
,,,,,,jhbhhhhhvggvvcccccccfghhhhhhhhhhhhhgggggggggyyyyy hhbbhhhhgggyhhsyddhdhhddhsiejdhajshdhdhdhdhdhdudufjdhyeyeg hhdhdhdhdhdhdhdhdh d bhsuhabuesjjsoeijshshdhsjajsijehfdhhdhdhdhdhhdxbbxxhxhhdja hi in najajajhwhr7fhhhhhhhhhhhhhhhhhuhhuwbshdhhddh8rhedi8fnf
java I am trying to run my code but it is not letting me .pdfadinathassociates
java
I am trying to run my code but it is not letting me i dont know what i should do or fix. Thank you so
much for your help. This is the problem and my code will be on the bottom.
Problem #1 and Only
Dynamic Array of Integers Class
Create a class named DynamicArray that will have convenient functionality similar to JavaScripts
Array object and Javas ArrayList class. The class allows to store array of integers that can grow
and shrink as needed, search for values, remove elements, etc.
You are not allowed to use ArrayList object as well as any methods from java.util.Arrays
class.
Please see the list of required features and methods below.
private int array[] You MUST store the data internally in a regular partially-filled array of integers.
Please DO NOT USE ArrayList. The size of the allocated array is its capacity and will be
discussed below.
private int size. This variable stores the number of occupied elements in the array. Set to 0 in the
constructor.
Constructor with parameter. The parameter defines the capacity (length) of initial array. Allocates
array of given capacity (length), sets size field to 0. In case the parameter given to constructor is 0
or negative, IllegalArgumentException is being thrown.
No-argument constructor. Allocates array of length 3, assigns it to the array field, sets size field to
0.
Copy constructor. The constructor takes an object of type DynamicArray as a parameter and
copies it into the object it creates. The constructor throws IllegalArgumentException if the object
that was passed to copy from is null.
int getSize() returns the number of occupied elements in the array.
int getCapacity() returns the actual size (length) of the partially-filled array
int [] getArray() accessor returns the entire partially-filled array. Make sure you DO NOT return the
private array field, make a copy of it.
int [] toArray() accessor returns an occupied part of the partially-filled array. Make sure you DO
NOT return the private array field. Instead, allocate memory for the new array, copy the occupied
portion of the field into that new object, and return the new array.
public void push(int num) adds a new element to the end of the array and increments the size
field. If the array is full, you need to increase the capacity of the array:
Create a new array with the size equal to double the capacity of the original one.
Copy all the elements from the array field to the new array.
Add the new element to the end of the new array.
Use new array as an array field.
Make sure your method works well when new elements are added to an empty DynamicArray.
public int pop() throws RuntimeException removes the last element of the array and returns it.
Decrements the size field. If the array is empty a RuntimeException with the message Array is
empty must be thrown. At this point check the capacity of the array. If the capacity is 4 times larger
than the number of occupied elements (size), it is time to shrink the array:
Create a new array wi.
An Introduction to Programming in Java: ArraysMartin Chapman
An Introduction to Programming in Java: Arrays. Last delivered in 2012. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
,,,,,,jhbhhhhhvggvvcccccccfghhhhhhhhhhhhhgggggggggyyyyy hhbbhhhhgggyhhsyddhdhhddhsiejdhajshdhdhdhdhdhdudufjdhyeyeg hhdhdhdhdhdhdhdhdh d bhsuhabuesjjsoeijshshdhsjajsijehfdhhdhdhdhdhhdxbbxxhxhhdja hi in najajajhwhr7fhhhhhhhhhhhhhhhhhuhhuwbshdhhddh8rhedi8fnf
Everything needs to be according to the instructions- thank you! SUPPO.pdffirstchoiceajmer
Everything needs to be according to the instructions, thank you!
SUPPORTING CODE:
MyList.java
/**
This interface specifies the basic operations of any list-like object.
This interface contains a variation of the methods of the
standard java.util.List interface.
*/
public interface MyList {
/**
Adds an element at the end of the list.
*/
public void addToEnd(Object o);
/**
Inserts an element at the specified index
Throws NoSuchElementException if index is out of bounds.
*/
public void insertAt(int index, Object o);
/**
Removes the element at the specified index
Throws NoSuchElementException if index is out of bounds.
*/
public void removeAt(int index);
/**
Returns the element at the specified index
Throws NoSuchElementException if index is out of bounds.
*/
public Object getAt(int index);
/**
Returns the size of the list.
@return the number of elements in the list
*/
public int getSize();
/**
Returns a list iterator for this list.
@return a list iterator for this list
*/
public MyListIterator getIterator();
}
MyListIterator.java
/**
A list iterator allows access of a position in a list.
This interface contains a subset of the methods of the
standard java.util.ListIterator interface. The methods for
backward traversal are not included.
*/
public interface MyListIterator
{
/**
Moves the iterator past the next element.
@return the traversed element
*/
Object next();
/**
Tests if there is an element after the iterator
position.
@return true if there is an element after the iterator
position
*/
boolean hasNext();
}
Main.java
// you may use this file to write and run code to test your MyArrayList class
public class Main {
public static void main(String[] args) {
}
}
FILE THAT NEEDS THAT NEEDS CODE:
MyArrayList.java
// Complete the implementation of your MyArrayList class in this file
public class MyArrayList implements MyList {
// Implement the required fields and methods here
private int capacity = 8;
private Object[ ] array = new Object [capacity];
private int size = 0;
@Override
public void add(Object o) {
if (size >= capacity){
Object[] temp = new Object[2*array.length];
for(int i=0;i<size;++i){
temp[i] = array[i];
}
this.capacity = 2*array.length;
array = temp;
array[size++] = o;
return;
}
else
{
array[size++] = o;
}
}
@Override
public int size() {
return size;
}
@Override
public Object at(int index) {
if (index >= capacity)
return null;
else
return array[index];
}
@Override
public void insertAt(int index, Object o) {
if (index >= capacity)
return;
else
{
size++;
for (int x = size - 1; x > index; x--) {
array[x] = array[x - 1];
}
array[index] = o;
}
}
@Override
public void removeAt(int index) {
if (index >= size || size == 0)
return;
else {
Object e = array[index];
for (int x = index; x < this.array.length - 1; x++) {
array[x] = array[x + 1];
}
size--;
}
}
public void ensureCapacity(int minCapacity) {
}
public void trimToSize() {
ensureCapacity(size);
}
// Do not alter the code below
@Override
public MyListIterator getIterator() {
return new MyA.
ObjectivesMore practice with recursion.Practice writing some tem.docxvannagoforth
Objectives
More practice with recursion.
Practice writing some template functions.
Use stack ADT to implement given algorithms.
Look at some common applications of stacks.Description
In this assignment, you will be using the Stack abstract data type we developed this week and discussed in our weeks lectures, to implement 4 functions that use a stack data type to accomplish their algorithms. The functions range from relatively simple, straight forward use of a stack, to a bit more complex. But in all 4 cases, you should only need to use the abstract stack interface functions push(), pop(), top(), and isEmpty() in order to successfully use our Stack type for this assignment and the function you are asked to write.
For this assignment you need to perform the following tasks.
1. In the rst task, we will write a function that will check if a string of parenthesis is matching. Strings will be given to the function of the format "(()((())))", using only opening "(" and closing ")". Your function should be named doParenthesisMatch(). It takes a single string as input, and it returns a boolean result of true if the parenthesis match, and false otherwise.
The algorithm to check for matching parenthesis using a stack is fairly simple. A pseudo-code description migth be
for each charcter c in expression do
if c is an open paren ’(’ push it on stack
if c is a close paren ’)’:
do
if stack is empty
answer is false, because we can’t match the current ’)’
else pop stack, because we just matched an open ’(’ with a close ’)’
done
done
Your function will be given a C++ string class as input. It is relatively simple to parse each character of a C++ string. Here is an example for loop to do this:
s = "(())";
for (size_t index = 0; index < s.length(); index++)
{ char c = s[index];
// handle char c of the string expression s here }
2. In the next task, we will also write a function that decodes a string expression. Given a sequence consisting of ’I’ and ’D’ characters, where ’I’ denotes increasing and ’D’ denotes decreasing, decode the given sequence to construct a "minimum number" without repeated digits.
An example of some inputs and outputs will make it clear what is meant by a "minimal number".
sequence
output
IIII
->
12345
DDDD
->
54321
ID
->
132
IDIDII
->
1325467
IIDDIDID
->
125437698
If you are given 4 characters in the input sequence, the result will be a number with 5 characters, and further only the digits ’12345’ would be in the "minimal number" output. Each ’I’ and ’D’ in the input denotes that the next digit in the output should go up (increase) or go down (decrease) respectively. As you can see for the input sequence "IDI" you have to accommodate the sequence, thus the output goes from 1 to 3 for the initial increase, becase in order to then decrease, and also only have the digits ’123’, we need 3 for the second digit so the third can decrease to 2.
Take a moment to think how you might write an algorithm to solve this problem? It may be di cult to thi ...
Java Sorting CodeImplementing and testing all three sort algorithm.pdfforecastfashions
Java Sorting Code
Implementing and testing all three sort algorithms: Bubble Sort , Selection Sort , and Insertion
Sort . In additions, you will also be writing a driver to test the search algorithms and you will be
measuring the run times of each search. You will also be using the RunTime class that you
created for Homework 1. Finally, you will be analysing and comparing the performance of the
three sort algorithms based on the type of array that was being sorted and the run times you
computed.
Details
RunTime Class
import java.util.Arrays; public class RunTime implements RuntimeInterface { private static final
int MAX = 10; private long[] runtimes; private int count; public RunTime() { this.runtimes =
new long[MAX]; this.count += 0; } @Override public void addRuntime(long runTime) { if
(this.count == MAX) { for (int i = 0; i < (MAX - 1); i++) { this.runtimes[i] = this.runtimes[i +
1]; } this.runtimes[MAX - 1] = runTime; } else { this.runtimes[count] = runTime; this.count +=
1; } } @Override public double getAverageRunTime() { double sum = 0; for (int i = 0; i <
this.count; i++) { sum += this.runtimes[i]; } return (sum / this.count); } @Override public long
getLastRunTime() { return this.runtimes[this.count - 1]; } @Override public long[]
getRunTimes() { return Arrays.copyOf(this.runtimes, this.count); } @Override public void
resetRunTimes() { for (int i = 0; i < MAX; i++) { this.runtimes[i] = 0; } } } BubbleSort Class
You will write the BubbleSort.java class which will inherit from RunTime.java and implement
the Sort Interface using the Bubble Sort algorithm. The interface may be downloaded from
SortInterface.java Please note that your sort method must measure the run time and add it to the
RunTime class by using the addRunTime() method. Sort Interface /** * * This interface will be
used by various classes to sort an array Integer objects. * You will write three classes that
implement this interface: * *
*
BubbleSort
*
InsertionSort
*
SelectionSort
*
* * @author Sameh A. Fakhouri * */ public interface SortInterface { /** * * This method is
called to sort the given array of Integer objects. At the * completion of this method, the array will
be sorted. * * @param arrayToSort This is the array that contains all the Integer objects * that
need to be sorted. */ public void sort(Integer[] arrayToSort); } SelectionSort Class You will
write the SelectionSort.java class which will inherit from RunTime.java and implement the Sort
Interface using the Selection Sort algorithm. The interface may be downloaded from
SortInterface.java Please note that your sort method must measure the run time and add it to the
RunTime class by using the addRunTime() method. InsertionSort Class You will write the
InsertionSort.java class which will inherit from RunTime.java and implement the Sort Interface
using the Insertion Sort algorithm. The interface may be downloaded from SortInterface.java
Please note that your sort method must measure the run time and add it to th.
Pluto has been hard to measure from Earth because of its atmosphere. .pdfinfo309708
Pluto has been hard to measure from Earth because of its atmosphere. In 2007 Young, Young,
and Buie measured Pluto as having a diameter of 2322 km. The New Horizons probe traveled to
Pluto and measured it up close and we now know the actual size is 2372 km. What was the
percent error of the 2007 measurement?
Solution
Percentage error: (2372-2322)*100/2372 % = 2.108%.
Loops and ArraysObjectivesArrays are a series of elements consi.pdfinfo309708
Loops and Arrays
Objectives:
Arrays are a series of elements consisting of the same type (For ex: all integers), in a contiguous
chunk of memory. The elements can be individually referenced by indexing the array.
You must specify the type of data stored in an array, and each element in any array must be of
the same type.
An array has a static size -- they cannot grow any larger than the size you tell it to be when you
create it.
To access the value at that index of the array: for (int i = 0; i < 10; i++){
cout<< intArray[i]<< endl; }
To access the memory address of the array element: for (int i = 0; i < 10; i++){
cout << intArray + i << endl; }
Creating an Array and Initializing
When you declare an array, you will get an uninitialized section of memory. If you want to
create an array of numbers, you would do:
int intNumbers [10];
double dblNumbers[10];
Then, putting element in the array can be set up by using the index of the array element you want
to change:
intNumbers[0] = 3; intNumbers[1] = 5; intNumbers[2] = 6; intNumbers[3] = 8;
1. Write a program that uses a for loop.
2. Declare and initialize and array.
3. Practice the array operations print and modify.
When you create an array, you do so to capture a group of items that all need to be treated
separately, but also need to grouped together for some purpose. For example, when you think
about a song, each note in the song is a separate sound, but they all need to be included together
in a certain order to make up the song.
To initialize the array:
int intNum [5] = {16, 3, 20, 4, 21}; (Hint: notice the syntax difference initializing this array
versus the one above)
Retrieving/Adding/Changing elements
To access or retrieve individual elements in an array, the syntax is square brackets and the
element index (starting from 0):
intNumbers[0]; will be the first item in the intNumbers array. intNumbers[1]; will be the second
item in the intNumbers array.
Below is an example of a basic 2D array. It shows how we access certain elements shown in the
arrayName[row][column] format. This will be helpful for a future assignment.
We can change the values in the array using the index of the individual items, such as
Example 1:
int intNumbers[2];
intNumbers[0] = 5;
intNumbers[1] = 7;
intNumbers[1] = intNumbers[1] * 2 cout << intNumbers[1] << endl;
Example 2:
//this will print the value 14
intNumber[1] = 10;
Example 3:
for (int i = 0; i < 10; i++){
intArray[i] = i;
cout << intArray[i] << endl;
//this will update the value to 10 at that index
//will set what the values are in that position //will print out the value of i at each index
}
TO DO: Create an array in your main function
1) Create an array of 20 doubles, using a variable name of your choosing. Assign values to your
array using a for loop:
for (int i = 0; i < 20; i++) myDoubles[i] = i;
where myDoubles is the name of the variable created.
2) Print out the values in another for loop using: cout << “Stuff to print” << endl;
3) Now, using your array an.
More Related Content
Similar to Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdffirstchoiceajmer
Everything needs to be according to the instructions, thank you!
SUPPORTING CODE:
MyList.java
/**
This interface specifies the basic operations of any list-like object.
This interface contains a variation of the methods of the
standard java.util.List interface.
*/
public interface MyList {
/**
Adds an element at the end of the list.
*/
public void addToEnd(Object o);
/**
Inserts an element at the specified index
Throws NoSuchElementException if index is out of bounds.
*/
public void insertAt(int index, Object o);
/**
Removes the element at the specified index
Throws NoSuchElementException if index is out of bounds.
*/
public void removeAt(int index);
/**
Returns the element at the specified index
Throws NoSuchElementException if index is out of bounds.
*/
public Object getAt(int index);
/**
Returns the size of the list.
@return the number of elements in the list
*/
public int getSize();
/**
Returns a list iterator for this list.
@return a list iterator for this list
*/
public MyListIterator getIterator();
}
MyListIterator.java
/**
A list iterator allows access of a position in a list.
This interface contains a subset of the methods of the
standard java.util.ListIterator interface. The methods for
backward traversal are not included.
*/
public interface MyListIterator
{
/**
Moves the iterator past the next element.
@return the traversed element
*/
Object next();
/**
Tests if there is an element after the iterator
position.
@return true if there is an element after the iterator
position
*/
boolean hasNext();
}
Main.java
// you may use this file to write and run code to test your MyArrayList class
public class Main {
public static void main(String[] args) {
}
}
FILE THAT NEEDS THAT NEEDS CODE:
MyArrayList.java
// Complete the implementation of your MyArrayList class in this file
public class MyArrayList implements MyList {
// Implement the required fields and methods here
private int capacity = 8;
private Object[ ] array = new Object [capacity];
private int size = 0;
@Override
public void add(Object o) {
if (size >= capacity){
Object[] temp = new Object[2*array.length];
for(int i=0;i<size;++i){
temp[i] = array[i];
}
this.capacity = 2*array.length;
array = temp;
array[size++] = o;
return;
}
else
{
array[size++] = o;
}
}
@Override
public int size() {
return size;
}
@Override
public Object at(int index) {
if (index >= capacity)
return null;
else
return array[index];
}
@Override
public void insertAt(int index, Object o) {
if (index >= capacity)
return;
else
{
size++;
for (int x = size - 1; x > index; x--) {
array[x] = array[x - 1];
}
array[index] = o;
}
}
@Override
public void removeAt(int index) {
if (index >= size || size == 0)
return;
else {
Object e = array[index];
for (int x = index; x < this.array.length - 1; x++) {
array[x] = array[x + 1];
}
size--;
}
}
public void ensureCapacity(int minCapacity) {
}
public void trimToSize() {
ensureCapacity(size);
}
// Do not alter the code below
@Override
public MyListIterator getIterator() {
return new MyA.
ObjectivesMore practice with recursion.Practice writing some tem.docxvannagoforth
Objectives
More practice with recursion.
Practice writing some template functions.
Use stack ADT to implement given algorithms.
Look at some common applications of stacks.Description
In this assignment, you will be using the Stack abstract data type we developed this week and discussed in our weeks lectures, to implement 4 functions that use a stack data type to accomplish their algorithms. The functions range from relatively simple, straight forward use of a stack, to a bit more complex. But in all 4 cases, you should only need to use the abstract stack interface functions push(), pop(), top(), and isEmpty() in order to successfully use our Stack type for this assignment and the function you are asked to write.
For this assignment you need to perform the following tasks.
1. In the rst task, we will write a function that will check if a string of parenthesis is matching. Strings will be given to the function of the format "(()((())))", using only opening "(" and closing ")". Your function should be named doParenthesisMatch(). It takes a single string as input, and it returns a boolean result of true if the parenthesis match, and false otherwise.
The algorithm to check for matching parenthesis using a stack is fairly simple. A pseudo-code description migth be
for each charcter c in expression do
if c is an open paren ’(’ push it on stack
if c is a close paren ’)’:
do
if stack is empty
answer is false, because we can’t match the current ’)’
else pop stack, because we just matched an open ’(’ with a close ’)’
done
done
Your function will be given a C++ string class as input. It is relatively simple to parse each character of a C++ string. Here is an example for loop to do this:
s = "(())";
for (size_t index = 0; index < s.length(); index++)
{ char c = s[index];
// handle char c of the string expression s here }
2. In the next task, we will also write a function that decodes a string expression. Given a sequence consisting of ’I’ and ’D’ characters, where ’I’ denotes increasing and ’D’ denotes decreasing, decode the given sequence to construct a "minimum number" without repeated digits.
An example of some inputs and outputs will make it clear what is meant by a "minimal number".
sequence
output
IIII
->
12345
DDDD
->
54321
ID
->
132
IDIDII
->
1325467
IIDDIDID
->
125437698
If you are given 4 characters in the input sequence, the result will be a number with 5 characters, and further only the digits ’12345’ would be in the "minimal number" output. Each ’I’ and ’D’ in the input denotes that the next digit in the output should go up (increase) or go down (decrease) respectively. As you can see for the input sequence "IDI" you have to accommodate the sequence, thus the output goes from 1 to 3 for the initial increase, becase in order to then decrease, and also only have the digits ’123’, we need 3 for the second digit so the third can decrease to 2.
Take a moment to think how you might write an algorithm to solve this problem? It may be di cult to thi ...
Java Sorting CodeImplementing and testing all three sort algorithm.pdfforecastfashions
Java Sorting Code
Implementing and testing all three sort algorithms: Bubble Sort , Selection Sort , and Insertion
Sort . In additions, you will also be writing a driver to test the search algorithms and you will be
measuring the run times of each search. You will also be using the RunTime class that you
created for Homework 1. Finally, you will be analysing and comparing the performance of the
three sort algorithms based on the type of array that was being sorted and the run times you
computed.
Details
RunTime Class
import java.util.Arrays; public class RunTime implements RuntimeInterface { private static final
int MAX = 10; private long[] runtimes; private int count; public RunTime() { this.runtimes =
new long[MAX]; this.count += 0; } @Override public void addRuntime(long runTime) { if
(this.count == MAX) { for (int i = 0; i < (MAX - 1); i++) { this.runtimes[i] = this.runtimes[i +
1]; } this.runtimes[MAX - 1] = runTime; } else { this.runtimes[count] = runTime; this.count +=
1; } } @Override public double getAverageRunTime() { double sum = 0; for (int i = 0; i <
this.count; i++) { sum += this.runtimes[i]; } return (sum / this.count); } @Override public long
getLastRunTime() { return this.runtimes[this.count - 1]; } @Override public long[]
getRunTimes() { return Arrays.copyOf(this.runtimes, this.count); } @Override public void
resetRunTimes() { for (int i = 0; i < MAX; i++) { this.runtimes[i] = 0; } } } BubbleSort Class
You will write the BubbleSort.java class which will inherit from RunTime.java and implement
the Sort Interface using the Bubble Sort algorithm. The interface may be downloaded from
SortInterface.java Please note that your sort method must measure the run time and add it to the
RunTime class by using the addRunTime() method. Sort Interface /** * * This interface will be
used by various classes to sort an array Integer objects. * You will write three classes that
implement this interface: * *
*
BubbleSort
*
InsertionSort
*
SelectionSort
*
* * @author Sameh A. Fakhouri * */ public interface SortInterface { /** * * This method is
called to sort the given array of Integer objects. At the * completion of this method, the array will
be sorted. * * @param arrayToSort This is the array that contains all the Integer objects * that
need to be sorted. */ public void sort(Integer[] arrayToSort); } SelectionSort Class You will
write the SelectionSort.java class which will inherit from RunTime.java and implement the Sort
Interface using the Selection Sort algorithm. The interface may be downloaded from
SortInterface.java Please note that your sort method must measure the run time and add it to the
RunTime class by using the addRunTime() method. InsertionSort Class You will write the
InsertionSort.java class which will inherit from RunTime.java and implement the Sort Interface
using the Insertion Sort algorithm. The interface may be downloaded from SortInterface.java
Please note that your sort method must measure the run time and add it to th.
Pluto has been hard to measure from Earth because of its atmosphere. .pdfinfo309708
Pluto has been hard to measure from Earth because of its atmosphere. In 2007 Young, Young,
and Buie measured Pluto as having a diameter of 2322 km. The New Horizons probe traveled to
Pluto and measured it up close and we now know the actual size is 2372 km. What was the
percent error of the 2007 measurement?
Solution
Percentage error: (2372-2322)*100/2372 % = 2.108%.
Loops and ArraysObjectivesArrays are a series of elements consi.pdfinfo309708
Loops and Arrays
Objectives:
Arrays are a series of elements consisting of the same type (For ex: all integers), in a contiguous
chunk of memory. The elements can be individually referenced by indexing the array.
You must specify the type of data stored in an array, and each element in any array must be of
the same type.
An array has a static size -- they cannot grow any larger than the size you tell it to be when you
create it.
To access the value at that index of the array: for (int i = 0; i < 10; i++){
cout<< intArray[i]<< endl; }
To access the memory address of the array element: for (int i = 0; i < 10; i++){
cout << intArray + i << endl; }
Creating an Array and Initializing
When you declare an array, you will get an uninitialized section of memory. If you want to
create an array of numbers, you would do:
int intNumbers [10];
double dblNumbers[10];
Then, putting element in the array can be set up by using the index of the array element you want
to change:
intNumbers[0] = 3; intNumbers[1] = 5; intNumbers[2] = 6; intNumbers[3] = 8;
1. Write a program that uses a for loop.
2. Declare and initialize and array.
3. Practice the array operations print and modify.
When you create an array, you do so to capture a group of items that all need to be treated
separately, but also need to grouped together for some purpose. For example, when you think
about a song, each note in the song is a separate sound, but they all need to be included together
in a certain order to make up the song.
To initialize the array:
int intNum [5] = {16, 3, 20, 4, 21}; (Hint: notice the syntax difference initializing this array
versus the one above)
Retrieving/Adding/Changing elements
To access or retrieve individual elements in an array, the syntax is square brackets and the
element index (starting from 0):
intNumbers[0]; will be the first item in the intNumbers array. intNumbers[1]; will be the second
item in the intNumbers array.
Below is an example of a basic 2D array. It shows how we access certain elements shown in the
arrayName[row][column] format. This will be helpful for a future assignment.
We can change the values in the array using the index of the individual items, such as
Example 1:
int intNumbers[2];
intNumbers[0] = 5;
intNumbers[1] = 7;
intNumbers[1] = intNumbers[1] * 2 cout << intNumbers[1] << endl;
Example 2:
//this will print the value 14
intNumber[1] = 10;
Example 3:
for (int i = 0; i < 10; i++){
intArray[i] = i;
cout << intArray[i] << endl;
//this will update the value to 10 at that index
//will set what the values are in that position //will print out the value of i at each index
}
TO DO: Create an array in your main function
1) Create an array of 20 doubles, using a variable name of your choosing. Assign values to your
array using a for loop:
for (int i = 0; i < 20; i++) myDoubles[i] = i;
where myDoubles is the name of the variable created.
2) Print out the values in another for loop using: cout << “Stuff to print” << endl;
3) Now, using your array an.
Modern Database Management 11th Edition by Jeffrey A. HofferUse th.pdfinfo309708
Modern Database Management 11th Edition by Jeffrey A. Hoffer
Use the UNION statement to provide a combined listing of care center names and their locations
as well as laboratories and their location. The list should be sorted by location, in ascending
order. (You should use aliases to rename the fields in this query.)
Please provide results!
Solution
The UNION operator is used to combine the result-set of two or more SELECT statements.The
UNION operator selects only distinct values by default. To allow duplicate values, use the ALL
keyword with UNION.
Syntax:
SELECT column_name(s) FROM table1
UNION ALL
SELECT column_name(s) FROM table2;
Now Let us consider that there are two tables namely care_center_t and laboratory_t where the
care_center_t contains rows like care_center name ,location1 and the laboratory_t consists of
rows such as laboratories and Locations2.
SELECT operator is used in selecting of particular rows from the table. So, now we select rows
namely care_center_name and location1 from care_center_t table and Loboratories and location2
from laboratory_t table.
The Database Query for the above problem is
SELECT care_center_name as name,location1 as location from care_center_t
UNION all
Select laboratory as name ,location2 as location from laboratory_t.
Let f X Y be a function.True or FalseA sufficient condition for f .pdfinfo309708
Let f: X Y be a function.True or False?A sufficient condition for f to be one-to-one is that for all
elements y in Ym there is at most one x in X with f(x)= y.
Solution
true.
A function f from X to Y is called one-to-one (or 1-1) if whenever
f (x) = f (y) then x = y.
No element of Y is the image of more than one element in X.
that is one-one function has an inverse that is also a function..
Its your third week on the job at Panache Inc. Last week, you made.pdfinfo309708
It\'s your third week on the job at Panache Inc. Last week, you made sure all investment
transactions for trading, available-for-sale, held-to-maturity, and equity securities were properly
recorded. You are reviewing the financial statement reporting for the securities and have found a
newspaper clipping dated December 31 that indicates the price of the stock of Omni company
had dropped the day before because of the company\'s severe financial difficulties. While the
company is not expected to fail, the article states the earnings of the company have permanently
declined due to changes in the new-homes market. You do a quick check of the stock price on
that day and find that the stock closed at $8 per share. Panache owns 10,000 shares of Omni\'s
stock as an available-for-sale security. The original cost of the stock was $20 per share, and the
fair value at the last reporting date (September 30, 2016) was $15 per share. You have just begun
to write a memo to the president of the company, Mr. Cartwright, about this investment when he
stops by your office and says, \"I have a question for you.\" He says, \"As you know, we use a
special metal called tellurium in our cars. It takes 10 pounds for each car we build. I had a
feeling last summer that tellurium prices were going to go up in October, so Mr. Brown told me
he could lock the prices in by using a dirigible. Did he do that?\" \"It was probably a derivative,
Mr. Cartwright,\" you reply. \"Let me look through the files and see what I can find, and I\'ll get
back to you. I\'ll include my findings in the memo I\'m writing to you about another
investment.\" You locate a file labeled tellurium futures, and inside you find several documents.
The first one is a handwritten note dated August 31, 2015, that says: Agreed to tellurium futures
contract expiring December 31, 2015; agreement gives Panache the right to purchase 2,000
pounds of tellurium at a price of $500 per pound. Signed, C. Brown 8/31/2015. The second paper
is a schedule showing prices of tellurium: Date Price 8/31/2015 $500 9/30/2015 $530
10/31/2015 $550 The third document is an invoice for the purchase of 2,000 pounds of tellurium
on October 31 at $550 per pound. There is a note on the invoice in Ms. Brown\'s handwriting
that says: Settled futures contract today. C. Brown 10/31/2015. You know that tellurium
purchased in October would have been used to produce the 200 cars made in November. The
cars produced in November were sold in December for $15,000 each. The total cost to produce
the cars was $12,000 each. You are required to: Prepare all journal entries that should have been
recorded related to the futures contract, including any entries needed for the September 30, 2016,
financial statements; the purchase of the tellurium; and the sale of the cars in December. Create
the journal entries in an Excel spreadsheet. Write a 2-page memo to Mr. Cartwright that
includes: A discussion of the investment in Omni company stock and the requir.
In JAVA Write a program that uses a two-dimensional array to sto.pdfinfo309708
In JAVA
Write a program that uses a two-dimensional array to store the highest and lowest temperatures
for each month of the year. The program should output the average high, average low, and
highest and lowest temperatures of the year. Your program must consist of the following
methods:
a. Method getData: This method reads and stores the data in the two-dimensional array.
b. Method averageHigh: This method calculates and returns the average high temperature of the
year.
c. Method averageLow: This method calculates and returns the average low temperature of the
year.
d. Method indexHighTemp: This method returns the index of the highest temperature in the
array.
e. Method indexLowTemp: This method returns the index of the lowest temperature in the array.
(These methods must all have the appropriate parameters.)
Solution
CODE
package test;
import java.util.Scanner;
public class Temperatures {
//declaring temperatures as a static array
public static double[][] temperatures = new double[12][2];
public static void main(String[] args) {
getData();
System.out.println(\"Average high is : \"+averageHigh());
System.out.println(\"Average low is : \"+averageLow());
System.out.println(\"Month of highest temperature is : \"+indexHighTemp());
System.out.println(\"Month of lowest temperature is : \"+indexLowTemp());
}
//to get data of temperatures for all months from user
public static void getData() {
System.out.println(\"Enter details\");
Scanner in = new Scanner(System.in);
for (int i = 0; i < 12; i++) {
System.out.println(\"Enter highest temperature for month \" + (i + 1));
temperatures[i][0] = in.nextDouble();
System.out.println(\"Enter lowest temperature for month \" + (i + 1));
temperatures[i][1] = in.nextDouble();
}
}
//to get avegare of highest temperatures of all months
public static double averageHigh() {
double avg = 0;
for (int i = 0; i < 12; i++) {
avg += temperatures[i][0];
}
return avg / 12;
}
//to get sverage of lowest temperatures of all months
public static double averageLow() {
double avg = 0;
for (int i = 0; i < 12; i++) {
avg += temperatures[i][1];
}
return avg / 12;
}
//to get index of highest tempeartures of all months
public static int indexHighTemp() {
int index = 0;
double max = Double.MIN_VALUE;
for (int i = 0; i < 12; i++)
if (temperatures[i][0] > max)
{
index = i;
max =temperatures[i][0];
}
return index+1;
}
//to get index of lowest tempeartures of all months
public static int indexLowTemp() {
int index = 0;
double min = Double.MAX_VALUE;
for (int i = 0; i < 12; i++)
if (temperatures[i][1] < min)
{
index = i;
min = temperatures[i][1];
}
return index+1;
}
}
SAMPLE OUTPUT
Enter details
Enter highest temperature for month 1
60
Enter lowest temperature for month 1
50
Enter highest temperature for month 2
50
Enter lowest temperature for month 2
40
Enter highest temperature for month 3
40
Enter lowest temperature for month 3
30
Enter highest temperature for month 4
30
Enter lowest temperature for month 4
20
Enter highest temperature f.
How do CCMI model help with the improvements and comparison of the p.pdfinfo309708
How do CCMI model help with the improvements and comparison of the process life cycle?
Solution
CCMI: Capability improvement model integration which is a method of improvement model
which includes the top perfomances advanced in improvement of software,acquired from
industry .CMMI isolates the top perfomance knowledge to discrete levels ,and every level
advances to elevated level.each and every level inscribe growth and nurture of the life cycle.
CMMI is uniquely applied to software evolution organisations and focus on uniterrupted
improvement..
How would you implement a node classs and an edge class to create .pdfinfo309708
How would you implement a node classs and an edge class to create a undirected and a directed
graph using c++
Please provide a default constructor, copy constructor, accessing functions , and destructor for
each of the classes to print out a graph
( node, edge , directed ,undirected )
V={1,3,3,4,5,6}
E={(1,2),(1,4),(2,3),(2,4),(2,5),(3,4),(5,3),(6,3),(6,5)}
How would you implement a node classs and an edge class to create a undirected and a directed
graph using c++
Please provide a default constructor, copy constructor, accessing functions , and destructor for
each of the classes to print out a graph
( node, edge , directed ,undirected )
V={1,3,3,4,5,6}
E={(1,2),(1,4),(2,3),(2,4),(2,5),(3,4),(5,3),(6,3),(6,5)}
Please provide a default constructor, copy constructor, accessing functions , and destructor for
each of the classes to print out a graph
( node, edge , directed ,undirected )
V={1,3,3,4,5,6}
E={(1,2),(1,4),(2,3),(2,4),(2,5),(3,4),(5,3),(6,3),(6,5)}
Solution
#include
#include
#include
#include
#include
using namespace std;
class Graph;
class Edge;
class Vertex;
class Edge {
int weight;
Vertex * vertex1;
Vertex * vertex2;
public:
int getWeight() const {return weight;}
Vertex* getV1() const {return vertex1;}
Vertex* getV2() const {return vertex2;}
void setWeight(int w){weight=w;}
void setV1(Vertex * v){vertex1=v;}
void setV2(Vertex * v){vertex2=v;}
Edge(int w, Vertex* v1, Vertex* v2){weight=w;vertex1=v1;vertex2=v2;}
};
class Vertex {
string label;
vector edgesLeavingMe;
bool visited;
public:
string getLabel() const {return label;}
vector getEdges()const{return edgesLeavingMe;}
Edge * getEdgeTo(string d){
for (vector::iterator it = edgesLeavingMe.begin(); it != edgesLeavingMe.end(); ++it){
if ((*it)->getV2()->getLabel()==d){
return (*it);
}
}
return 0;
}
void setVisited(bool v){visited=v;}
bool getVisited() {return visited;}
void addEdge(Edge * e){edgesLeavingMe.push_back(e);}
void removeEdge(Edge *
e){edgesLeavingMe.erase(remove(edgesLeavingMe.begin(),edgesLeavingMe.end(),e),edgesLea
vingMe.end());}
void removeEdgeTo(string l){
Edge * e = getEdgeTo(l);
removeEdge(e);
}
Vertex(string l){label=l; visited=false;}
};
class Graph {
vector edges;
map vertices;
public:
Vertex * addVertex(string label){
Vertex * v = new Vertex(label);
vertices[label]=v;
return v;
}
Edge * addEdge(int w, string from, string to);
void removeEdge(string from, string to);
Vertex * getVertexWithlabel(string l);
void removeVertex(string l);
};
class UnDirectedGraph {
vector edges;
map vertices;
public:
Vertex * addVertex(string label){
Vertex * v = new Vertex(label);
vertices[label]=v;
return v;
}
map getVertices(){return vertices;}
vector getEdges(){return edges;}
Edge * addEdge(int w, string from, string to){
if (vertices.find(from) != vertices.end() && vertices.find(to) != vertices.end()){
Vertex * vfrom = vertices.find(from)->second;
Vertex * vto = vertices.find(to)->second;
Edge * e = new Edge(w,vfrom,vto);
(*vfrom).addEdge(e);
(*vto).addEdge(e);
edges.push_back(e.
How do you evaluate your own global mind set levelsSolutionAN.pdfinfo309708
How do you evaluate your own global mind set levels?
Solution
ANSWER:
A global mindset is refers to a special trait of global leadership which is associated with
manager-employee relationship, trust, and organizational commitment. There are prime three
features of global mindset namely- intellectual capital, psychological capital and social capital.
While evaluating my own global mind set levels I have to consider all these features. Intellectual
capital is my ability to understand and process new information, which are helpful to learn about
people of different cultures and know how to respond. Psychological capital, is evaluating my
openness, cognitive flexibility and willingness to work with other cultures. Social capital is the
relationships network that I have with their colleagues from different cultures, and can help me
to act in a trustworthy manner and build relationship with others from different cultures. The
development of a global mindset that sub-includes cultural intelligence and global business
orientation will help me to think globally and swiftly act to maintain the competitiveness in
multicultural organizations and international markets. Keeping all these above points, I can
properly designed questionnaire survey can be of useful in global mindset evaluation for me as
well as others. My global mindset affects the cognitive capabilities and the decision-making
patterns, thus exerting significant influence on the strategic capabilities of firms as well as my
personal life..
Here are two datasetsDataset A 64 65 66 68 70 71 72Dataset B .pdfinfo309708
Here are two datasets:
Dataset A: 64 65 66 68 70 71 72
Dataset B: 64 65 66 68 70 71 720
For dataset A, the mean and median are 68. Looking at dataset B, notice that all of the
observations except the last one are close together. Which measure will be affected by this last
observation in dataset B?
Mean
or
Median
Solution
Data set B: Mean will be affected since we have outlier(720) in the data hence we know that
outlers are very much affected by mean . But no affect on the Median.
For this homework, you will develop a class called VendingMachine th.pdfinfo309708
For this homework, you will develop a class called VendingMachine that simulates an imaginary
vending machine at CSUMB. In the program, a user can buy a bottle of water ($1.50), a coffee
($2.00), a bag of chips ($1.00),
and a chocolate bar ($2.50) from the machine. The user can buy several items if they are
available
in the machine. For the payment, a user can use only cash (including coins). Additionally, an
administrator of the machine can reset or refill the machine.
1 Demo Program
The following code presents a demo program that uses the VendingMachine class.
public class VendingMachineDemo {
public static void main(String[] args) {
VendingMachine machine1 = new VendingMachine(100);
VendingMachine machine2 = new VendingMachine(200, \"Library\");
System.out.println(\"===== Welcome to the CSUMB Vending Machine =====\");
System.out.println(machine1);
System.out.println(\"\");
System.out.println(machine2);
System.out.println(\"\ === Compare Two Machines ===\");
System.out.println(machine1.equals(machine2));
machine1.setLocation(\"BIT104\");
machine1.setName(50);
machine1.setName(100);
System.out.println(\"\ === Machine Reset ===\");
machine1.reset(4, 5, 0, 6); // In this method, we assume that a machine
// administrator resets the contents of
// a machine.
machine1.addItems(1,2,3,4); // A system admin can add items to the machine
System.out.println(machine1);
System.out.println(\"\");
machine1.displayMenu();
System.out.println(\"\ === Buy an Item ===\");
machine1.buyItem();
System.out.println(\"\ === Buy another Item ===\");
1
if(machine1.buyItem(1, 4) == false) {
System.exit(1);
}
System.out.println(\"\ === Return Two Items ===\");
machine1.returned(1, 2);
machine1.returned(2, 3);
System.out.println(\"\ === Buy another Item ===\");
machine1.buyItem(3, 5);
System.out.println(\"\ === Pay for items selected. ===\");
if(machine1.payment()) {
System.out.println(\"\ === Valid payment. ===\");
machine1.displayReceipt();
} else {
System.out.println(\"\ === Invalid payment. Try one more time. ===\");
if(machine1.payment()) {
System.out.println(\"\ === Print Receipt ===\");
machine1.displayReceipt();
} else {
System.exit(1);
}
}
machine1.addItems(5,5,5,5);
System.out.println(\"\ === Machine Status ===\");
machine1.status();
System.out.println(\"\ ===== Thank you! =====\");
}
}
Sample Run of the Demo Program: The following presents a sample result of the demo
program.
Read the result very carefully to identify the operations of the program.
===== Welcome to the CSUMB Vending Machine =====
Serial Number: 100
Location: UNKNOWN
Contents:
Water: 0
Coffee: 0
Sun Chips: 0
Chocolate Bar: 0
Serial Number: 200
Location: Library
Contents:
Water: 0
Coffee: 0
Sun Chips: 0
2
Chocolate Bar: 0
=== Compare Two Machines ===
false
=== Machine Reset ===
Serial Number: 100
Location: BIT104
Contents:
Water: 5
Coffee: 7
Sun Chips: 3
Chocolate Bar: 10
===== Vending Machine Menu =====
1. Water............$1.50
2. Regular Coffee...$2.00
3. Sun Chips........$1.00
4. Chocolate Ba.
Discuss what is SSH and the advantages and disadvantages of using it.pdfinfo309708
Discuss what is SSH and the advantages and disadvantages of using it on your Linux
distribution.
Also discuss how to control ssh access and how you configure this service.
Solution
SSH is also known as Secure Socket Shell. It is a network protocol that provides administrators
with a secure way to access a remote computer.
For advantages of it, SSH is widely used by network administrators for managing systems and
applications remotely. It allows them to log in to another computer over a network, execute
commands and move files from one computer to another.
The biggest disadvantage would be people logging in as the computer\'s administrator over SSH
and this can be done by brute force for the password.
To limit ssh access to a linux machine based on originating IP address, edit /etc/hosts.allow:.
Describe the differences between the three major physical connection .pdfinfo309708
Describe the differences between the three major physical connection mediums: twisted-pair
cable, coaxial cable, and fiber-optic cable.
Solution
Below is the Difference Between Fiber Optic Cable, Twisted Pair and coaxial Cable :
Twisted Pair Cables
Twisted pair cable consists of a pair of insulated wires twisted together, which is adapted in the
field of telecommunication for a long time. With the cable twisting together, it helps to reduce
noise from outside sources and crosstalk on multi-pair cables. Twisted pair cable works well on
transferring balanced differential signals, the merits of which are extremely valuable in wide
bandwidth and high fidelity system. Basically, twisted pair cable can be divided into two types:
unshielded twisted-pair (UTP) and shielded twisted-pair (STP). The former serves as the most
commonly used one with merely two insulated wires twisted together. Any data communication
cables and normal telephone cables belong to this category. However, shielded twisted pair
distinguishes itself from UTP in that it consists of a foil jacket which helps to prevent crosstalk
and noise from outside source. It is typically used to eliminate inductive and capacitive coupling,
so it can be applied between equipment, racks and buildings. With the advancement of
technology, the twisted pair cables are now being phased out by more technically developed and
reliable media.
Coaxial Cables
Coaxial cable acts as a high-frequency transmission cable which contains a single solid-copper
core. A coaxial cable has over 80 times the transmission capability of the twisted-pair. It is
commonly used to deliver television signals and to connect computers in a network as well, so
people may get more familiar with this kind of cable. Coaxial cable has always been the
mainstay of high speed communication and has also been applied to network with 10 gigabit
links data centers, because it is proved to be cost efficient for short links within 10 m and for
residential network. Besides, it features anti-jamming capability, stable transmission of data and
money saving. Coaxial cable is widely employed in feedlines connecting radio transmitters and
receivers, computer network connection, digital audio and television signals distribution.
Moreover, coaxial cable can effectively protect signals from being interfered by external
electromagnetic influence.
Fiber Optic Cables
Computing and data communications are fast-moving technologies. There comes a new
generation of transmission media—fiber optic cable. It refers to the complete assembly of fibers,
which contain one or more optical fibers that are used to transmit data. Each of the optical fiber
elements is individually coated by plastic layers and contained in a protective tube. Fiber optic
cable transmits data as pulses of light go through tiny tubes of glass, the transmission capacity of
which is 26,000 times higher than that of twisted-pair cable. When comparing with coaxial
cables, fiber optic cables ar.
Create a student record management system using linked list and queu.pdfinfo309708
Create a student record management system using linked list and queue using Java language and
database to save files and GUI Java swing to create background and also use HTML.
With the following properties
A . register students(assume each students has ID, first name ,last name and middle name)
B.register students with courses(course no ,course title crh)
C.able to maintain grade on which course they are registered
d.searches students by ID displays if found
E.searches by course name
F. sorts student name in alphabetical order
G.displays the details of all students
H.Deletes a student by id
I.Deletes a course by courseNo
J. Handles errors in informative ways .
Solution
public class StudentRegistration extends JFrame implements ActionListener{
JLabel idLabel, fnameLabel, midnameLabel, lastnameLabel, courseLabel;
JTextField idField, fnameField, midnameField, lastnameField, courseField;
JButton registerButton;
JPanel panel;
List list = new ArrayList();
StudentRegistration() {
setSize(800, 400);
setLayout(null);
idLabel = new JLabel(\"ID\");
fnameLabel = new JLabel(\"First Name\");
midnameLabel = new JLabel(\"Mid Name\");
lastnameLabel = new JLabel(\"Last Name\");
courseLabel = new JLabel(\"Course\");
// Defining ID field
idField = new JTextField();
idField.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
}
});
// Defining Name field
fnameField = new JTextField();
fnameField.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
}
});
registerButton
= new JButton(\"Register\");
registerButton.addActionListener(this);
add(idLabel);
add(fnameLabel);
add(midnameLabel);
add(lastnameLabel);
add(courseLabel);
add(idField);
add(fnameField);
add(midnameField);
add(lastnameField);
add(courseField);
add(registerButton);
list.add(new User(idField.getText(), fnameField.getText(),midnameField.getText(),
lastnameField.getText(),courseField.getText()));
saveValues();
JOptionPane.showMessageDialog(this,
\"Student Successfully Registered\");
}
}
public void saveValues() throws SQLException {
User str = list.get(list.size()-1);
Connection connection = null;
Class.forName(\"com.mysql.jdbc.Driver\");
String url = \"jdbc:mysql://localhost/testdb\";
String user = \"root\";
String password = \"\";
connection = DriverManager.getConnection(url,
user, password);
Statement stmt = connection.createStatement();
String sql = \"INSERT INTO students(str.fname,str.midname,str.lastname,str.course) \";
stmt.execute(sql);
}
public static void
main(String[] args) {
new StudentRegistration();
}
}.
Coca-Cola companyStrategic Goals and Objectivesi. Objectives are.pdfinfo309708
Coca-Cola company
Strategic Goals and Objectives
i. Objectives are the specific, measurable steps that will help you achieve your mission. Develop
objectives that are SMART: specific, measurable, achievable (eventually), relevant to your
mission, and timed (with a date for completion.).
Solution
The strategic goals and objectives to the Coca-Cola Company will be framed as,.
C programming. Answer question only in C code Ninth Deletion with B.pdfinfo309708
C programming. Answer question only in C code Ninth: Deletion with Binary Search Tree (20
points) In the ninth part, you will extend the binary search tree in the eighth part to support the
deletion of a node. The deletion of a node is slightly trickier compared to the search and insert in
the eighth The deletion is straightforward if the node to be deleted has only one child. You make
the parent of the node to be deleted point to that child. In this scenario, special attention must be
paid only when the node to be deleted is the root Deleting a node with two children requires
some more work. In this case, you must find the minimum element in the right subtree of the
node to be deleted. Then you insert that node in the place where the node to be deleted was. This
process needs to be repeated to delete the minimum node that was just moved In either case, if
the node to be deleted is the root, you must update the pointer to the root to point to the new root
node Input format: This program takes a file name as argument from the command line. The file
is either blank or contains successive lines of input. Each line contains a character, \'i or \'d\'
followed by a tab and an integer. For each line that starts with \'i\', your program should insert
that number in the binary search tree if it is not already there. If the line starts with a \'s, your
program should search for that value. If the line starts with a \'d\', your program should delete
that value from the tree output format: For each line in the input file, your program should print
the status/result of the operation. For insert and search, the output is the same as in the Eighth
Part: For an insert operation, the program should print either \"inserted\" with a single space
followed by a number the height of the inserted mode in the tree, or \"duplicate\" if the value is
already present in the tree. The height of the root node is 1. For a search, the program should
either print \"present\" followed by the height of the node, or absent\" based on the outcome of
the search. For a delete, the program should print \"success or \"fail\" based on the whether the
value was present or not. Again, as in the Eight Part, your program should print \"error\" (and
nothing else) if the file does not exist or for input lines with improper structure Example
Execution: Lets assume we have a file filel.txt with the following contents: i 5 i 3 i 4 i 1 i 6 i 2 s
1 d 3 s 2 Executing the program in the following fashion should produce the output shown
below:
Solution
// C program to demonstrate delete operation in binary search tree
#include
#include
struct node
{
int key;
struct node *left, *right;
};
// A utility function to create a new BST node
struct node *newNode(int item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
// A utility function to do inorder traversal of BST
void inorder(struct node *root)
{
if (root != NULL)
.
Biology LabThe poisonous wastes of diptheria germs are called (A).pdfinfo309708
Biology Lab:
The poisonous wastes of diptheria germs are called (A) antitoxins (B) antibodies (C) immunities
(D) toxins
Solution
Biology Lab ANS: (D) toxins
Explanation:
A toxin is a poisonous substance which produced by some bacteria or an organism
Diphtheria is mainly caused by the corynebacterium diphtheriae bacteria. It is a gram positive,
non-endospore forming, pleiomorphic bacteria.
Poisonous wastes of diptheria germs (C.diphtheriae) can produce diphtheria toxin. It causes sore
throat and fever. This toxins prevents protein synthesis and causes cell death..
Aside from the expansion of industrial capitalism, what factors affe.pdfinfo309708
Aside from the expansion of industrial capitalism, what factors affected American development
during the late 19th centry? How important are those factors in comparison to capitalism’s
growth?
Solution
ANSWER:
During the late nineteenth Americans believed for the expansion of national borders in order to
keep the America running upright. Moreover, the Americans believed that the United States was
the most powerful of nations, and that they could take any land they pleased. The expansion of
American started after the Civil War. The war made substantial use of the telegraph and
railroads. Moreover there was a crucial expansion of railroads with a motive on combing the
Atlantic and Pacific coasts, with movement.
This growing population and an advanced transportation is one of the main causes of expansions
of America in late 19th century. Europeans with surplus wealth joined Americans in investing
the economic expansion of the nation. Also the farmers during this time required arable land for
livestock and crops which was unavailable due to overcrowding. Thus financial panics uprooted
them and sent them west for a new start. Furthermore, the American government also motivated
the citizens to move west, with the motive of acquisition of new territory from foreign powers.
The above discussed factors are different from the factors in capitalism’s growth. Capitalism is a
system in an economy where private entities own the factors of production namely
entrepreneurship, natural resources, capital goods and labor; and ensures that an economy will
produce the most desired products at an acceptable price. The owners of capital goods,
entrepreneurship and natural resources exercise control through companies..
Yates (2009) notes that unions have a purpose broader than serving t.pdfinfo309708
Yates (2009) notes that unions have a purpose broader than serving their members. What
arguments does he make in that regard? What do you think of his arguments, and why?
Solution
Yates says that unions actually mean better pay, benefits, and slao working conditions for their
members and they indeed force employers to treat employees with dignity and respect; and at
their maximum best, they provide the workers to work in the society with utmost satisfaction on
the whole. Yates used simple language with suffiecient examples to tell that how unions popped
out to be helpful at certain troublesome instants on the whole. His arguments exactly carried on
to tell the importance of unions and he advises all the workers to join in the unions which would
be ultimately beneficial to them on the whole..
write a C program for blinking light using function make sure it.pdfinfo309708
write a C program for blinking light using function
** make sure it will compile
Solution
GPIO is General purpose input output it is very useful for blinking a led.
GPIO is configured with input and output. itis micro controller.
#include
/* PORT B0 is the microcontroller */
int main()
{
unsigned int signal =0;
/* Configure GPIO with input and output */
DDRB = 0x01;
while(1)
{
for (signal =0;signal <50000;signal ++)
{
PORTB = 0x00;
}
for (signal =0;signal <50000;signal ++)
{
PORTB = 0x01;
}
}
return 0;
}.
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Sectors of the Indian Economy - Class 10 Study Notes pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
1. Getting Started
Create a class called Lab8. Use the same setup for setting up your class and main method as you
did for the previous assignments. Be sure to name your file Lab8.java. Additionally, make
another file called Arrays.java. This file will be an object, so simply start it off by declaring an
Arrays class. You can copy the following skeleton and fill in the appropriate code below each of
the comments:
public class Arrays {
/ Instance Variables
// Constructors
// findMin 1
// findMax
// calcSum
// calcAverage
// toString
}
Task Overview
Your task for this lab is to create a class called Arrays with some array processing methods. This
class will maintain an array and the number of elements present in it. Additionally, methods will
be available to display the current min and max elements along with the average of all of them.
Finally, a toString() method will be available to cleanly display all the array elements. Finally,
you will write a simple driver class to test out the above Arrays class.
Part 1: Instance Variables for Arrays
The first thing to do for the Arrays class is to set up its instance variables. Declare the following
(private) instance variables:
• An int array called array ? this will be the array we will be writing methods for.
• An int called count - this represents the number of valid elements in the array.
Part 2:
Constructors for Arrays The Arrays class will have two constructors. The first constructor takes
the maximum size of the array as input as a parameter and initializes the array instance variable
appropriately. It also sets count to size. Finally, it will initialize all of the array elements to some
values between 0 and 10, inclusive. To create this constructor, follow these steps:
• Import java.util.Random to make use of the random number generator.
• Create a constructor with the following header: public Arrays(int size)
• Initialize your array variable and set its size to size (see the chart on page 252 for reference on
initializing arrays). Be very careful that you are setting the value of your array instance variable,
2. as opposed to creating a new variable called array.
• Set the value of the count variable to size because we will be populating the entire array.
• Copy the following code to the constructor in order to generate random values between 0 and
10, inclusive:
Random rand = new Random();
for (int i = 0; i < count; i++)
{
array[i] = (rand.nextInt(10));
}
Next, create another constructor with the following header: public Arrays(int[] arr). This
constructor will initialize the class by using the passed arr argument in order to fill its instance
variables. The following things need to be done inside of this constructor:
• Set the array variable equal to arr.
• Set the count variable equal to the length of the array.
Part 3: Displaying the Output findMin()
The first method of this class will search the array for the minimum element. Copy the following
code for the findMin method. Note how the count instance variable is used instead of
array.length. This is just in case the entire array is not being used (it will be in our case, though).
public int findMin()
{
int min = array[0]; // Set min to the first element for (int i = 1; i < count; i++)
{
// Reassign min if there is a smaller element
if (array[i] < min)
{ min = array[i];
}
}
return min; // Return the smallest element
}
findMax()
Using the above code as reference, write a method which finds the maximum element within the
array. You can refer to page 259 if you are stuck.
calcSum()
The calcSum() method will be a private method (for clarity, it is the only private method in this
class). It will be used later on within the class as a helper method, but never outside of the class.
This method will return the sum of all of the elements in the array. You can use the following
3. steps as guidelines for how to complete this method, if you choose:
• Use the following as the header: private int calcSum()
• Declare an int variable for the sum - initialize it to 0
• Write a for loop to iterate through all the elements in the array (remember to use the count
instance variable instead of the length of the array).
• Add the value of each element to the sum.
• Return the sum after the for loop
calcAverage()
This method will return the average of all of the elements in the array. Use the following for the
header of this method: public double calcAverage(). IMPORTANT: Use the calcSum() private
method in your computation of the average for full credit.
Hints:
• You will need to make use of the total elements in the array.
• You will need to cast the result to a double at the appropriate time to achieve an accurate
average
toString()
The toString() method is called whenever an object is passed into a print statement. This
particular toString() method will print the following, assuming the array consists of elements {1,
2, 3, 4}:
[ 1, 2, 3, 4 ]
Copy the following code to use for this method:
public String toString()
{
String output = "[ "; for (int i = 0; i < count; i++)
{
output += array[i];
if (i != count - 1)
{
output += ", ";
}
}
return output + " ]";
}
Part 4:
Test Class for Arrays At this point, the Arrays class is completed. The next step is to create a
driver class to test it. This is the Lab8.java file that you created at the beginning of the lab. Copy
4. the following code into the main method of the Lab8.java file. This code tests the first
constructor of the Arrays class along with all its methods.
// Create an Arrays object using the first constructor Arrays arr1 = new Arrays(5);
// Print the contents of the array in arr1 System.out.println(arr1);
// Call findMin, findMax, and calcAverage on arr1 and print their values
System.out.println("Min: " + arr1.findMin());
System.out.println("Max: " + arr1.findMax());
System.out.println("Average: " + arr1.calcAverage());
System.out.println();
The next step is to add code which tests the second constructor of the Arrays class. To do this,
complete the following tasks by adding code to the end of the code you just copied into the main
method.
• Create an int array of length 3 - explicitly set its values to any 3 ints by using an array
initialization list. See the chart on the bottom of page 252 for a reference on how to set an array
with initial values.
• Create an Arrays object using the second constructor. Note that this involves passing the array
variable you just created. Call this object arr2.
• Print the arr2 object by passing it into a println statement. • Print the min, max, and average of
the arr2 object, as what was done with the arr1 object.
Sample Output Below is an example of what your output should roughly look like when this lab
is completed. Please note that your values will almost certainly be different, depending both on
the random number generator and the values of the array you created in Lab8.java. The
following run initialized its array in the arr2 object to contain {1, 2, 3}.
Sample Run:
[2, 1, 8, 4, 4]
Min: 1
Max: 8
Average: 3.8
[1, 2, 3]
Min: 1
Max: 3
Average: 2.0
Solution
Arrays.java
5. import java.util.Random;
public class Arrays {
//Declaring instance variables
private int array[];
private int count;
//Parameterized constructor
public Arrays(int size) {
super();
array = new int[size];
this.count = size;
Random rand = new Random();
for (int i = 0; i < count; i++) {
array[i] = (rand.nextInt(10));
}
}
//Parameterized constructor
public Arrays(int[] arr) {
this.array = arr;
this.count = arr.length;
}
//This method will find the smallest element of an array
public int findMin() {
int min = array[0]; // Set min to the first element
for (int i = 1; i < count; i++) {
// Reassign min if there is a smaller element
if (array[i] < min) {
min = array[i];
}
}
return min; // Return the smallest element
}
//This method will find the maximum element of an array
public int findMax() {
int max = array[0]; // Set max to the first element
for (int i = 1; i < count; i++) {
6. // Reassign max if there is a smaller element
if (array[i] > max) {
max = array[i];
}
}
return max; // Return the smallest element
}
/* This method will calculate the
* sum of the elements of an array
*/
private int calcSum() {
int sum = 0;
for (int i = 0; i < count; i++) {
sum += array[i];
}
return sum;
}
/* This method will find the average
* of all the elements of an array
*/
public double calcAverage() {
return (double) (calcSum() / count);
}
public String toString() {
String output = "[ ";
for (int i = 0; i < count; i++) {
output += array[i];
if (i != count - 1) {
output += ", ";
}
}
return output + " ]";
}
}
____________________________
7. Lab8.java
public class Lab8 {
public static void main(String[] args) {
// Create an Arrays object using the first constructor
Arrays arr1 = new Arrays(5);
// Print the contents of the array in arr1
System.out.println(arr1);
// Call findMin, findMax, and calcAverage on arr1 and print their values
System.out.println("Min: " + arr1.findMin());
System.out.println("Max: " + arr1.findMax());
System.out.println("Average: " + arr1.calcAverage());
System.out.println();
int arr[] = { 1, 2, 3 };
Arrays arr2 = new Arrays(arr);
// Print the contents of the array in arr2
System.out.println(arr2);
// Call findMin, findMax, and calcAverage on arr2 and print their values
System.out.println("Min: " + arr2.findMin());
System.out.println("Max: " + arr2.findMax());
System.out.println("Average: " + arr2.calcAverage());
}
}
__________________________
Output:
[ 1, 8, 1, 5, 2 ]
Min: 1
Max: 8
Average: 3.0
[ 1, 2, 3 ]
Min: 1
Max: 3
Average: 2.0
__Thank You