Questions
n = int(input("Enter any number: ")) sum1 = 0 for i in range(1, n): if(n %...

n = int(input("Enter any number: "))
sum1 = 0
for i in range(1, n):
    if(n % i == 0):
        sum1 = sum1 + i
if (sum1 == n):
    print("The number is a Perfect number!")
else:
    print("The number is not a Perfect number!")

taking the code above, how would i create a new function that calls the program above and finds all perfect numbers within a certain range? the function would accept two parameters, the two ranges, and use a for loop to call the function above and print out all perfect numbers within a certain range (Ex. 1,100)

In: Computer Science

Refactor the code below so that it isn't awful! Justify your design decisions! public class BrownBear...

Refactor the code below so that it isn't awful! Justify your design decisions!

public class BrownBear {
  public String roar(){
    return "bear";
  }
}

public class SilentBrownBear {
  public String roar(){
    return "";
  }
}

public class PolarBear {
  public String roar(){
    return "brrrr";
  }
}

public class SilentPolarBear {
  public String roar(){
    return "";
  }
}

In: Computer Science

Based on what you know about object oriented programming, inheritance, and polymorphism, why do you think...

Based on what you know about object oriented programming, inheritance, and polymorphism, why do you think it is not possible to write code like this in Java:

public class X extends Y, Z {
  // ...
}

...but can write code like this:

public class A implements B, C {
  //...
}

In: Computer Science

c program Identify type of library file that need to be used when the program needs...

c program

  1. Identify type of library file that need to be used
    1. when the program needs to returns the absolute value of its integer argument such as : if x is -5, abs(x) is 5.
    2. When the program needs to return a randomly chosen integer between 0 and the value associated with RAND_MAX,
    3. When the program needs to return the base-10 logarithm of x for x>0.0: example if x is 100.0, log 10(x) is 2.0

In: Computer Science

declare an integer array of n numbers //enter a value for n before the declaration enter...

declare an integer array of n numbers //enter a value for n before the declaration

enter values for the declared array, pass the array to the method that has the name "countNumbers"

let the function countNumber count how many elements of the array in the interval
[70 90] means between 70 and 90 inclusive, returns this count to the main, and prints it using format printing.

---------------
Please Solve As soon as
Solve quickly I get you thumbs up directly
Thank's
Rawan F

In: Computer Science

In C++ 1. Test Scores #1 Write a program that dynamically allocates a built-in array large...

In C++

1. Test Scores #1

Write a program that dynamically allocates a built-in array large enough to hold a user-defined number of test scores. (Ask the user how many grades will be entered and use a dynamic array to store the numbers.) Once all the scores are entered, the array should be passed to a function that calculates the average score. The program should display the scores and average. Use pointer notation rather than array notation whenever possible. (Input Validation: Do not accept negative numbers for test scores.) Make it a class, call it something like gradeholder. You will need a destructor because you are using dynamic arrays.

In: Computer Science

c program Evaluate the expression 1 && (30%10 >=0) && (30 %10<=3) Is either set of...

c program

  1. Evaluate the expression
    1. 1 && (30%10 >=0) && (30 %10<=3)
    2. Is either set of parentheses required?
    3. Write the complement of the expression two ways. First, add one operator and one set of parentheses. For the second version, use DeMorgan’s theorem.

In: Computer Science

what is the difference between capacity and size in COA, and what is the formula to...

what is the difference between capacity and size in COA, and what is the formula to calculate them?

In: Computer Science

Need urgently, please do it as soon as possible i have only 40 min for this...

Need urgently, please do it as soon as possible i have only 40 min for this task ( Doing in Java).

Question no 1: Solve completely.

a) Define the following concepts with proper syntax, where required. Also, write why we use these concepts (for last three bullets).

 Execution process of java program

 Copy constructor

 Instance and class variable

 Access specifiers

b) Write a program to print the area of a rectangle by creating a class named 'Area' having two methods. First method named as 'setDim' takes length and breadth of rectangle as parameters and the second method named as 'getArea' returns the area of the rectangle. Length and breadth of rectangle are passed through constructor.

In: Computer Science

Display nonduplicate names in ascending order) Given one or more text files, each representing a day’s...

Display nonduplicate names in ascending order) Given one or more text files, each representing a day’s attendance in a course and containing the names of the students who attended the course on that particular day, write a program that displays, in ascending order, the names of those students who have attended at least one day of the course. The text file(s) is/are passed as command-line argument(s). USe language java, ide netbeans

In: Computer Science

Find a 13-bit burst error polynomial that cannot be detected by the CRC-8 check. The burst...

Find a 13-bit burst error polynomial that cannot be detected by the CRC-8 check. The burst error polynomial must have the form E(x) = x^12 + … + 1, and the terms x^k for k = 1, 2, …, 11 can have a coefficient of either 0 or 1. Here is a 13-bit burst error polynomial that can be detected: x^12 + x^8 + x^2 + x + 1. The CRC-8 generator polynomial is x^8 + x^2 + x + 1. (By a 13-bit burst error we mean that there has been a burst of energy that causes noise on the communication channel during the span of 13 bits. For example, the energy may drive the voltage to a high value for all 13 bits. Some of those bits might have been 1’s (and represented by the high voltage), so the energy does not cause those bits to be in error. So, assume the first and thirteenth bits are incorrect, and the bits in between those two end points may or may not be in error.)

In: Computer Science

1. You are the director of operations of a large airport. Discuss the above statement showing...

1. You are the director of operations of a large airport. Discuss the above statement showing how far it is reflected in your day to day work. 2. The Information Super-highway is widely used in modern airports. Discuss how the Information Super-highway is useful in the following domains: a) Communication b) Security

In: Computer Science

We want to develop a sales system for a mobile shop. The system should keep information...

We want to develop a sales system for a mobile shop. The system should keep information about the mobile phones available at the shop. the system should allow the user the ADD new mobile phones, one at a time, along with their features. The system should also allow to search mobile phones , update their information, and delete them (one by one). Try to provide different criteria for search. When the system starts, it should load the information about the mobile phones forma file. if the file doesn't exist, the system should create the file. The system should provide a (console based) menu to interact with it. The system not use any arrays and all the changes should be reflected in the file.

Language: C++

In: Computer Science

Describe the three main types of referential actions (cascade, restrict, set null). How do you use...

Describe the three main types of referential actions (cascade, restrict, set null). How do you use these in your work?

In: Computer Science

I have a problem with the code for my project. I need the two clients to...

I have a problem with the code for my project. I need the two clients to be able to receive the messages but the code I have done only the server receives the messages. I need the clients to be able to communicate with each other directly not throught the server.

The requirements of this "local chat" program must meet are:

1. The chat is performed between 2 clients and a server.

2. The server will first start up and choose a port number. Then the server prints out its IP address and port number.

3. The client then will start up and create a socket based on the information provided by the server.

4. Now the client and the server can chat with each other by sending messages over the network.

5. The client/server MUST be able to communicate with each other in a continuous manner. (e.g. One side can send multiple messages without any replies from the other side)

6. There is no requirement on what language you use to implement this project, but your program should call upon the socket API for UDP to realize the functionality.

7. You should demonstrate your project using two machines (one for the client and one for the server. Pick your virtual machine as the client to communicate with your actual machine, which is server in our project).

8. You need to open at least 2 cmd window in your virtual machine to demonstrate multiple machine communicate with your server machine (actual machine)

My Code

UDPServer.java

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPServer {
   public static void main(String args[]) throws Exception{
       int serverport=6789;
       int clientport=1234;
       byte[] receiveData = new byte[1024];
       byte[] sendData = new byte[1024];
       DatagramSocket serverSocket = new DatagramSocket(serverport);
       System.out.println("SERVER READY");
       while(true){
       DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
       serverSocket.receive(receivePacket);
       String msg = new String(receivePacket.getData()).trim();
       System.out.println("Message from CLIENT with ID:"+msg);
        InetAddress IPAddress = receivePacket.getAddress();
       int port = receivePacket.getPort();
       String returnMsg = "Thanks. Received your message!";
       sendData = returnMsg.getBytes();
       DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
       serverSocket.send(sendPacket);
       }
   }
}

UDPClient.java

package socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPClient {
   public static void main(String args[]) throws Exception{
       int serverport=6789;
       int clientport=1234;
       byte[] sendData = new byte[1024];
       byte[] receiveData = new byte[1024];       
       BufferedReader inFromUser = new BufferedReader(   new InputStreamReader(System.in));
       String clientId;
       System.out.println("Enter your ID:");
       clientId = inFromUser.readLine();
       while(true) {
           System.out.println("Enter your message:");
           String sentence = inFromUser.readLine();
          
           DatagramSocket clientSocket = new DatagramSocket();
           InetAddress IPAddress = InetAddress.getByName("localhost");
           sendData = (clientId+":"+sentence).getBytes();
           DatagramPacket sendPacket =
                   new DatagramPacket(sendData, sendData.length, IPAddress, serverport);
           clientSocket.send(sendPacket);
           DatagramPacket receivePacket =
                   new DatagramPacket(receiveData, receiveData.length);
           clientSocket.receive(receivePacket);
           String receivedMsg = new String(receivePacket.getData()).trim();
           System.out.println("FROM SERVER:" + receivedMsg);
           clientSocket.close();
       }
   }
}

In: Computer Science