1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
HACTEHA [7]
4 years ago
14

Please add comments to your program to explain it. Thank you!

Engineering
1 answer:
Step2247 [10]4 years ago
8 0

Answer / Explanation:

(1) We should first understand that the input filename are passed in as the first command arguments at command line, respectively.

To do this, we import the data file:

So we have,

import java.io.*;

/**

*  Makes a copy of a file.  The original file and the name of the

*  copy must be given as command-line arguments.  In addition, the

*  first command-line argument can be "-f"; if present, the program

*  will overwrite an existing file; if not, the program will report

*  an error and end if the output file already exists.  The number

*  of bytes that are copied is reported.

*/

public class CopyFile {

  public static void main(String[] args) {

     String sourceName;   // Name of the source file,  

                          //    as specified on the command line.

     String copyName;     // Name of the copy,  

                          //    as specified on the command line.

     InputStream source;  // Stream for reading from the source file.

     OutputStream copy;   // Stream for writing the copy.

     boolean force;  // This is set to true if the "-f" option

                     //    is specified on the command line.

     int byteCount;  // Number of bytes copied from the source file.

     

     /* Get file names from the command line and check for the  

        presence of the -f option.

(2)   If the command line is not one

        of the two possible legal forms, print an error message and  

        end this program. */

   

     if (args.length == 3 && args[0].equalsIgnoreCase("-f")) {

        sourceName = args[1];

        copyName = args[2];

        force = true;

     }

     else if (args.length == 2) {

        sourceName = args[0];

        copyName = args[1];

        force = false;

     }

     else {

        System.out.println(

                "Usage:  java CopyFile <source-file> <copy-name>");

        System.out.println(

                "    or  java CopyFile -f <source-file> <copy-name>");

        return;

     }

     

     /* Create the input stream.  If an error occurs, end the program. */

     

     try {

        source = new FileInputStream(sourceName);

     }

     catch (FileNotFoundException e) {

        System.out.println("Can't find file \"" + sourceName + "\".");

        return;

     }    

     /* If the output file already exists and the -f option was not

        specified, print an error message and end the program. */

   

     File file = new File(copyName);

     if (file.exists() && force == false) {

         System.out.println(

              "Output file exists.  Use the -f option to replace it.");

         return;  

    }      

     /* Create the output stream.  If an error occurs, end the program. */

     try {

        copy = new FileOutputStream(copyName);

     }

     catch (IOException e) {

        System.out.println("Can't open output file \"" + copyName + "\".");

        return;

     }

     

   (3)   /* Copy one byte at a time from the input stream to the output

        stream, ending when the read() method returns -1 (which is  

        the signal that the end of the stream has been reached).  If any  

        error occurs, print an error message.  Also print a message if  

        the file has been copied successfully.  */  

     byteCount = 0;

     

     try {

        while (true) {

           int data = source.read();

           if (data < 0)

              break;

           copy.write(data);

           byteCount++;

        }

        source.close();

        copy.close();

        System.out.println("Successfully copied " + byteCount + " bytes.");

     }

     catch (Exception e) {

        System.out.println("Error occurred while copying.  "

                                  + byteCount + " bytes copied.");

        System.out.println("Error: " + e);

     }    

  }  // end main()  

} // end class CopyFile

You might be interested in
20. Antifreeze spills should be contained with:
denis23 [38]

Answer:

D

Explanation:

the sponge's and rags are meant for this exact purpose

3 0
3 years ago
List two reasons why machined parts often require a high degree of precision.
Gekata [30.6K]

Explanation:

Precision machining is a subtractive process used in cases where material needs to be removed from a raw product to create the finished product. Precision machining can be used to create a wide variety of products, items, and parts for any number of different objects and materials. These parts usually require tight tolerances variation from nominal dimensions and from part to part, which means that there is not much room for error in the production of the piece. Repeatability and well-controlled tolerances are hallmarks of precision machining. Components, parts and finished durable products that are designed to maintain extremely tight tolerance margins and a high degree of durability are essential and common drivers for utilization of precision machining. For example, parts that need to work together as part of a machine may need to always align within a certain margin of 0.01mm to 0.05mm. Precision engineering and machining help to ensure these parts can not only be made precisely but can be produced with this level of accuracy over and over again.

3 0
3 years ago
I have to create a mask and i would like some ideas of how i could create it or yall have any ideas?
Paul [167]

Answer:

get a mask mold and the strips of the stuff than gets sticky when it's wet. Do 2 or 3 layers of it on the mold wait a few days for it to dry and then design it

Explanation:

4 0
3 years ago
Read 2 more answers
A HSS152.4 × 101.6 × 6.4 structural steel [E = 200 GPa] section (see Appendix B for crosssectional properties) is used as a colu
Temka [501]

Answer:

(a) 126.66 kN (b) 31.665 kN (c) 258.49 kN (d) 506.64 kN

Explanation:

Solution

Given

A HSS152.4 × 101.6 × 6.4 structural steel is used as a column

Actual length of the column , L= 6 m

The elasticity modules, E = 200 GPa

The factor of safety with respect to failing buckling . F.S =2

Geometric properties  of structural steel shapes for, A HSS152.4 × 101.6 × 6.4

the moment of inertial about y axis Iy =4 .62 * 10^ 6 mm ^4

For

(a)  If the end condition is pinned - pinned

The effective  length factor, K =1

The critical buckling load , Pcr = π²EI/(KL)²

Pcr = π² * 200 * 10 ^3 * 4.62 * 10 ^6/( 1* 6* 10 ^3)

= 253319.85N

= 253.32N

The maximum safe load , Pallow = 253.32 /2 = 126.66kN

hence, the maximum safe for the column is 126.66kN

(b)If the end condition is  fixed free-free

the effective length factor, K= 2

The critical buckling load , Pcr = π²EI/(KL)²

Pcr = π² * 200 * 10 ^3 * 4.62 * 10 ^6/( 2 * 6 * 10 ^3)²

= 63329.96N

=63.33kN

The maximum safe load,  P allow = Pcr/F.S

P allow = 63.33/2

31.665 kN

Therefore the maximum safe for the column is 31.665 kN

(c) If the end condition is fixed- pinned

The effective  length factor K =0.7

The critical buckling load , Pcr = π²EI/(KL)²

Pcr = π² * 200 * 10 ^3 * 4.62 * 10 ^6/( 0.7 * 6 * 10 ^3)²

=516979.2 8N

=516.98 kN

The maximum safe load,  P allow = Pcr/F.S

P allow = 516.98 kN/2

=258.49 kN

Therefore the maximum safe for the column is 258.49 kN

(d) If the end condition is fixed -fixed

The effective factor, K =0.5

The critical buckling load , Pcr = π²EI/(KL)²

Pcr = π² * 200 * 10 ^3 * 4.62 * 10 ^6/( 0.5 * 6 * 10 ^3)²

=1013279.4 N

=1013.28 kN

The maximum safe load,  P allow = Pcr/F.S

P allow = 1013.28 / 2

= 506.64 kN

P allow = 506.64 kN

Therefore the maximum safe for the column is 506.64 kN

8 0
4 years ago
An urn contains r red, w white, and b black balls. Which has higher entropy, drawing k ~2 balls from the urn with replacement or
svetlana [45]

Answer:

The case with replacement has higher entropy

Explanation:

The complete question is given:

'Drawing with and without replacement. An urn contains r red,  w white  and b black balls. Which has higher entropy, drawing k ≥ 2 balls from the urn with  replacement or without replacement?'

Solution:

- n drawing is the same irrespective of whether there is replacement or not.

-  X to denotes drawing from an urn with r red balls,  w white balls and b black balls. So, n = b + r +  w.

We have:

                                      p_X(cr) = r / n

                                      p_X(cw) = w / n

                                      p_X(cb) = b / n

- Now, if  Xi is the ith drawing with replacement then Xi are independent and p_Xi (x) = pX(x) for x e ( cr , cb , cw ).

- Now, let  Yi be the ith drawing with replacement where Yi are not independent p_Yi (x) = pX(x) for x ∈ X.

- To see this, note  Y1 =  X and assume it is true for  Yi and consider  Yi+1:

    p_Y(i+1) (cr) = p(Y(i+1),Yi).(cr, cr) + p(Y(i+1),Yi).(cr, cw) + p(Y(i+1),Yi).(cr, cb)

= pY(i+1)|Yi  (cr|cr)*pYi  (cr) +pY(i+1)|Yi  (cr|cw)*pYi (cw) + pY(i+1)|Yi  (cr|cb)*pYi (cb)

= r*( r - 1 )/n*(n-1) + w*r/n*(n-1) + b*r/n*(n-1) = r / n =  p_X(cr)

- This means, using the chain rule and the conditioning theore m:

H(Y1, Y2, . . . , Yn) =  H(Y1) +  H(Y2|Y1) +  H(Y3|Y2, Y1) + ... H(Yn|Yn−1, . . . , Y1)

=< SUM H(Yi) = n*H(X) =  H(X1, X2, . . . , Xn)

- with equality if and only if the  Yi were independent:

                          H(Y1, Y2, . . . , Yn) < H(X1, X2, . . . , Xn)

Answer: The case with replacement has higher entropy

   

4 0
4 years ago
Other questions:
  • why are apartments called apartments if there together? and why are buildings called buildings if there already built? hmmmm
    7·1 answer
  • Explain the conductivity results observed for ionic compounds in the solid state and in aqueous solution.i.Solid ionic compounds
    12·1 answer
  • What are the x and y coordinates of the centroid of the area?
    10·1 answer
  • Summary: Given integer values for red, green, and blue, subtract the gray from each value. Computers represent color by combinin
    15·2 answers
  • Consider the two wood pieces that are connected by a velcro as indicated below. The block is subjected to a tension force P and
    6·2 answers
  • Complete the following sentence.
    5·1 answer
  • A plastic molding machine produces a product whose annual demand is in the millions.
    15·1 answer
  • A manometer is used to measure the air pressure in a tank. The fluid used has a specific gravity of 1.25, and the differential h
    13·1 answer
  • Determine the specific weight of air when the temperature is 100∘F and the absolute pressure is 60 psi . The gas constant for th
    9·1 answer
  • Name four emerging technologies that could significantly impact how the construction industry conducts business.
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!