Use this implementation of Integer node,
public class IntegerNode {
public int item;
public IntegerNode next;
public IntegerNode(int newItem) {
item = newItem;
next = null;
} // end constructor
public IntegerNode(int newItem, IntegerNode nextNode) {
item = newItem;
next = nextNode;
} // end constructor
} // end class IntegerNode
You need to implement add( ), delete( ), traverse( ) methods for an ordered linked list. And after insertion and deletion, your linked list will remain ordered.
Your code should include comments and documentation.
Testing
Here is the procedure for testing, which must be documented (a Word document is preferred, as is the use of screenshots).
In: Computer Science
Java OOP - how do I avoid using getter and setter method in player class for better privacy? I am told to use regular method instead. but I dont know how
Thank you
-----------------------------------------------------------------------------------------------------------
package MainPackage;
import java.util.ArrayList;
public class SoccerTeam {
private ArrayList<Player> list;
public SoccerTeam(int maxSubmission) {
list = new ArrayList<>(maxSubmission);
}
public boolean addPlayer(String newPlayer) {
if(newPlayer == null || newPlayer.isEmpty() == true) {
return false;
}
for(Player player : list) {
if(player.getName() == newPlayer) {
return false;
}
}
Player player = new Player(newPlayer);
list.add(player);
return true;
}
public int numOfTeamMembers() {
return list.size();
}
public boolean addFile(String name, int[] goal) {
boolean isPlayerPresent = false;
for(Player player : list) {
if(player.getName() == name) {
if(player.getNumOfSubmissions() <= 10) {
isPlayerPresent = true;
player.increaseNumOfSubmissions();
int goals = 0;
for(int i : goal) {
goals = goals + i;
}
if(player.getGoals() < goals ) {
player.setGoals(goals);
}
}
}
}
if(!isPlayerPresent) {
return false;
}
return true;
}
public int goals(String name) {
if(name == null || name.isEmpty() == true) {
return -1;
}
for(Player player : list) {
if(player.getName() == name) {
return player.getGoals();
}
}
return -1;
}
public int numFile(String name) {
for(Player player : list) {
if(player.getName() == name) {
return player.getNumOfSubmissions();
}
}
return -1;
}
}
public class Player {
private int numOfSubmissions;
private int goals;
private String name;
public Player(String name) {
numOfSubmissions = 0;
goals = 0;
this.name = name;
}
public int getNumOfSubmissions() {
return numOfSubmissions;
}
public void increaseNumOfSubmissions() {
this.numOfSubmissions = numOfSubmissions + 1;
}
public int getGoals() {
return goals;
}
public void setGoals(int goals) {
this.goals = goals;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
In: Computer Science
PYTHON Perform a series of benchmarking tests on merge-sort and quick-sort to determine which one is faster. Your tests should include sequences that are “random” as well as “almost” sorted.
In: Computer Science
Question 5
In one of the buildings that your company has installed a network, some of the devices have stopped working completely. The devices do not even turn on. Your manager has requested that you investigate the possible causes of the damaged devices. Advise on what can be installed so that other devices can be protected. Explain two ways to achieve this.
In: Computer Science
Consider inserting n distinct keys into a hash table with m buckets, where collisions are resolved by chaining and simple uniform hashing applies.
1. What is the probability that none of the n keys hashed to a particular bucket?
2. What is the expected number of empty buckets?
3. What is the expected number of collisions?
In: Computer Science
Please create the following tables for a tool rental database with appropriate
primary keys & foreign keys.
Assumptions:
1. Each tool belongs to a category.
2. Each category may have a parent category but the parent category should not have
a parent category (so at most two levels). E.g., a Tool A belongs to the electric mower,
and electric mowers belong to mowers. Mower has no parent category.
3. Each tool can be rented at different time units. The typical time units are hourly,
daily, and weekly. There is a different price for each time unit and tool
combination. E.g., tool A may be rented at $5 per hour, $30 per day, and $120 per
week.
4. Each customer can rent a tool for a certain number of time units. If the tool is
returned late a late fee will be charged.
The list of tables is:
Cust_Table:
cid, -- customer id
cname, --- customer name
cphone, --- customer phone
cemail, --- customer email
Category_Table:
ctid, --- category id
ctname, --- category name
parent, --- parent category id since category has a hierarchy structure, power washers,
electric power washers, gas power washers. You can assume that there are only two
levels.
Tool_Table:
tid, --- tool id
tname, --- tool name
ctid, --- category id, the bottom level.
quantity, --- number of this tools
Time_Unit_Table allowed renting unit
tuid, --- time unit id
len, --- length of period, can be 1 hour, 1 day, etc.
min_len, --- minimal #of time unit, e.g., hourly rental but minimal 4 hours.
Tool_Price:
tid, --- tool id
tuid, --- time unit id
price, -- price per period
Rental_Table:
rid, --- rental id
cid, --- customer id
tid, --- tool id
tuid, --- time unit id
num_unit, --- number of time unit of rental, e.g., if num_unit = 5 and unit is hourly, it
means 5 hours.
start_time, -- rental start time
end_time, --- suppose rental end_time
return_time, --- time to return the tool
credit_card, --- credit card number
total, --- total charge
- Insert at least three rows of data to each table. Make sure you keep the
primary key and foreign key constraints.
-Write an anonymous PL/SQL program to compute the sum of 2, 4, 6, 8, 10.
You must use a loop. Tip: consider how to update your loop variable.
- Print out the estimated charge for rental ID 1 if the customer returns the tool in
time. The charge is computed by the price in the price_tool table * number of units the
customer plans to rent. E.g., if a customer rents a tool hourly for 5 hours, and the hourly rate for the tool is $6, the estimated charge should be $30.
In: Computer Science
In: Computer Science
a) Which parts of DES uses permutation method?
b) Which parts of DES uses the substitution method?
c) Explain why DES can be invertible (verify each round is easy to inverse).
d) Does DES require that the function f is invertible? Why?
In: Computer Science
- What is the output of the following program?
StackPT stk1 = new ArrayStackPT( 10 );
StackPT stk2 = new ArrayStackPT( 10 );
StackPT stk3 = new ArrayStackPT( 10 );
StackPT stk4 = new ArrayStackPT( 10 );
QueuePT q1 = new ArrayQueuePT(10);
int n = 12;
while (n > 0){
stk1.push(n%2);
n = n/2;
}
String result = "";
while (! stk1.isEmpty()){
result += stk1.pop()+ " ";
}
System.out.println("the output of stk1 : "+result); //___________
for(int i =0; i<10; i++){
stk3.push(i);
}
stk2.push(stk3.pop());
stk2.push(stk3.pop());
stk2.push(stk3.pop());
result = "";
while (! stk2.isEmpty()){
result += stk2.pop()+ " ";
}
System.out.println("the output of stk2 : "+result); //___________
for(int i = 0; i < 10; i++){
if(i%4==0)
stk4.push( i + stk3.pop() );
}
result = "";
while (! stk4.isEmpty()){
result += stk4.pop()+ " ";
}
System.out.println("the output of stk4 : "+result); //___________
int limit = 5;
for(int i = 0; i < limit; i++) {
q1.push(Math.pow (i, i));
q2.push((limit - i)*(limit - i));
}
result = "";
while (! q1.isEmpty()){
result += q1.pop()+ " ";
}
System.out.println("the output of q1 : "+result); //___________
In: Computer Science
In: Computer Science
Imagine you are developing a software package that requires users to enter their own passwords. Your software requires that users' passwords meet the following criteria: The password should be at least six characters long. The password should be at least one uppercase and at least one lowercase letter. The password should have at least one digit. Write a program that asks for a password then verifies that it meets the stated criteria. If it doesn't, the program should display a message telling the user why.
In: Computer Science
In: Computer Science
//BEGIN--TABLE.H--
#ifndef TABLE_H
#define TABLE_H
#include // Provide string
#include // Provide hash
#include // Provide list
using namespace std;
class Table
{
public:
// MEMBER CONSTANT
static const unsigned int TABLE_SIZE = 13;
Table() { total_records = 0; }
virtual ~Table() { }
unsigned int get_total() { return total_records; }
virtual void insert(string key) =0;
virtual void print() =0;
protected:
unsigned int total_records;
// HELPER FUNCTION
unsigned int hashcode(string key) const
{
hash thishash;
return thishash(key) %
TABLE_SIZE;
}
};
class ChainTable : public Table
{
public:
ChainTable() {}
virtual void insert(string key);
virtual void print();
private:
list datatable[TABLE_SIZE];
};
class QuadTable : public Table
{
public:
QuadTable() {}
virtual void insert(string key);
virtual void print();
bool full() { return total_records == TABLE_SIZE;
}
private:
string datatable[TABLE_SIZE];
};
#endif
//END TABLE.H--
//BEGIN_TABLE1.CPP---
#include
#include "table1.h"
void ChainTable::insert(string key)
{
//-----------------------------------------------
// TO-DO: insert key into the chained hash table
// ------
// 1. use hashcode function to calculate bucket index
i
// 2. check if key is already in the
list at datatable[i];
// - if yes, do nothing
// - if no, insert key into the list,
increment total_records
}
// print table contents visually
void ChainTable::print()
{
cout << "ChainTable content: \n";
if (total_records==0)
{
cout << "\t Empty!\n";
return;
}
for (unsigned int i=0; i
{
if (datatable[i].empty())
continue;
cout << "\t Entry "
<< i << ": ";
for (list::iterator it =
datatable[i].begin(); it != datatable[i].end(); it++)
{
cout <<
(*it) << " -> ";
}
cout << "NULL\n";
}
}
//////////////////////////////////////////////////
void QuadTable::insert(string key)
{
//--------------------------------------------------------------
// TO-DO: insert key into the hash table using
quadratic probing
// ------
// 1. if hash table is full, do nothing and
return
// 2. use hashcode function to calculate
array index i
// 3. check if datatable[i] is empty
// - if yes, insert key at
datatable[i]
// - if no, use quadratic probing with
probe function c(i)=i^2,
// until an empty
location is found, insert key at that location
// 4. increment total_records
}
// print table contents visually
void QuadTable::print()
{
cout << "QuadTable content: \n";
if (total_records==0)
{
cout << "\t Empty!\n";
return;
}
for (unsigned int i=0; i
{
if (datatable[i].empty())
continue;
cout << "\t Entry "
<< i << ": ";
cout << datatable[i] <<
endl;
}
}
//End Table1.cpp--
In: Computer Science
You are required to use C++ static or dynamic arrays of characters to store c-strings. You are NOT allowed to use any C++ string data type variable for any purpose. Moreover, you are allowed to add any include directive. You are not allowed to include string, cstdlib or math libraries. Also, you are not allowed to use any built-in functions of c-strings.
can someone help with the third, fourth, and fifth functions? I tried many ways but i cannot figure them out...i don't know how to search char array and arrangement of range. I need it urgently.
typedef char* charPointer;
int cstrlen(const charPointer& s)
{
int i = 0;
int count = 0;
while (s[i] != '\0')
{
count++;
i++;
}
return count;
}
int countChars(const charPointer& s, const char&
ch)
{
int count = 0;
cstrlen;
for (int i = 0;i < cstrlen(s); i++)
{
if (s[i] == ch)
{
count++;
}
}
return count;
}
int findChar(const charPointer& s, const char& ch, const
int& startIndex = 0, const int& lastIndexTemp = -1)
{
/*
returns the smallest index where the character ch is
found in s starting from
startIndex (inclusive) upto lastIndex (exclusive). The
default argument value
for startIndex is 0. The default argument value for
lastIndexTemp is -1 in which
case cstrlen(s) must be used instead of -1.
For example,
findChar("test", 't', 1, 4) must
return 3. Here startIndex = 1, lastIndex = 4
findChar("test", 't', 3) must
return 3. Here startIndex = 3, lastIndex = 4
findChar("test", 't', 1, 3) must
return -1. Here startIndex = 1, lastIndex = 3
findChar("test", 't') must return
0. Here startIndex = 0, lastIndex = 4
If ch is not found in s in the given interval, the the
function must return -1
This function must first validate both the startIndex
and lastIndex.
That is, if lastIndex > cstrlen(s) or startIndex
< 0 it must return -1
*/
}
charPointer getCopy(const charPointer& s)
{
/*
returns a new cstring that is a copy of the cstring
s.
That is a new cstring with as big memory as the size
of
the cstring s is created and then all the characters
of
s including the null char are copied to it.
*/
}
void rotateString(const charPointer& s, const int&
r)
{
/*
Rotates the characters of s by r units
If r > 0, rotate the characters
of s to the left
If r < 0, rotate the characters
of s to the right
Please note the value of r can be
any integer even larger than the length of s
For example,
"asmara" rotated
to the left by 0 becomes "asmara"
"asmara" rotated
to the left by 1 becomes "smaraa"
"asmara" rotated
to the left by 2 becomes "maraas"
"asmara" rotated
to the left by 3 becomes "araasm"
"asmara" rotated
to the left by 4 becomes "raasma"
"asmara" rotated
to the left by 5 becomes "aasmar"
"asmara" rotated
to the left by 6 becomes "asmara"
"asmara" rotated
to the left by 7 becomes "smaraa"
"asmara" rotated
to the left by 8 becomes "maraas"
similarly
"asmara" rotated
to the right by 0 becomes "asmara"
"asmara" rotated
to the right by 1 becomes "aasmar"
"asmara" rotated
to the right by 2 becomes "raasma"
"asmara" rotated
to the right by 3 becomes "araasm"
"asmara" rotated
to the right by 4 becomes "maraas"
"asmara" rotated
to the right by 5 becomes "smaraa"
"asmara" rotated
to the right by 6 becomes "asmara"
"asmara" rotated
to the right by 7 becomes "aasmar"
"asmara" rotated
to the right by 8 becomes "raasma"
and
etc…
*/
}
int main()
{
/*
This main program is designed to test the functions
you need to implement.
You should NOT remove any line of code from this main
program.
But you may add more test code in the main program if
you like.
*/
cout << "This program is designed to help you
test your functions." << endl;
srand(time(0));
//Test cstrlen function
cout << endl << "Testing cstrlen
function";
cout << endl << "------------------------"
<< endl;
char s1[] = "irregular";
cout << "The length of s1=\"" << s1
<< "\" is " << cstrlen(s1) << endl;
char emptyCstr[] = "";
cout << "The length of \"\" is " <<
cstrlen(emptyCstr) << endl;
//Test countChars functions
cout << endl << "Testing countChars
function";
cout << endl <<
"---------------------------" << endl;
char ch = 'r';
int count = countChars(s1, ch);
cout << "ch='" << ch << "' is found
in s1=\"" << s1 << "\" " << count << "
times." << endl;
/*//Test findChar functions
cout << endl << "Testing findChar
function";
cout << endl <<
"-------------------------" << endl;
int a = 2, b = cstrlen(s1);
int index = findChar(s1, ch, a, b);
cout << "ch='" << ch << "' is found
in s1=\"" << s1 << "\" in the index interval ["
<< a << ", " << b << ") at index " <<
index << endl;
a = 3;
index = findChar(s1, ch, a);
cout << "ch='" << ch << "' is found
in s1=\"" << s1 << "\" in the index interval ["
<< a << ", " << b << ") at index " <<
index << endl;
b = 8;
index = findChar(s1, ch, a, b);
cout << "ch='" << ch << "' is found
in s1=\"" << s1 << "\" in the index interval ["
<< a << ", " << b << ") at index " <<
index << endl;
index = findChar(s1, ch);
cout << "ch='" << ch << "' is found
in s1=\"" << s1 << "\" in the index interval [0, "
<< cstrlen(s1) << ") at index " << index <<
endl;
//Test getCopy function
cout << endl << "Testing getCopy
function";
cout << endl << "------------------------"
<< endl;
char* s2 = getCopy(s1);
cout << "A copy of \"irregular\" is s2=\""
<< s2 << "\"" << endl;
char* s3 = getCopy(s2);
cout << "A copy of s2=\"" << s2 <<
"\" is s3=\"" << s3 << "\"" << endl;
delete[] s2;
s2 = new char('\0');
cout << "s2 is modified to s2=\"" << s2
<< "\" but s3 is still s3=\"" << s3 << "\""
<< endl;
delete[] s3;
s3 = getCopy(s2);
cout << "A copy of s2=\"" << s2 <<
"\" is s3=\"" << s3 << "\"" << endl;
//Test rotateString function
cout << endl << "Testing rotateString
function";
cout << endl <<
"-----------------------------" << endl;
char s4[] = "asmara";
for (int i = 0; i < 10; i++)
{
int r = rand() % 101 - 50;
if (r > 0)
cout <<
"s4=\"" << s4 << "\" rotated " << r << "
times to the left becomes ";
else
cout <<
"s4=\"" << s4 << "\" rotated " << -r << "
times to the right becomes ";
rotateString(s4, r);
cout << "\"" << s4
<< "\"" << endl;
}
return 0;
}
In: Computer Science
Counts the number of odd, even, and zero digits in an integer input value. Repeat until user does not want to continue. Develop the program in an incremental fashion. For example, write the part of the program, which inputs a single integer value and displays number of odd, even, and zero digits in that number. Submit your partial program for grading to make sure it works for the first few test cases. Below is an example execution of a partial program: Enter an integer value: 22000333 The number 22000333 contains Zero digits: 3 Even digits: 2 Odd digits: 3 Now, you can embed your partial code into a loop, which will allow the user to input more than one integer number, one at a time, and to see the number of odd, even, and zero digits in each respective number. When the user enters the sentinel value -99, the program terminates. Refer to Section 4.3 of zyBooks for an example program, which uses a loop with sentinel value. Below is an example execution of a complete program: ********************************************* Name: ??, CSCI1301, Section ??, Term: ?? Count Digits ********************************************* Enter an integer value (-99 to end): 7 The number 7 contains Zero digits: 0 Even digits: 0 Odd digits: 1 Enter an integer value (-99 to end): 22000333 The number 22000333 contains Zero digits: 3 Even digits: 2 Odd digits: 3 Enter an integer value (-99 to end): 12345 The number 12345 contains Zero digits: 0 Even digits: 2 Odd digits: 3 Enter an integer value (-99 to end): -99 Have a nice day!
Program is java
In: Computer Science