Questions
In the Gui need a file in and out writter. That also takes from in file...

In the Gui need a file in and out writter. That also takes from in file and out file. Write errors to no file found or wrong file. Clear button and Process buttons need to work.

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.*;

import javax.swing.*;

@SuppressWarnings("serial")
public class JFileChooserDemo extends JFrame implements ActionListener
{
private JTextField txtInFile;
private JTextField txtOutFile;
private JButton btnInFile;
private JButton btnOutFile;
private JButton btnProcess;
private JButton btnClear;
public JFileChooserDemo()
{
   Container canvas = this.getContentPane();
   canvas.setLayout(new GridLayout (3,1));
     
   canvas.add(createInputFilePanel());
   canvas.add(createOutputFilePanel());
   canvas.add(createButtonPanel());
   this.setVisible(true);
   this.setSize(800, 200);
   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public JPanel createInputFilePanel()
{
   JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
   panel.add(new JLabel("In File"));
   txtInFile = new JTextField(60);
   panel.add(txtInFile);
   btnInFile = new JButton("In File");
   panel.add(btnInFile);
   btnInFile.addActionListener(this);
   return panel;
}
  
public JPanel createOutputFilePanel()
{
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));  
panel.add(new JLabel("Out File"));
txtOutFile = new JTextField(58);
panel.add(txtOutFile);
btnOutFile = new JButton("Out File");
panel.add(btnOutFile);
btnOutFile.addActionListener(this);
return panel;   
}
public JPanel createButtonPanel()
{
   JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
   btnProcess =new JButton("Process");
   btnProcess.addActionListener(this);
   panel.add(btnProcess);
  
   btnClear =new JButton("Clear");
   btnClear.addActionListener(this);
   panel.add(btnClear);
   return panel;
}
public static void main(String[] args)
{
   new JFileChooserDemo();
   Scanner file = null;
   PrintWriter fout= null;
           try {
               file = new Scanner(new File("numbers.txt"));
               fout = new PrintWriter("TotalSums.txt");
               while(file.hasNext())
               {
                  
                   @SuppressWarnings("resource")
                   Scanner line = new Scanner(file.nextLine());
   int totalSum = 0;
   while (line.hasNext()) {
   int number = line.nextInt();
   totalSum += number;
   fout.print(number);
   if (line.hasNext())
   {
   fout.print("+");
   }
   }
   fout.println("=" + totalSum);
   }
           }
           catch (FileNotFoundException e)
           {
              
               System.out.println("NOT FOUND");
           }
           finally
           {
               if(fout!=null)fout.close();
           }
          
           if(file!=null)file.close();
          
       }
      
      
  
  
public void clearInput()
{
txtInFile.setText(""); txtOutFile.setText("");

}
@Override
public void actionPerformed(ActionEvent e)
{
   if(e.getSource() == btnInFile)
   {
       JFileChooser jfcInFile = new JFileChooser();
       if(jfcInFile.showOpenDialog(this) != JFileChooser.CANCEL_OPTION)
       {
           File inFile = jfcInFile.getSelectedFile();
           txtInFile.setText(inFile.getAbsolutePath());
       }
       else
       {
          
       }
   }
   if(e.getSource() == btnProcess)
   {
       File file = new File(txtInFile.getText());
       try
       {
           Scanner fin = new Scanner(file);
       }
       catch (FileNotFoundException e1)
       {
          
           e1.printStackTrace();
       }
   }
  
}
}

In: Computer Science

Is the following system in a safe state? Process Allocation Max Available A B C A...

Is the following system in a safe state?

Process Allocation Max Available
A B C A B C A B C

P0 1 1 0 3 2 0 3 2 2
P1 0 0 1 3 2 2
P2 2 1 0 2 2 1

how to answer this kind of question.

In: Computer Science

Consider the following class TestScores. All the methods have direct access to the scores array. Please...

Consider the following class TestScores. All the methods have direct access to the scores array. Please type in the answers here.

TestScores

  • SIZE : int //Size of the array

  • scores : int [ ]

  • TestScores()       

  • findMax() : int

  • findMin() : int

  • findScore(value: int) : bool

  • countScores(): int


  1. Write the constructor method. It fills the array with random number from 0 -100. Find below the code to get you started.

   public TestScores ()

  {

    Random rand = new Random();

    for(int i = 0; i < SIZE ; i++)

        {

           scores[i] = rand.nextInt(101);

        }

  }


  1. Finding the maximum value in an array. Write the method findMax. It returns the maximum value in the array.


  1. Finding the minimum value in an array. Write the method findMin. It returns the minimum value in the array.




  1. Write the method countScores. The method returns the number of exams where the score is greater or equal to 90. This is an example of a linear search.



  1. Write the method called findScore that accepts one int value. The method should check if the value exists in the array and if it does it returns true. Otherwise, the method should return false.

In: Computer Science

Can I have this answer in a screenshot of the python software? In the game of...

Can I have this answer in a screenshot of the python software?

In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are many ways to win: (1, 6), (2, 5), and soon. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people's eyes glaze over at the first mention of mathematics “wins $4”.

      Your challenge is to write a program that demonstrates the futility of playing the game. Your Python program should take as input the amount of money that the player wants to put into the pot, and play the game until the pot is empty.

            The program should have at least TWO functions (Input validation and Sum of the dots of user’s two dice). Like the program 1, your code should be user-friendly and able to handle all possible user input. The game should be able to allow a user to ply as many times as she/he wants.

            The program should print a table as following:

      Number of rolls            Win or Loss                 Current value of the pot

                  1                                 Put                                    $10

                  2                                 Win                                  $14

                  3                                 Loss                                  $11

                  4

                  ##                              Loss                                  $0

        You lost your money after ## rolls of play.

        The maximum amount of money in the pot during the playing is $##.

        Do you want to play again?

      At that point the player’s pot is empty (the Current value of the pot is zero), the program should display the number of rolls it took to break the player, as well as maximum amount of money in the pot during the playing.

        Again, add good comments to your program.

        Test your program with $5, $10 and $20.

In: Computer Science

We can install Ad-blocking software to enable our web browsers let us visit different websites while...

We can install Ad-blocking software to enable our web browsers let us visit different
websites while not viewing pop-up advertisements available on those websites. Give
reasons in favor or against the following proposition.
"Different companies provide you with free access to those websites because they use the advertisements as a mean of revenues. Hence you as a user violate an implicit
social contract by installing Ad-blocking software on your browser."

*please give me you opinion not from the internet.

In: Computer Science

java: Sample output: Aoccdrnig to reacresh at an Elingsh uinervtisy, it deos not mttaer in waht...

java:

Sample output: Aoccdrnig to reacresh at an Elingsh uinervtisy, it deos not mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer are in the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae we do not raed ervey lteter by it slef but the wrod as a wlohe and the biran fguiers it out aynawy.

PROGRAM DESCRIPTION: In this assignment, you will read an unspecified number of lines of text from STDIN. Input is terminated with EOF (ctrl-d for keyboard input). Your only output, to STDOUT, will echo the input except that the letters of any word with more than three characters will be randomly shuffled (except for the first and last letters). Don't scramble any punctuation, and you may assume that punctuation will only occur at the end of a word. Any word will have, at most, one punctuation character. Punctuation does not count towards the length of the word. You may also assume that each word will be separated by one space and that a line will have no leading or trailing whitespace. Blank lines are allowable. You must preserve the newlines (output must have the same number of lines and the same number of words on each line as when input.) (A word, here, is defined as a sequence of alphanumeric characters delimeted by whitespace.) For this assignment you must code the shuffle algorithm as described in class, and not a library shuffle function.

Sample input:According to research at an English university, it does not matter in what order the letters in a word are, the only important thing is that the first and last letter are in the right place. The rest can be a total mess and you can still read it without a problem. This is because we do not read every letter by itself but the word as a whole and the brain figures it out anyway.

Sample run:

This is a test
This is a tset
Hello, how are you today?
Hlleo, how are you toady?

SUGGESTIONS

You may find it easiest to complete this program in stages. Begin by writing a program that echos input lines of text to output. Then add the ability (a function) to break a line of text into individual words, finally add the scrambling feature (another function) for a word.

In: Computer Science

Write a recursive method to find the smallest int in an unsorted array of numbers. int[]...

Write a recursive method to find the smallest int in an unsorted array of numbers.

int[] findMin = { 0, 1, 1, 2, 3, 5, 8, -42, 13, 21, 34, 55, 89 };

System.out.printf("Array Min: %d\n", arrayMin(findMin, 0)

public static int arrayMin(int[] data, int position) { ??? }

everything I've tried doesn't return the -42 like it should, somehow I think I end up returning a count of the search or something like that and I'm not sure where I'm going wrong. Thanks for the help.

In: Computer Science

Min. 175 words Discuss the structure of a Java™ program including files and arrays with GUI....

Min. 175 words

Discuss the structure of a Java™ program including files and arrays with GUI.

How do iterative structures differ from conditional structures in OOP?

Provide an example.

In: Computer Science

1-Give a BNF grammar (do not use EBNF) for the language that generates the set of...

1-Give a BNF grammar (do not use EBNF) for the language that generates the set of all strings consisting of the keyword begin, followed by zero or more statements with a semicolon after each one, followed by the keyword end. Use the non-terminal for statements, and do not give productions for it.

2-Give a BNF grammar (do not use EBNF) for the language that generates the set of all strings consisting of the keyword begin, followed by one or more statements with a semicolon after each one, followed by the keyword end. Use the non-terminal for statements, and do not give productions for it.

3-Give a BNF grammar (do not use EBNF) for the set of all strings consisting of zero or more as, with a comma between each a and the next. (There should be no comma before the first or after the last.)

4-Give a BNF grammar (do not use EBNF) for the set of all strings consisting of an open bracket (the symbol [) followed by a list of zero or more digits separated by commas, followed by a closing bracket (the symbol ]).

In: Computer Science

Using a text editor or IDE, copy the following list of names and grade scores and...

Using a text editor or IDE, copy the following list of names and grade scores and save it as a text file named scores.txt:
Name, Score
Joe Besser,70
Curly Joe DeRita,0
Larry Fine,80
Curly Howard,65
Moe Howard,100
Shemp Howard,85
Create a JavaScript program of the files that display high, low, and average scores based on input from scores.txt. Verify that the file exists and then use string functions/methods to parse the file content and add each score to an array. Display the array contents and then calculate and display the high, low, and average score. Format the average to two decimal places. Note that the program must work for any given number of scores in the file. Do not assume there will always be six scores and use Node Js as IDE.

In: Computer Science

Imagine a set Implementation which uses heaps, instead of binary search trees. How would performance of...

Imagine a set Implementation which uses heaps, instead of binary search trees. How would performance of such a data structure differ from a set Implementation using Balanced Trees(AVL or Red/Black Trees)? Performance meaning RunTime(Time complexity) of the methods in the data structure ex. add()

In: Computer Science

Given the class below, which answer choice would be an implementation of the default constructor (without...

Given the class below, which answer choice would be an implementation of the default constructor (without an initialization list)?

class MyInteger {
    private:
       int num;
    public:
       MyInteger();
       MyInteger(int newint);
       void setInt(int newint);
       int getInt();
       int operator[](int index);
};

  

MyInteger::MyInteger(int newNum) { num = newNum; }

   

MyInteger::MyInteger() { num = 0; }

   

MyInteger::MyInteger(int newNum = 0) { num = newNum; }

   

MyInteger::MyInteger(int newNum) : num{0} {;}

   

MyInteger::MyInteger(int newNum = 0) : num{0} {;}

   

MyInteger::MyInteger() : num{0} {;}

   

MyInteger::MyInteger(newNum) { num = newNum; }

In: Computer Science

Create a Factorial application that prompts the user for a number and then displays its factorial....

Create a Factorial application that prompts the user for a number and then displays its factorial. The factorial of a number is the product of all the positive integers from 1 to the number. For example, 5! = 5*4*3*2*1. I also need an algorithm and pseudocode in java please

In: Computer Science

C++!!! PLEASE PAY ATTENTION TO THE BOLD TEXT VERY WELL. THANK YOU Write a program that...

C++!!!

PLEASE PAY ATTENTION TO THE BOLD TEXT VERY WELL. THANK YOU

Write a program that creates three identical arrays, list1, list2, and list3, of 5000 elements. The program then sorts list1 using bubble sort, list2 using selection sort, and list3 using insertion sort and outputs the number of comparisons and item assignments made by each sorting algorithm.

Please use the file names listed below since your file will have the following components:

Ch18_Ex15.cpp

searchSortAlgorithms.h

In: Computer Science

***USING C++*** (a) Write a program that reads a text file in which each line in...

***USING C++***

(a) Write a program that reads a text file in which each line in the file consists of a first name, a last name, following by 4 grades (double types) like Tim Hanes 78.3 98.0 80.5 72.3 The program must read every line of the text file, find the average of the 4 grades then print the names followed by the averages (one name per line) in a second file as well as on the monitor. Create the text file with at least 5 entries with the format given in part (a). Give the absolute path of the file in your computer. Test your program in part 2(a) on this file.

In: Computer Science