Questions
Java Question: Which of the following statements about the reference super is true? a) It must...

Java Question:

Which of the following statements about the reference super is true?

a)

It must be used every time a method from the superclass is called.

b)

It must be the last statement of the subclass constructor.

c)

It must be the first statement of the subclass constructor.

d)

It can only be used once in a program.

In: Computer Science

C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select (...

C# ( asp.net ) 2019 Visual Studio

I have a dropdown where you can select ( integer, string, date )

After selecting the desired dropdown option, user can input a list of inputs. For example; for integer: 2,5,7,9,1,3,4

And then , I have a 'sort' button

Can you please help me with the code behind for sorting them( For integer, string, and date )

Thank you.

In: Computer Science

What countermeasures can be adopted to mitigate SYN flood attacks?

What countermeasures can be adopted to mitigate SYN flood attacks?

In: Computer Science

Python Question Using lists, write the function non_unique(list) that takes a list list as argument. It...

Python Question

Using lists, write the function non_unique(list) that takes a list list as argument. It
returns a list which duplicated elements remains and each duplicated element is followed by
a number which shows how many times it appears. All elements in return list should be in
the same order as their appearance in the original list.
For example, given the input [‘a’, ‘b’, ‘c’, ‘a’, ‘b’, ‘d’, ‘a’,‘e’], the function
would return [‘a’, 3, ‘b’, 2]. Another example, ['abc', 'def', 'abc', 'xyz', 'def','def', 'qwe'] -> ['abc', 2, 'def', 3]


If no such non_unique list exist, just return an empty list.
Your program should contain the function with format shown as below:

def non_unique(list):
# Your codes here
return result # ‘result’ is a list.

In: Computer Science

Locate your Student project from the previous in-class assignment. You will add a new class to...

Locate your Student project from the previous in-class assignment. You will add a new class to that project.

1. Create a class called Course. It should have a field to hold an ArrayList of Student objects.

2. Create a constructor for Course that accepts an ArrayList of Student objects, and set field to the parameter.

3. In the Course class, create a method called addStudent(Student s). This should add the parameter "s" to the ArrayList of Student objects.

4. In the Course class, create a method called removeStudent(Student s). This method should remove the parameter"s" from the ArrayList of Student objects.

5. In the Course class, create a method called toString(). This method should return a String showing the information from all the Student objects in the ArrayList. It should be formatted in the following way:

"Student 0: *Student 0 toString()*

Student 1: *Student 1 toString()*

...

Student n: *Student n toString()*"

This method should call each Student object's toString() method, as shown in the above example.

MY CODE :

student.java

package student;


public class Student {

  
public static void main(String[] args) {
  
  
Course myNewCourse = new Course(2) ;

System.out.println(myNewCourse.toString());
}
  
private int idNum;
private String firstN;
private String lastN;
  
public Student(int studentId, String firstName, String lastName ){   
idNum = studentId;
firstN = firstName;
lastN = lastName;
}
  
public String toString(){   
  
String allData = "Student"+"1"+":ID: "+getIdNum()+ ", First name: "
+ getFirstName()+ ", Last name: " +getLastName()+ "." ;
  

return allData;
}
  
public void setIdNum(int studentId){
  
this.idNum = studentId;
  
  
  
}
  
public void setFirstName(String firstName){
  
this.firstN = firstName;
  
  
}
  
public void setLastName(String lastName){
  
this.lastN = lastName;
  
}
  
public int getIdNum(){
  
  
return idNum;
  
}
  
  
public String getFirstName(){
  
return firstN;
  
}
  
public String getLastName() {
  
return lastN;
}
}

course.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package student;

import java.util.ArrayList;

/**
*
* @author farha
*/
public class Course {
  
ArrayList<Student> students = new ArrayList<Student>();
  
  
  
public Course(ArrayList<Student> students){
  
this.students = students;
  
  
}
  
public void addStudent(Student s){
  
students.add(0, s);
  
  
  
}
  
public void removeStudent(Student s){
  
students.remove(s);
  
}
  
public String toString(){
  
String information = ("");
  

return information;
}
  
  
  
}

In: Computer Science

My recursive Tower of Hanoi program does not render the correct index numbers. Also, it does...

My recursive Tower of Hanoi program does not render the correct index numbers. Also, it does not prompt user to enter the starting rod letter and the ending rod letter. Could you help me fix it?

Main.java

import java.io.*;

import java.util.List;

import java.util.Scanner;

public class Main {

int index = 1;

public static void main(String[] args) {

/**There is a stack of N disks on the first of three poles (call them A, B and C) and your job is to move the disks from pole A to pole B without

ever putting a larger disk on top of a smaller disk.*/

System.out.println();

System.out.println("Tower of Hanoi");

System.out.println("Program by Quang Pham");

System.out.println();

char startingrod = ' ';

char endingrod = ' ';

Scanner sc = new Scanner(System.in);

System.out.println("Enter the starting rod letter (A, B, or C).");

startingrod = sc.next().charAt(0);

System.out.println("Enter the ending rod letter (A, B, C).");

endingrod = sc.next().charAt(0);

if (startingrod == endingrod)

{

System.out.println("Sorry. Starting rod and ending rod cannot be the same.");

System.out.println("Enter ending rod letter (A, B, C)");

endingrod = sc.next().charAt(0);

}

if (startingrod == 'A' && endingrod =='C')

{

System.out.println("OK. Starting with discs 1, 2, 3, on rod A \n");

System.out.println("Moves are:");

int count = playHanoi (3,"A","B","C");

System.out.println();

System.out.println("All done.");

System.out.println("Took a total of " + count + " moves.");

System.out.println();

}

}

private static int playHanoi( int n, String from , String other, String to)

{ int count = 1;

//int index = 1;

if (n == 0)

return 0;

else if(n == 1)

{

System.out.printf("%d." + " Move disk "+ n +" from rod %s to rod %s \n", count, from, to);

//index++;

return count;

}

else{

count+= playHanoi(n-1, from, to, other);

System.out.printf("%d." + " Move disk " + n + " from rod %s to rod %s \n ", count, from, to);

count+=playHanoi(n-1, other, from, to);

}

//

return count;

}

}

The directions are:

  • Use three rods labeled A, B, and C
  • Use three discs labels 1 (smallest), 2 (medium size), and 3 (largest disc)
  • The program prompts you to enter the starting rod (A, B, or C)
  • The program prompts you to enter the ending rod (A, B, or C, but cannot be same rod as entered as starting rod)
  • The starting rod has discs 1, 2, 3, where 1 is on top of 2 is on top of 3 (just like we covered in class)
  • Your program should print out each move, showing clearly which disc goes from/to. See trace below.

Tower of Hanoi Program by YOUR NAME Enter Starting Rod (A, B, or C): A Enter Ending Rod (A, B, or C): A Sorry. starting and ending rod cannot be the same. Enter Ending Rod ((A, B, or C): C OK Starting with discs 1, 2, and 3 on rod A Moves are as follows: 1. Move disc 1 from rod A to rod C 2. Move disc 2 from rod A to rod B 3. Move disc 1 from rod C to rod B 4. Move disc. 3 from rod A to rod C 5. Move disk 1 from rod B to rod A 6. Move disk 2 from rod B to rod C 7. Move disk 1 from rod A to rod C All done. Took a total of 7 moves.

Any help with this program is greatly appreciated. Yours truly, Quang Pham

In: Computer Science

Why is anonymity different in TWN and WLAN? explain the 802.11 shared-key authentication process

Why is anonymity different in TWN and WLAN?

explain the 802.11 shared-key authentication process

In: Computer Science

For practice using exceptions, this exercise will use a try/catch block to validate integer input from...

For practice using exceptions, this exercise will use a try/catch block to validate integer input from a user. Write a brief program to test the user input. Use a try/catch block, request user entry of an integer, use Scanner to read the input, throw an InputMismatchException if the input is not valid, and display "This is an invalid entry, please enter an integer" when an exception is thrown. InputMismatchException is one of the existing Java exceptions thrown by the Scanner if the input does not match the type requested.

In: Computer Science

Goals Practice loops and conditional statements Description Create a game for elementary school students to practice...

Goals Practice loops and conditional statements Description Create a game for elementary school students to practice multiplication. The application should display a greeting followed by a set of mathematical questions.  In each set the player is asked to enter a number from 1 to 9 to test multiplication skills or to press ‘E’ to exit the game.  The application checks if the number entered is indeed between 1 and 9 and if not displays a message inviting the player to try again.  Upon receiving a number in a proper range the application starts displaying multiplication questions with that number being multiplied by 0,1,2,…,10. For example, if the player entered number 3, the first question will be: “3 x 0 = ?”, the second: “3 x 1 = ?”, and so on with the last question being “3 x 10 = ?”  At any point the player can press ‘E’ to exit current set  For each question if an incorrect result is entered the application prompts the player to try again. The player can choose to try again or bypass. The application provides up to 4 replay attempts to answer the same question.  For each question, the maximum score is 5 points if answered correctly. If not, each replay attempt lowers the score by 1 point. For example, if the player answered a question wrong and then got it right on the first replay attempt, the score is 4 points. Once the set is finished, a score for the set is presented and the player is invited to try another set.

In: Computer Science

QUESTION 15 Which line coding technique represents logical “1s” as alternating voltage changes (e.g., 1,1 represented...

QUESTION 15

Which line coding technique represents logical “1s” as alternating voltage changes (e.g., 1,1 represented as +v, -v).

a. Non-return to zero (NRZ)

b. Bipolar Alternative Mark Inversion (AMI)

c. Manchester

d. Bipolar with 8-zero substitution

QUESTION 16

  1. 4B5B differs from line coding techniques in that is ensures that strings of consecutive “1s” and “0s” do not exist prior to being line coded. Select the correct statement(s) regarding 4B5B.

    a. since 4B5B eliminates long string of logical “1s” and “0s”, simpler line coding techniques such as NRZ can be used.

    b. since one bit out of every five bits sent is not real information, the data link suffers from a 1/5 or 20% overhead cost (i.e., reduction in data throughput)

    c. only 80% of the data sent using 4B5B is real information

    d. all of the above are correct statements

QUESTION 17

  1. Analog-to-digital conversion (ADC) describes converting an analog signal into digital data. How is this accomplished?

    a. analog signals are continuous and therefore can never be converted into a digital signal

    b. analog signals must undergo a line coding process

    c. analog signals mush be sampled and quantized

    d. analog signals are modulated onto digital carriers

QUESTION 18

  1. You want to capture a live music concert and covert it into digital format for transmission. The human ear has a frequency bandwidth of approximately 20,000 Hz. Select the best sampling rate and bit depth.  (hint: use Nyquist and a bit-depth of 16)

    a. fs=40,000 samples/s, Bit depth = 1 bit per sample

    b. fs=40,000 samples/s, Bit depth = 16 bit per sample

    c. fs=10,000 samples/s, Bit depth = 16 bit per sample

    d. fs=20,000 samples/s, Bit depth = 1 bit per sample

QUESTION 19

When digitizing an analog signal, quantization errors will always be present regardless of bit-depth used.

True

False

QUESTION 20

What happens during an analog-to-digital conversion process, if you fail to follow the Nyquist formula?

a. signal aliasing occurs

b. quantization errors are experienced

c. nothing – your signal will be fine

d. None of the above

QUESTION 21

You digitize an analog signal that has a frequency bandwidth of 8kHz, using a bit depth of 4. What data rate must be supported?

a. 32 kpbs

b. 64 kbps

c. 128 kbps

d. 256 kbps

In: Computer Science

Write 2 pages on what is effective communication and follow up.

Write 2 pages on what is effective communication and follow up.

In: Computer Science

Handling Competition among Processes in computer science. Task Scheduling and Tasks Scheduler 3. What are the...

  1. Handling Competition among Processes in computer science.
  2. Task Scheduling and Tasks Scheduler

3. What are the Operating System (OS) functions to the computer and application software

In: Computer Science

The GroceryItem class must maintain the name of the item and its price (a double). You...

The GroceryItem class must maintain the name of the item and its price (a double).

You must read the grocery data from file, and store each line's information in a single GroceryItem object. In other words, there should be one GroceryItem object created for each line in the file. Implement all standard and necessary getters and setters, as well as constructors. Also, implement a calculateWithTax method that takes a double parameter, and returns the price with the tax added.

The input file, input.txt is attached to this assignment. You can assume each item has only one name without space (i.e., beef, pork, chicken, salad are all acceptable, but roast beef, roast chicken, honey ham, kale salad are not.)

Store all the objects of type GroceryItem in an ArrayList, and then in the main file, write a method that takes the ArrayList as a parameter, and prints out all the items with their pre- and post-tax prices.

The file I/O should take place in the GroceryItemDemo class, NOT the GroceryItem class.

**input.txt is as follows**

Tomatoes 1.99
Fudge 2.99
Bananas 1.99
Popcorn 0.99
Jerky 3.99
Milk 1.99

Two separate class files are required. We are using Netbeans with javaFX. I have input.txt in the correct place Im just confused on how to execute this.

In: Computer Science

Determine whether or not the following pairs are equivalent by constructing truth tables: [(wx'+y')(w'y+z)] and [(wx'z+y'z)]...

Determine whether or not the following pairs are equivalent by constructing truth tables:

[(wx'+y')(w'y+z)] and [(wx'z+y'z)] [(wz'+xy)] and [(wxz'+xy+x'z')]

In: Computer Science

Is there anyway to solve below problem in Java? Wherever there is int it gives an...

Is there anyway to solve below problem in Java?

Wherever there is int it gives an error! It's not only line 20! it give an runtime error everywhere get int after string! or even before read string!

cities[i] = sc.next(); //This way does not work!!!!

==============

input

San Francisco
Las Vegas
8
San Diego
Los Angeles
San Francisco
San Jose
Sacramento
Santa Barbara
Las Vegas
Pheonix
8 19
0 1
0 3
1 0
1 2
1 4
1 3
2 1
2 5
2 6
2 7
3 7
3 0
3 1
4 7
4 1
5 2
6 2
7 2
7 3

==============

Error:

==============

Exception in thread "main" java.util.InputMismatchException
        at java.util.Scanner.throwFor(Scanner.java:864)
        at java.util.Scanner.next(Scanner.java:1485)
        at java.util.Scanner.nextInt(Scanner.java:2117)
        at java.util.Scanner.nextInt(Scanner.java:2076)
        at Solution.main(myFuncs.java:20)

=======================

==============

import java.io.*;
import java.util.*;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;


public class myFuncs{

    public static void main(String arg[]) {
        Scanner sc = new Scanner(System.in);
        String s1, s2;
        s1 = sc.nextLine(); //first city
        s2 = sc.nextLine(); //second city
        int n = sc.nextInt(); //total number of cities
        String cities[] = new String[n];
        for (int i = 0; i < n; i++) {
            cities[i] = sc.nextLine(); //getting each city and storing them
        }
        n = sc.nextInt();
        int e = sc.nextInt();
        int adj[][] = new int[n][e];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < e; j++)
                adj[i][j] = 0;
        for (int i = 0; i < e; i++) {
            int c1 = sc.nextInt();
            int c2 = sc.nextInt();
            adj[c1][c2] = 1;
            adj[c2][c1] = 1;
        }

        int index1 = -1, index2 = -1;

        for (int i = 0; i < n; i++) {
            if (cities[i].equals(s1)) index1 = i; //storing the index of first city
            if (cities[i].equals(s2)) index2 = i; //storing the index of second city
        }

        adj[index1][index2] = 0;
        adj[index2][index1] = 0;


        System.out.println(cities[index1] + " " + index1);
        System.out.println(cities[index2] + " " + index2);


        if (bfs(adj, index1, index2, n)) System.out.println("true");
        else System.out.println("false");
    }

    public static boolean bfs(int adj[][], int source, int dest, int V) {

        boolean visited[] = new boolean[V];

        LinkedList < Integer > queue = new LinkedList < Integer > ();

        visited[source] = true;
        //visited[dest]=true;
        queue.add(source);

        while (queue.size() != 0) {

            int s = queue.poll();

            if (queue.size() != 0)
                queue.remove();

            System.out.print(s + " ");

            for (int i = s; i < V; i++) {
                if (adj[s][i] == 1 && !visited[i]) {
                    visited[i] = true;
                    queue.add(i);
                    if (i == dest) return true;
                }
            }

        }

        return false;
    }

}

In: Computer Science