Questions
in java please!!! suppose there is a text file named TextFile.txt with some data in the...

in java please!!!

suppose there is a text file named TextFile.txt with some data in the root directory (e.g. C:\ or \) of your computer. In JAVA, write code that (i) opens the file in read mode; (ii) displays the file content on the monitor screen/console; (iii) uses exception handling mechanism with try, catch, and finally blocks; and (iv) safely closes the file. Writing the main() method is optional.

In: Computer Science

Introduction to the Problem Design an Amazon Virtual Private Cloud (VPC): "Scenario: You have a small...

Introduction to the Problem

Design an Amazon Virtual Private Cloud (VPC):

"Scenario: You have a small business with a website that is hosted on an Amazon Elastic Compute Cloud (Amazon EC2) instance. You have customer data that is stored on a backend database that you want to keep private. You want to use Amazon VPC to set up a VPC that meets the following requirements:

•          Your web server and database server must be in separate subnets.

•          The first address of your network must be 10.0.0.0. Each subnet must have 256 total IPv4 addresses.

•          Your customers must always be able to access your web server.

•          Your database server must be able to access the internet to make patch updates.

•          Your architecture must be highly available and use at least one custom firewall layer."

For the Program Level Assessment, short summary report using the following criteria:

Define the Problem

re-state the problem you are asked to solve and detail all relevant findings and recommendations.

Identify Strategies

Explain how your VPC design meets requirements in scenario.

Propose Solutions

How you can improve or change your design using additional services learned in class.

Evaluate Outcomes

Briefly explain how your design and propose solutions meets at least two of the pillars of AWS Well-Architected Framework.

Submit a Word Document

Using the section headers above, provide responses for each and summary report.

In: Computer Science

Here is class Dog -String name; -int age -String breed; -boolean adopted; //false if available …………………...

Here is class Dog

-String name; -int age

-String breed;

-boolean adopted; //false if available ………………… +constructor, getters, setters, toString() Write a lambda expression showAdoptable using a standard functional interface that will display the dog’s name age and breed if adopted is false.

Help please!!

In: Computer Science

public class Point { protected double x, y; // coordinates of the Point //Default constructor public...

public class Point
{
        protected double x, y; // coordinates of the Point

                //Default constructor
        public Point()
        {
        setPoint( 0, 0 );
        }

                //Constructor with parameters
        public Point(double xValue, double yValue )
        {
        setPoint(xValue, yValue );
        }

                // set x and y coordinates of Point
        public void setPoint(double xValue, double yValue )
        {
        x = xValue;
        y = yValue;
        }

                // get x coordinate
        public double getX()
        {
        return x;
        }

                // get y coordinate
        public double getY()
        {
        return y;
        }

                // convert point into String representation
        public String toString()
        {
        return "[" + String.format("%.2f", x)
               + ", " + String.format("%.2f", y) + "]";
        }

     //Method to compare two points
        public boolean equals(Point otherPoint)
        {
        return(x == otherPoint.x &&
               y == otherPoint.y);
        }

     //Method to compare two points
        public void makeCopy(Point otherPoint)
        {
        x = otherPoint.x;
        y = otherPoint.y;
        }

        public Point getCopy()
        {
        Point temp = new Point();

        temp.x = x;
        temp.y = y;

        return temp;
        }

                // print method
        public void printPoint()
        {
        System.out.print("[" + String.format("%.2f", x)
                       + ", " + String.format("%.2f", y) + "]");
        }

}  // end class Point

**********************************************************************************************************************************************************************

Every circle has a center and radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Please do the following:

  1. Design the class Circle that can store the radius and the center of the circle based on the class Point (above). You should be able to perform the usual operation on a circle, such as setting radius, printing the radius, calculating and printing the area and circumference, and carrying out the usual operations on the center.
  2. Write a test program to test your program.

In: Computer Science

In JAVA, please With the mathematics you have studied so far in your education you have...

In JAVA, please

With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to an equation f(x) = 0 for some function f. Use the bisection method. To solve the problem using this method first find two values of x, A and B, such that when evaluated in the function f(x) they give opposites signs for the y value. If f(x) is continuous between these two values then we know that there is at least one x which evaluates to a 0 y value, which is between these two values A and B. Treat the positive value as an upper bound and the negative value as a lower bound. Divide the space between A and B in half and evaluate the function at that new point.   If the value is positive than it replaces the existing upper-bound and if it is negative it replaces the existing lower-bound. Continue dividing the space between the upper-bound and lower-bound in half and evaluating this new value and generating new upper and lower bounds as the case may be. Continue the evaluation process until the x value that you are plugging into the function evaluates to a y value that is zero plus or minus .0000001.

                Consider the possibility of finding all the real roots of any given function up to and including x raised to the fifth power. Input should consist of reading the coefficients one at a time to the powers of x up to 5 and some constant.   Do a desk check with calculator on y = X2 -2 and identify the variables associated with that problem. Write the code that follows your algorithm. Then test your program on other polynomials such as 2x5 -15x4 + 35x3 -15x2-37x + 30 (roots are -1, 1, 2, 2.5, 3) and 3x5 -17x4 + 25x3 + 5x2 -28x + 12 (roots are -1,1, 2/3, 2, 3). Use at lest 3 methods. One to read the 5 coefficients, one to calculate the value of the polynomial and one to do the binary bisection search.   Use the following for loop to work through the X values:for(double x = -5.0000001; x < 5.0000001; x = x + .1)

After it runs as a console program, using the GUI example from my website as a guide, convert this program to a graphics program. Keep the example GUI always working. Create multiple versions as you add code that will implement the polynomial problem. Always be able to go back to a previous working version if you get stuck. When you get the polynomial program working then delete the example code. To debug your compiled program, use System.out.println() to follow intermediate values of your variables to see where your code does not follow the algorithm.

----------------------- example
/**
 * demonstrating a GUI program
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class ExampleGUI extends JPanel
{
        // ***Variables are created ***
        //*** GUIs are made up of JPanels.  Panels are created
        //*** here and named appropriately to describe what will
        //*** be placed in each of them.
        JPanel titlePanel = new JPanel();
        JPanel questionPanel = new JPanel();
        JPanel inputNumberPanel = new JPanel();
        JPanel addAndSubtractButtonPanel = new JPanel();
        JPanel answerPanel = new JPanel();
        JPanel nextNumberPanel = new JPanel();
        //*** a JLabel is a text string that is given a String value
        //*** and is placed in its corresponding JPanel or JButton
        JLabel titleLabel = new JLabel();
        JLabel questionLabel = new JLabel();
        JLabel inputNumberLabel = new JLabel();
        JLabel add5Label = new JLabel();
        JLabel subtract5Label = new JLabel();
        JLabel answerLabel = new JLabel();
        JLabel nextNumberLabel = new JLabel();
        //*** three JButtons are created.  When pushed, each button calls
        //*** its corresponding actionPerformed() method from the class created
        //*** for each button. This method executes the method code, performing
        //*** what the button is to do.
        JButton add5Button = new JButton();
        JButton subtract5Button = new JButton();
        JButton nextNumberButton = new JButton();
        //*** a JTextField creates a location where the client can place
        //*** text
        JTextField inputTextField = new JTextField(15);

        
         //*** constructor
         //*** Variables are given initial values
        
        public ExampleGUI()
        {
                //*** set panel layouts
                //*** panels could be LEFT, or RIGHT justified.
                titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
                questionPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
                inputNumberPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
                addAndSubtractButtonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
                answerPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
                nextNumberPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

                //*** set Label fonts.  You can use other numbers besides 30,20
                //*** or 15 for the font size.  There are other fonts.
                Font quizBigFont = new Font("Helvetica Bold", Font.BOLD, 30);
                Font quizMidFont = new Font("Helvetica Bold", Font.BOLD, 20);
                Font quizSmallFont = new Font("Helvetica Bold", Font.BOLD, 15);
                titleLabel.setFont(quizBigFont);
                questionLabel.setFont(quizMidFont);
                inputNumberLabel.setFont(quizMidFont);
                add5Label.setFont(quizSmallFont);
                subtract5Label.setFont(quizSmallFont);
                answerLabel.setFont(quizBigFont);
                nextNumberLabel.setFont(quizSmallFont);
                inputTextField.setFont(quizMidFont);
                //*** labels are given string values
                titleLabel.setText("Add or Subtract Five");
                questionLabel.setText("Please enter an integer number.");
                inputNumberLabel.setText("Number:");
                add5Button.setText("   Add 5   ");
                subtract5Button.setText("Subtract 5");
                answerLabel.setText("");
                nextNumberButton.setText("   New Number   ");
                //*** the 3 buttons are connected to their classes
                add5Button.addActionListener(new add5Button());
                subtract5Button.addActionListener(new subtract5Button());
                nextNumberButton.addActionListener(new nextNumberButton());
                //*** Labels, buttons and textFields are added to their
                //*** panels
                titlePanel.add(titleLabel);
                questionPanel.add(questionLabel);
                //*** inputNumberPanel has 2 items added
                inputNumberPanel.add(inputNumberLabel);
                inputNumberPanel.add(inputTextField);
                //*** submitPanel has two items added
                addAndSubtractButtonPanel.add(add5Button);
                addAndSubtractButtonPanel.add(subtract5Button);
                answerPanel.add(answerLabel);
                nextNumberPanel.add(nextNumberButton);
                //*** The panels are added in the order that they should appear.
                //*** Throughout the declarations and initializations variables were
                //*** kept in this order to aid in keeping them straight
                setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                add(titlePanel);
                add(questionPanel);
                add(inputNumberPanel);
                add(addAndSubtractButtonPanel);
                add(answerPanel);
                add(nextNumberPanel);
                
                 //*** The method writeToFile() is called from the constructor.
                 //*** One could call a read method from the constructor.
                
        //      writeToFile();
        }// constructor
        
         //*** This method writes 4 lines to a file.  Eclipse puts the file in
         //*** the folder of the project but not in the src folder.  Put any
         //*** file that you want read in the same place so that Eclipse can
         //*** find it.
        /* 
        private void writeToFile()
        {
                String fileName = "textFile.txt";
                String line = null;
                int count;
                Scanner scan = new  Scanner(System.in);
                PrintWriter textStream = TextFileIO.createTextWrite(fileName);
                System.out.println("Enter 4 lines of text:");
                for (count = 1; count <= 4; count++)
                {
                        line = scan.nextLine();
                        textStream.println(count + " " + line);
                }
                textStream.close( ); //*** did not require error handling
                System.out.println("Four lines were written to " + fileName);
        }
        */
         //*** display() is called from main to get things going
         
        public void display()
        {       //*** A JFrame is where the components of the screen
                //*** will be put.
                JFrame theFrame = new JFrame("GUI Example");
                //*** When the frame is closed it will exit to the
                //*** previous window that called it.
                theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                //*** puts the panels in the JFrame
                theFrame.setContentPane(this);
                //*** sets the dimensions in pixels
                theFrame.setPreferredSize(new Dimension(600, 380));
                theFrame.pack();
                //*** make the window visible
                theFrame.setVisible(true);
        }
        
         //*** method doSomething is called from an actionPerformend method
         //*** demonstrating calling methods that can do work for you.
         
        private void doSomething()
        {
                for(int x = 1; x <= 10; x++)
                        System.out.println(" in doSomething method x is " + x);
        }

        
        //*** This class has one method that is called when the add5Button
        //*** is pushed.  It retrieves the string from the JTextField
        //*** inputTextField, converts it to an integer and manipulates the
        //*** number.
        //*** NOTE: a string of integers can be formed by creating a string
        //*** with one of the numbers and then concatenating the other integers
        //*** to form the string.
         
        class add5Button implements ActionListener
        {
                public void actionPerformed(ActionEvent e)
                {
                        System.out.println(" in add5Button class");
                        doSomething();//*** other methods can be called
                        int number = Integer.parseInt(inputTextField.getText());
                        number = number + 5;
                        String stringNumber = "" + number;
                        answerLabel.setText(stringNumber);//*** answerLabel gets a new value
                        inputTextField.setText(stringNumber);
                }
        }
        class subtract5Button implements ActionListener
        {
                public void actionPerformed(ActionEvent e)
                {
                        System.out.println(" in subtract5Botton class");
                        int number = Integer.parseInt(inputTextField.getText());
                        number = number - 5;
                        String stringNumber = "" + number;
                        answerLabel.setText(stringNumber);
                        inputTextField.setText(stringNumber);
                }
        }
        
        //*** this method resets the values of inputTextField and answerLable
         
        class nextNumberButton implements ActionListener
        {
                public void actionPerformed(ActionEvent e)
                {
                        inputTextField.setText("");//*** erases the values of this JTextField
                        answerLabel.setText("");//*** erases the value of this JLabel
                }
        }
        public static void main(String[] args) throws IOException
          {
                ExampleGUI gameGUI = new ExampleGUI();
                System.out.println("we can print to the console");
            gameGUI.display();

          }
}

In: Computer Science

How to write Method in Java: public static in firstLetterFreq(char letter, String[] words] { // it...

How to write Method in Java: public static in firstLetterFreq(char letter, String[] words]

{

// it returns 0 if (words == null OR words.length == 0)

// returns number of times letter is the first letter of a String in words array

// use equalIgnoreCase to check if letter and str.charAt(0) are equal and ignoring case

}

In: Computer Science

Briefly describe the difference between recursive and iterative DNS query?

Briefly describe the difference between recursive and iterative DNS query?

In: Computer Science

PYTHON head_count = [np.equal(x3,i).sum() for i in range(1,18)] head_count The question is: how could I write...

PYTHON

head_count = [np.equal(x3,i).sum() for i in range(1,18)]
head_count

The question is: how could I write code that does the same as np.equal(x3,i).sum() without using Numpy?

In: Computer Science

RecursiveFunction(n) // n is an integer { if (n > 0){ PrintOut(n % 2); RecursiveFunction(n /...

RecursiveFunction(n) // n is an integer {

if (n > 0){

PrintOut(n % 2);

RecursiveFunction(n / 3);

PrintOut(n % 3);

}

}

What is the output of this RecursiveFunction Pseudocode algorithm if it is initially called with 10 for n? Explain how you arrived at that answer; by writing call stack for the execution of his function at each step. What is the Big O running time of the RecursiveFunction described above? Explain your answer.

In: Computer Science

JS Suppose you have an object named obj. How do you serialize it to a JSON...

JS

Suppose you have an object named obj. How do you serialize it to a JSON string with each level indented two spaces? This action is the inverse of JSON.parse.

In: Computer Science

Add a sort instance method to the IntList class, so that x.sort() returns an IntList that...

Add a sort instance method to the IntList class, so that x.sort() returns an IntList that is a version of the IntList x, sorted in non-decreasing order. You may use any sorting algorithm you like. There should be no side effect on x.

//IntList Class

public class IntList {

private ConsCell start;

public IntList(ConsCell s) {

start = s;

}

public IntList cons (int h) {

return new IntList(new ConsCell(h,start));

}

public int length() {

int len = 0;

ConsCell cell = start;

while (cell != null) {

len++;

cell = cell.getTail();

}

return len;

}

public void print() {

System.out.print("[");

ConsCell a = start;

while (a != null){

System.out.print(a.getHead());

a = a.getTail();

if (a != null) System.out.print(",");

}

System.out.println("]");

}

public static void sort(int[] ConsCell) {

}

}

// ConsCell Class

/**

* A ConsCell is an element in a linked list of

* ints.

*/

public class ConsCell {

private int head;

private ConsCell tail;

public ConsCell(int h, ConsCell t) {

head = h;

tail = t;

}

public int getHead() {

return head;

}

public ConsCell getTail() {

return tail;

}

public void setTail(ConsCell t) {

tail = t;

}

}

//Main Class

public class Main {

public static void main(String args[]){

IntList a = new IntList(null);

IntList b = a.cons(2);

IntList c = b.cons(1);

IntList d = c.cons(3);

int x = a.length() + b.length() + c.length() + d.length();

a.print();

b.print();

c.print();

d.print();

System.out.println(x);

}

}

In: Computer Science

In Java, Modify “Producer and Consumer Problem” from lecture note so that it can use all...

In Java, Modify “Producer and Consumer Problem” from lecture note so that it can use all buffer space, not “buffer_size – 1” as in the lecture note. This program should work as follows:

1. The user will run the program and will enter two numbers on the command line. Those numbers will be used for buffer size and counter limit.

2. The main program will then create two separate threads, producer and consumer thread.

3. Producer thread generates a random number through random number generator function and inserts this into buffer and prints the number. Increment counter.

4. Consumer thread goes to the buffer and takes a number in the proper order and prints it out. Increment counter.

5. After counter reaches its limit, both threads should be terminated and return to main.

6. Main program terminates.

In: Computer Science

Hello everyone! I have been stuck on this problem in my python 3 coding class. Is...

Hello everyone! I have been stuck on this problem in my python 3 coding class. Is there anybody who can see what I am doing wrong? The wings are .50 cents each, If I input sour and want 20 wings it should output a 0.15 discount. I just can't get it to work but I feel like I am really close. Thank you

Code:

#Variables
answer = str()
wings = int()
rate = float()
discount = float()
subtotal = float()
total = float()

#Enter the type of wings
type = input("Enter the wing type: ")
sour = int()
hot = int()

#determining the discount rate
while answer != 'no':
#Enter the quantity of wings
wings = int(input("Enter the quantity: "))
if hot <= 6:
rate = 0
elif hot > 6 <= 12:
rate = 0.1
elif hot > 12 <= 24:
rate = 0.2
elif sour <= 6:
rate = 0.05
elif sour > 6 <= 12:
rate = 0.1
elif sour > 12 <= 24:
rate = 0.15
else: 0.25

#determining the subtotal
subtotal = wings * .5
#determining the discount
discount = rate * subtotal
#determining the total
total = subtotal - discount

#print out rate, subtotal, discount and total
print("Discount Rate:", rate)
print("Subtotal: $", subtotal)
print("Discount: $", discount)
print("Total: $", total)
#ask the user if they want to enter another batch
answer = input("Would like to purchase another order of wings : ")

In: Computer Science

When using the ORDER BY statement, the keywords: ASC, or DESC must be used to control...

When using the ORDER BY statement, the keywords: ASC, or DESC must be used to control the sort order. The ORDER BY statement will not work without a designated sort order keywords.

In: Computer Science

1. Give the O-runtime depending on n for the code snippet below (n > 0). for(...

1. Give the O-runtime depending on n for the code snippet below (n > 0).

for( j = n; j <= 0; j = j - 1)

                                    for( k = 1; k <= n; k = k + 1)

                                                print(" ");

2. Give the O-runtime depending on n for the code snippet below (n > 0).

           for( j = 1; j <= n; j = j + 1)

                                    for( k = 1; k <= n; k = k + 2)

                                                print(" ");

In: Computer Science