Questions
Hi I have a java code for my assignment and I have problem with one of...

Hi

I have a java code for my assignment and I have problem with one of my methods(slice).the error is Exception in thread "main" java.lang.StackOverflowError

Slice method spec:

Method Name: slice
Return Type: Tuple (with proper generics)
Method Parameters: Start (inclusive) and stop (exclusive) indexes. Both of these parameters are "Integer" types (not "int" types). Like "get" above, indexes may be positive or negative. Indexes may be null.
Description:

  • Positive indexes work in the normal way
  • Negative indexes are described above for "get"
  • If the "start" index is null, that means start at the beginning of the list (index=0)
  • If the "stop" index is null, that means the slice should go to the end of the list (including the last element)
  • If both "start" and "stop are null, that means to copy the tuple (in other words, return a new tuple with the same elements).


Given this Tuple:

[10, 20, 30, 40]

Example slice results

Start Stop Result (New Tuple)
0 1 [10]
0 2 [10, 20]
0 3 [10, 20, 30]
0 4 [10, 20, 30, 40]
null 1 [10]
null 3 [10, 20, 30]
-2 -1 [30]
-2 null [30, 40]
-1 null [40]
null null [10, 20, 30, 40]



Note: Each result is a new tuple

Example usage:

tuple2 = tuple1.slice(0, 1);
tuple2 = tuple1.slice(-1, null);

My code is the following:


import java.util.*;
public class Tuple1 <T>{
  
   private List<T> elements;

  
   public Tuple1(List<T> newElements){
       this.elements=newElements;
   }
  
   @SafeVarargs
   public Tuple1(T...newElements){
      
       List<T> elementsss=new ArrayList<T>();
       for(T i:newElements){
          
           elementsss.add(i);
           }
          

           this.elements=elementsss;
       }
  
   public Tuple1(Tuple1<T> tuple){
       elements=tuple.elements;
       }
  

   public List<T> getElements(){
           return this.elements;
       }
  
   public T get(Integer index){
      
       if(index<0){
               return this.getElements().get(size()+index);
           }
      
       else{
           return this.getElements().get(index);
      
       }

       }
  
   public int size(){
       return getElements().size();
      
   }
   public T getFirst(){
       return this.get(0);
          
       }

   public T getLast(){
       return this.get(-1);
       }  

  
   public List toList(){
      
       List<T> copy=new ArrayList<>(this.getElements());
          
           return copy;
       }

   public Integer confirmStart(Integer start){
           Integer star=0;

           if (start==null){
               star=0;
           }

           else if (start<0){
               star=this.size()+start;
               }

           else {
               star=start;
               }
           return star;
       }
  
   public Integer confirmStop(Integer stop){
           Integer sto=0;

           if(stop==null){
                   sto=this.size();
           }

           else if(stop<0){
                   sto=this.size()+stop-1;
               }

           else{
                   sto=stop-1;
           }
           return sto;
              
          
       }

   public Tuple1 <T> slice(Integer start,Integer stop){
          
           List<T> list= new ArrayList<T>();
          
           Integer star=this.confirmStart(start);
           Integer sto=this.confirmStop(stop);
          
           list=this.getElements().subList(star,sto);
          
           Tuple1 <T> t;
           t= new Tuple1 <T>(list);
               return t;
          
           }

   @Override
   public String toString(){
       String output="Tuple Elementst: "+" "+this.getElements()+
           "\n Get Element: "+this.get(0)+
           "\nSize: "+this.size()+
           "\nFirst Element:"+" "+this.getFirst()+
           "\nLast Element :"+" "+this.getLast()+
           "\nconfirmStart: "+" "+this.confirmStart(1)+
           "\nConfirm Stop:"+" "+this.confirmStop(-1)+
           "\ntoList:"+" "+this.toList()+
           "\nSlice:"+" "+this.slice(0,2);
          
           return output;
}

   public static void main (String[]args){
       List<String>elementss=new ArrayList<String>();
       elementss.add("Haitham");
       elementss.add("Lindsey");
       elementss.add("Lamar");
       elementss.add("Narmin");
      
       Tuple1 <String> elm;
       elm=new Tuple1<String>(elementss);
       System.out.println(elm.toString());
       System.out.println("================================");
       Tuple1 <Integer> elms;
       elms=new Tuple1<Integer>(1,2,3,4,5);
       System.out.println(elms.toString());

       }
   }  






















































In: Computer Science

In java what is the full code of a BoyerMoore search algorithm when nested in another...

In java what is the full code of a BoyerMoore search algorithm when nested in another class, using only JCF and no non standard packages. The text searching through can only contain printable ASCII characters, and capitalization matters. Also please provide the worst-case time complexity of the search algorithm.

The pattern is a String, and the contents searching is a String.

In: Computer Science

briefly describ major element of the structuar models in ood with UML

briefly describ major element of the structuar models in ood with UML

In: Computer Science

Java Project Tasks: Create a Coin.java class that includes the following:             Takes in a coin...

Java Project

Tasks:

Create a Coin.java class that includes the following:

            Takes in a coin name as part of the constructor and stores it in a private string

            Has a method that returns the coins name

            Has an abstract getvalue method

Create four children classes of Coin.java with the names Penny, Nickle, Dime, and Quarter that includes the following:

            A constructor that passes the coins name to the parent

            A private variable that defines the value of the coin

            A method that returns the coins name via the parent class

            And any other methods that should be required.

Create a Pocket class that includes the following:

            An ArrayList of type coin to manage coins.(You MUST use an ARRAYLIST)

            A method that allows a coin to be added

            A method that allows a coin to be removed

            A method that returns a count of the coins in your arraylist by coin type.

            A method that returns a total value of all the coins in your arraylist   

Create a NoSuchCoin class that will act as your custom exception (see pg.551 in book).

Create a PocketMain class that includes the following :

            Creates an object of type pocket to be used below

            A main method that prompts the user with a menu of options to include:

                        Add a coin (must specify type)

                        Remove a coin (must specify type)

                        Display a coin count

                        Display a total value in the pocket

                        An ability to exit the program

            This method must handle poor user input somehow using your custom exception

YOU MUST COMMENT YOUR CODE SO I KNOW WHAT IS HAPPENING!!!

Deliverables:

Pocket.java

Coin.java

Nickle.java

Penny.java

Dime.java

Quarter.java

PocketMain.Java

NoSuchCoin.java

In: Computer Science

I need assistance on what I am doing wrong, I've been trying to declare "getRandomLetter" as...

I need assistance on what I am doing wrong, I've been trying to declare "getRandomLetter" as a scope, but haven't found how to all day. It's been about 3+ hours and I still have nothing. Please help fix these and let me know what I am doing wrong (There may be more simple ways of coding all this, but I just need help fixing the errors with current code, thank you). I am trying to have buildAcronym() hold the position of going from A-Z , & as well as getRandomLetter() choose a letter from A-Z using the ASCII character set. This is a bit of the prompt where it asks to set these up. If I am off, I do apologize.

Define and overload two void-typed functions named buildAcronym that assign a (pseudo)-random uppercase letter to two (2) or three (3) character parameters, depending on the version called. Each character in an acronym must be a unique uppercase letter. Two arguments (or three, depending on the version called) will be assigned a random character literal, which can then be printed out in main.

These are my errors.

Acronyms.cpp: In function 'void buildAcronym(char, char, char)':
Acronyms.cpp:13:35: error: 'getRandomLetter' was not declared in this scope
getRandomLetter(a , b , c)
^
Acronyms.cpp: In function 'void buildAcronym(char, char)':
Acronyms.cpp:25:24: error: 'getRandomLetter' was not declared in this scope
getRandomLetter(a,b)
^
Acronyms.cpp: In function 'int main()':
Acronyms.cpp:50:39: error: 'getRandomLetter' was not declared in this scope
cout << getRandomLetter(a,b) ;
^
Acronyms.cpp:56:42: error: 'getRandomletter' was not declared in this scope
cout << getRandomletter(a,b,c);
^
Acronyms.cpp:60:9: error: expected ';' before '{' token
{
^
Acronyms.cpp:67:1: error: expected 'while' at end of input
}
^
Acronyms.cpp:67:1: error: expected '(' at end of input
Acronyms.cpp:67:1: error: expected primary-expression at end of input
Acronyms.cpp:67:1: error: expected ')' at end of input
Acronyms.cpp:67:1: error: expected ';' at end of input
Acronyms.cpp:67:1: error: expected '}' at end of input

------------------------------------------------------------------------------------------------------------------------------------

--

--------------------------------------

(there are 3 lines above include Name: Date: Filename: apologies that it is missing)

#include
using namespace std;


void buildAcronym(char a ,char b , char c)
{
if('A'<= b && 'A' <= b && 'A' <= c && a <= 'Z' && b <= 'Z' && c <= 'Z')
{
getRandomLetter(a , b , c)
{
cout << a + rand() % 65 + 90 << "." ;
cout << b + rand() % 65 + 90 << "." ;
cout << c + rand() % 65 + 90 << "." ;
}
}
return ;
}

void buildAcronym(char a , char b)
{
getRandomLetter(a,b)
{
cout << a + rand() % 65 + 90 << "." ;
cout << b + rand() % 65 + 90 << "." ;
}

return ;
}

int main()
{
char a , b , c ;
int choice ;
do
{
cout << "Press 1 for a two letter acronym, and 2 for a three letter acronym. " ;
cin >> choice ;
switch(choice)
{
case 1 :

if (choice == 1)
{

cout << getRandomLetter(a,b) ;
break ;
}
case 2 :
if (choice == 2)
{
cout << getRandomletter(a,b,c);
break;
}
else (choice != 1 && choice != 2)
{
cout << "Press 1 for a two letter acronym, and 2 for a three letter acronym. ";
}
}while(choice!=1 && choice != 2);

return 0;
}

In: Computer Science

1) Explain the process of port mirroring 2) difference between network media and networking device vulnerabilities

1) Explain the process of port mirroring

2) difference between network media and networking device vulnerabilities

In: Computer Science

Write a C++ function to print any given std::array of a given type to the standard...

Write a C++ function to print any given std::array of a given type to the standard output in the form of {element 0, element 1, element 2, ...}. For example given the double array, d_array = {2.1, 3.4, 5.6, 2.9}, you'd print {2.1, 3.4, 5.6, 2.9} to the output upon executing std::cout << d_array; line of code. Your function mus overload << operator.

In: Computer Science

Write a C++ function to print out all unique letters of a given string. You are...

Write a C++ function to print out all unique letters of a given string. You are free to use any C++ standard library functions and STL data structures and algorithms and your math knowledge here. Extend your function to check whether a given word is an English pangram (Links to an external site.). You may consider your test cases only consist with English alphabetical characters and the character.

In: Computer Science

Problem Description A local veterinarian at The Pet Boutique has asked you to create a program...

Problem Description A local veterinarian at The Pet Boutique has asked you to create a program for her office to create invoices for her patient’s office visits. When a customer brings their pet to the boutique, the clerk gets the Customer’s name, address, phone number and email address, as well as the pets name, pet type, pet age, and pet weight. After the customer sees the Veterinarian, the clerk determines the charges for the services, and medications for the office visit and prints the invoice for the customer’s records. The invoice should include the Customer’s name, address, phone, and email address, the pet’s name, type, age, and weight, service charges, medication charges, sales tax, and the total charges for the office visit. All calculations should take place in the class methods. All display should use method calls to the get methods from the classes to display the appropriate information. Do not accept any numbers that are less than or equal to zero. Calculate the sales tax using a constant equal to .0925 and limit the display to two decimal places. in Java

In: Computer Science

Hi, I am wondering how to create code that will allow (in c) the console to...

Hi, I am wondering how to create code that will allow (in c) the console to read a password from a .txt file, and have the ability to change this password?

I have a function that logs certain users in using simple if statements and hardcoded passwords, but i would like the ability to be able to change the password and read it from a .txt so it is editable instead of having it in a function in the code.

Thanks

In: Computer Science

i have this problem write an application that evaluates the factorials of the integeres from 1...

i have this problem write an application that evaluates the factorials of the integeres from 1 to 5 . i have this
!

control.WriteLine( "n\tn!;n");

for (in number=1; number <=5; number ++);

{

int factorail=1:

for (int 1=1; i<=number;1++);

factorial *=1:

Console.Writeline("{0}\t{1}".number,factorial);

output

n n!

1 1

2 2

3 6

4 24

5 120

I understand how the first row is printed.  

the first 1 in because the intfactorial is 1

the #2 if printed becasue in number =1; number<=5; number ++ =2

then it runs again number=2; number <=5; number ++ ) number is 3

then it runs again number=3; number <=5; number ++) number is 4

then it runs again number=4); njmber <=5; number ++) number is 5 and then ends because it hits <=5 and becomes true

so it goes to the next

for (int i=1; i<=number; i++

factorial *=1;

not sure how this works or comes up the mulipliers

In: Computer Science

Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Task 2...

Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested.

Task 2

Please define a function that extracts the even numbers in a given list. For example, given a list x = [2,3,5,6,7], the function will return a sublist [2,6] because 2 and 6 are even numbers in the list x.

The input of this function should be a list, and the output of the function should be a list as well (the sublist).

You can try the inline for loop with conditions to make the solution super simple.

Task 3

Use inline for loop to extract the common elements in two lists. For example, if x = [1,2,3], and y = [2,3,4], the result should be [2,3].

Hint: to check if a value exists in a list, you can use the “in” command. For example: we define two variables

a = 2 in [1,2,3]

b = 4 in [1,2,3].

After executing the codes, a will be a “True”, and b will be a “False”.

In: Computer Science

Digital security is an increasing concern is the Internet age. In order to protect sensitive information...

Digital security is an increasing concern is the Internet age. In order to protect sensitive information online, what are the methods for enhancing digital security? Select one method and describe in detail how it is implemented and how you would implement it to protect your online data.

In: Computer Science

Java Write a method that removes duplicates from an array of strings and returns a new...

Java

Write a method that removes duplicates from an array of strings and returns a new array, free of any duplicate strings.

In: Computer Science

Create a Java application to simulate a “GradeBook”. A teacher has five students who have taken...

Create a Java application to simulate a “GradeBook”. A teacher has five students who have taken four exams. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four exam scores:

Average

Letter Grade

90 – 100

A

80 – 89

B

70 – 79

C

60 – 69

D

0 – 59

F

Write logic to create a String array to hold student names, a character array to hold student letter grades, and a two-dimensional array to hold each of the five students’ test scores for each of the four exams completed during the semester.

Use nested for loop logic to fill the names and test scores arrays. Do not accept test scores less than zero or greater than 100. Make sure you test both ends of the range!

Use another nested for loop to compute the average test score for each student and then assign the corresponding letter the letter grade array. Make sure you test each letter grade value!

Use while loop logic to display a table showing each student’s name and letter grade.

In: Computer Science