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
An air-standard dual cycle has a compression ratio of 9.1 and displacement of Vd = 2.2 L. At the beginning of compression, p1 =
jok3333 [9.3K]

Answer:

a) T₂ is 701.479 K

T₃ is 1226.05 K

T₄ is 2350.34 K

T₅ is 1260.56 K

b) The net work of the cycle in kJ is 2.28 kJ

c) The power developed is 114.2 kW

d) The thermal efficiency, \eta _{dual} is 53.78%

e) The mean effective pressure is 1038.25 kPa

Explanation:

a) Here we have;

\frac{T_{2}}{T_{1}}=\left (\frac{v_{1}}{v_{2}}  \right )^{\gamma -1} = \left (r  \right )^{\gamma -1} = \left (\frac{p_{2}}{p_{1}}  \right )^{\frac{\gamma -1}{\gamma }}

Where:

p₁ = Initial pressure = 95 kPa

p₂ = Final pressure =

T₁ = Initial temperature = 290 K

T₂ = Final temperature

v₁ = Initial volume

v₂ = Final volume

v_d = Displacement volume =

γ = Ratio of specific heats at constant pressure and constant volume cp/cv = 1.4 for air

r = Compression ratio = 9.1

Total heat added = 4.25 kJ

1/4 × Total heat added = c_v \times (T_3 - T_2)

3/4 × Total heat added = c_p \times (T_4 - T_3)

c_v = Specific heat at constant volume = 0.718×2.821× 10⁻³

c_p = Specific heat at constant pressure = 1.005×2.821× 10⁻³

v₁ - v₂ = 2.2 L

\left \frac{v_{1}}{v_{2}}  \right =r  \right = 9.1

v₁ = v₂·9.1

∴ 9.1·v₂ - v₂ = 2.2 L  = 2.2 × 10⁻³ m³

8.1·v₂ = 2.2 × 10⁻³ m³

v₂ = 2.2 × 10⁻³ m³ ÷ 8.1 = 2.72 × 10⁻⁴ m³

v₁ = v₂×9.1 = 2.72 × 10⁻⁴ m³ × 9.1 = 2.47 × 10⁻³ m³

Plugging in the values, we have;

{T_{2}}= T_{1} \times \left (r  \right )^{\gamma -1}  = 290 \times 9.1^{1.4 - 1} = 701.479 \, K

From;

\left (\frac{p_{2}}{p_{1}}  \right )^{\frac{\gamma -1}{\gamma }}= \left (r  \right )^{\gamma -1} we have;

p_{2} = p_{1}} \times \left (r  \right )^{\gamma } = 95 \times \left (9.1  \right )^{1.4} = 2091.13 \ kPa

1/4×4.25 =  0.718 \times 2.821 \times  10^{-3}\times (T_3 - 701.479)

∴ T₃ = 1226.05 K

Also;

3/4 × Total heat added = c_p \times (T_4 - T_3) gives;

3/4 × 4.25 = 1.005 \times 2.821 \times  10^{-3} \times (T_4 - 1226.05) gives;

T₄ = 2350.34 K

\frac{T_{4}}{T_{5}}=\left (\frac{v_{5}}{v_{4}}  \right )^{\gamma -1} = \left (\frac{r}{\rho }  \right )^{\gamma -1}

\rho = \frac{T_4}{T_3} = \frac{2350.34}{1226.04} = 1.92

T_{5} =  \frac{T_{4}}{\left (\frac{r}{\rho }  \right )^{\gamma -1}}= \frac{2350.34 }{\left (\frac{9.1}{1.92 }  \right )^{1.4-1}} =1260.56 \ K

b) Heat rejected =  c_v \times (T_5 - T_1)

Therefore \ heat \ rejected =  0.718 \times 2.821 \times  10^{-3}\times (1260.56 - 290) = 1.966 kJ

The net work done = Heat added - Heat rejected

∴ The net work done = 4.25 - 1.966 = 2.28 kJ

The net work of the cycle in kJ = 2.28 kJ

c) Power = Work done per each cycle × Number of cycles completed each second

Where we have 3000 cycles per minute, we have 3000/60 = 50 cycles per second

Hence, the power developed = 2.28 kJ/cycle × 50 cycle/second = 114.2 kW

d)

Thermal \ efficiency, \, \eta _{dual} =  \frac{Work \ done}{Heat \ supplied} = \frac{2.28}{4.25} \times 100 = 53.74 \%

The thermal efficiency, \eta _{dual} = 53.78%

e) The mean effective pressure, p_m, is found as follows;

p_m = \frac{W}{v_1 - v_2} =\frac{2.28}{2.2 \times 10^{-3}} = 1038.25 \ kPa

The mean effective pressure = 1038.25 kPa.

3 0
4 years ago
Solar ovens use heat from the Sun to cook food. They work on a principle similar to that of solar panels used to heat homes. Wha
marishachu [46]

Explanation:

Absorption of the sun's energy (heat) in solar cooking is best achieved when a surface is dark in color, thus the most common solar oven interiors are usually black in color as well as the color of the cookware used for cooking the food. Dark colors absorb the heat, whereas light colors do not absorb heat well.

Metal reflectors should be positioned around the oven to maximize light input to be the most effective.

4 0
3 years ago
Read 2 more answers
What are materials engineers trying to discover when they study different materials?
coldgirl [10]
What do materials science and engineering graduates do?
Almost two-thirds of materials science graduates are in employment six months after graduation.

The skills developed during a materials science degree allow graduates enter a range of sectors, including working as engineering professionals and in design and marketing roles.

Destination Percentage
Employed 60.4
Further study 24.5
Working and studying 5.1
Unemployed 4
Other 6.1
Graduate destinations for materials science and engineering
Type of work Percentage
Engineering and building 23.9
Marketing, PR and sales 11.9
Business, HR and financial 11.7
Technicians and other professionals 10
Other 42.5
5 0
3 years ago
Read 2 more answers
Steam enters a turbine at 8000 kPa, 440oC. At the exit, the pressure and quality are 150 kPa and 0.19, respectively.
levacccp [35]

Answer:

\dot W_{out} = 3863.98\,kW

Explanation:

The turbine at steady-state is modelled after the First Law of Thermodynamics:

-\dot Q_{out} -\dot W_{out} + \dot m \cdot (h_{in}-h_{out}) = 0

The specific enthalpies at inlet and outlet are, respectively:

Inlet (Superheated Steam)

h_{in} = 3353.1\,\frac{kJ}{kg}

Outlet (Liquid-Vapor Mixture)

h_{out} = 890.1\,\frac{kJ}{kg}

The power produced by the turbine is:

\dot W_{out}=-\dot Q_{out} + \dot m \cdot (h_{in}-h_{out})

\dot W_{out} = -2.93\,kW + (1.57\,\frac{kg}{s} )\cdot (3353.1\,\frac{kJ}{kg} - 890.1\,\frac{kJ}{kg} )

\dot W_{out} = 3863.98\,kW

8 0
3 years ago
In this homework problem we’ll begin completing an implementation of SimpleList that uses a linked list of Item objects internal
balu736 [363]

The solution contains multiple java files. The initial linked list is 10 20 30 40 . The modified list is 20 30 40

<u>Explanation</u>

//Define the interface SimpleList;

public interface SimpleList

{

   public Object get (int index);

   public void set (int index, Object element);

   public void add (int index, Object element);

   public Object remove(int index);

   public int size();

}

SimpleLinkedList.java:

//Define the class SimpleLinkedList that implements the SimpleList.

public class SimpleLinkedList implements SimpleList

{

   //Define the Item class.

   class Item

   {

       Object value;

       Item next;          

       Item (Object setValue, Item setNext)

       {

           value = setValue;

           next = setNext;

       }

   }      

   protected Item start;

   protected int currentSize;      

   //Define the default constructor.

   public SimpleLinkedList()

   {

       currentSize = 0;

       start = null;

   }      

   //Define the parameterized constructor.

   SimpleLinkedList(Object[] values)

   {

       currentSize = 0;          

       //Start the loop and call the add method.

       for(int i = 0; i<values.length;i++)

       {

           add(i, values[i]);

       }

   }      

   //Define the method to return the object

   // at the given index.

   atOverride

   public Object get (int index)

   {

       //Call the getItem() method and return it's value.

       return getItem(index).value;

   }      

   //Define the set() method.

   atOverride

   public void set (int index, Object element)

   {

       if (index < 0 || index >= currentSize)

       {

           return;

       }

       int currentIndex = 0;          

       for (Item current = start; current != null; current = current.next)

       {

           if (currentIndex == index)

           {

               current.value = element;

               break;

           }

           currentIndex++;

       }

   }    

   //Define the getItem() method.

   protected Item getItem(int index)

   {

       if (index < 0 || index >= currentSize)

       {

           return null;

       }      

       int currentIndex = 0;        

       for (Item current = start; current != null; current = current.next)

       {

           if (currentIndex == index)

           {

               return current;

           }

           currentIndex++;

       }

       return null;

   }      

   //Define the add() method.

   atOverride

   public void add (int index, Object toAdd)

   {

       if (index == 0)

       {

           start = new Item (toAdd, start);

           currentSize++;

           return;

       }        

       Item previousItem = getItem(index - 1);        

       if(previousItem == null)

       {

           return;

       }          

       Item newItem = new Item(toAdd, previousItem.next);

       previousItem.next = newItem;

       currentSize++;

   }      

   //Define the method to return the size of the linked list.

   atOverride

   public int size ()

   {

       return currentSize;

   }      

   //Define the method to remove an index from the linked list.

   atOverride

   public Object remove (int index) {

       // TODO Auto-generated method stub

       return null;

   }      

}

YourSimpleLinkedList.java:

//Define the YourSimpleLinkedList class.

public class YourSimpleLinkedList extends SimpleLinkedList

{

   //Define the default constructor.s

   public YourSimpleLinkedList()

   {

       super();

   }      

   //Define the parameterized constructor.

   YourSimpleLinkedList(Object[] values)

   {

       super(values);

   }

   //Define the method to remove an index.

   at Override

   public Object remove(int index)

   {

       //Return null if the index is out of range.

       if (index < 0 || index >= currentSize)

       {

           return null;

       }        

       //Set the start Item if the first value

       // is to be removed.

       if (index == 0)

       {

           //Store the value of the node to be removed.

           Object temp = start.value;

           

           //Set the start Item.

           start = start.next;

           

           //Update the size of the linked list and return

           // the deleted value.

           currentSize--;

           return temp;

       }        

       //Initialize the required variables.

       int currentIndex = 0;

       Item current = start;

       Item prev = start;        

       //Start the loop to traverse the list.

       while (current != null)

       {

           //Check the index value.

           if (currentIndex == index)

           {

               //Store the value to be deleted.

               Object temp = current.value;                

               //Set the next pointer.

               prev.next = current.next;                  

               //Update the size of the linked list and return

               // the deleted value.

               currentSize--;

               return temp;

           }            

           //Update the values.

           currentIndex++;

           prev = current;

           current = current.next;

       }

       return null;

   }

}

Main.java:

public class Main

{

   public static void main(String[] args)

   {

       //Create a list of objects.

       Object [] values = {10, 20, 30, 40};          

       //Create an object of the YourSimpleLinkedList class.

       YourSimpleLinkedList myList = new YourSimpleLinkedList(values);        

       //Display the initial list.

       System.out.print("The initial linked list is ");

       for (int i=0;i<myList.size();i++)

       {

           System.out.print(myList.get(i) + " ");

       }        

       //Remove an index from the list.

       myList.remove(0);        

       //Display the modified list.

       System.out.println();

       System.out.print("The modified list is ");

       for (int i=0;i<myList.size();i++)

       {

           System.out.print(myList.get(i) + " ");

       }

   }  

}

5 0
4 years ago
Other questions:
  • Write down the types of the Hydraulic Cylinders?
    7·1 answer
  • Create a document that includes a constructor function named Company in the document head area. Include four properties in the C
    7·1 answer
  • 4. What are the basic scientific principles the engineers who designed the digital scales would have needed to understand to des
    5·1 answer
  • What does it mean if a manufacturing company "retools"?
    7·2 answers
  • Consider the formation of p-nitrophenol from p-nitrophenyl trimethyl acetate. The process is known as enzymatic hydrolysis and i
    7·1 answer
  • Giving away points hope they help with your questions
    14·1 answer
  • WHICH OF THIS PLS FAST!!!
    5·1 answer
  • 1 . How are encoders used in the measurement of speed? Explain the encoder with a neat diagram.
    10·1 answer
  • A 1.5-kg specimen of a 90 wt% Pb-10 wt% Sn alloy (Animated Figure 9.8) is heated to 250°C; at this temperature it is entirely an
    9·1 answer
  • What is the difference between absorbed wavelengths and reflected wavelengths?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!