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
pickupchik [31]
3 years ago
6

IN JAVA,

Engineering
1 answer:
Citrus2011 [14]3 years ago
8 0

Answer:

Explanation:

Code:

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class Knapsack {

 

  public static void knapsack(int wk[], int pr[], int W, String ofile) throws IOException

  {

      int i, w;

      int[][] Ksack = new int[wk.length + 1][W + 1];

     

      for (i = 0; i <= wk.length; i++) {

  for (w = 0; w <= W; w++) {

  if (i == 0 || w == 0)

  Ksack[i][w] = 0;

  else if (wk[i - 1] <= w)

  Ksack[i][w] = Math.max(pr[i - 1] + Ksack[i - 1][w - wk[i - 1]], Ksack[i - 1][w]);

  else

  Ksack[i][w] = Ksack[i - 1][w];

  }

  }

     

      int maxProfit = Ksack[wk.length][W];

      int tempProfit = maxProfit;

      int count = 0;

      w = W;

      int[] projectIncluded = new int[1000];

      for (i = wk.length; i > 0 && tempProfit > 0; i--) {

         

      if (tempProfit == Ksack[i - 1][w])

      continue;    

      else {

          projectIncluded[count++] = i-1;

      tempProfit = tempProfit - pr[i - 1];

      w = w - wk[i - 1];

      }

     

      FileWriter f =new FileWriter("C:\\Users\\gshubhita\\Desktop\\"+ ofile);

      f.write("Number of projects available: "+ wk.length+ "\r\n");

      f.write("Available employee work weeks: "+ W + "\r\n");

      f.write("Number of projects chosen: "+ count + "\r\n");

      f.write("Total profit: "+ maxProfit + "\r\n");

     

  for (int j = 0; j < count; j++)

  f.write("\nProject"+ projectIncluded[j] +" " +wk[projectIncluded[j]]+ " "+ pr[projectIncluded[j]] + "\r\n");

  f.close();

      }    

  }

 

  public static void main(String[] args) throws Exception

  {

      Scanner sc = new Scanner(System.in);

      System.out.print("Enter the number of available employee work weeks: ");

      int avbWeeks = sc.nextInt();

      System.out.print("Enter the name of input file: ");

  String inputFile = sc.next();

      System.out.print("Enter the name of output file: ");

      String outputFile = sc.next();

      System.out.print("Number of projects = ");

      int projects = sc.nextInt();

      int[] workWeeks = new int[projects];

      int[] profit = new int[projects];

     

      File file = new File("C:\\Users\\gshubhita\\Desktop\\" + inputFile);

  Scanner fl = new Scanner(file);

 

  int count = 0;

  while (fl.hasNextLine()){

  String line = fl.nextLine();

  String[] x = line.split(" ");

  workWeeks[count] = Integer.parseInt(x[1]);

  profit[count] = Integer.parseInt(x[2]);

  count++;

  }

 

  knapsack(workWeeks, profit, avbWeeks, outputFile);

  }

}

Console Output:

Enter the number of available employee work weeks: 10

Enter the name of input file: input.txt

Enter the name of output file: output.txt

Number of projects = 4

Output.txt:

Number of projects available: 4

Available employee work weeks: 10

Number of projects chosen: 2

Total profit: 46

Project2 4 16

Project0 6 30

You might be interested in
As Becky was driving "Old Betsy," the family station wagon, the engine finally quit, being worn out after 171,000 miles. It can
andriy [413]

Answer:

1) 4.361 x 10 raised to power 8 revolutions

2) 1.744 x 10 raised to power 9 firings

3) 2.18 x 10 raised to power 8  intake strokes

Explanation:

The step by step explanation is as shown in the attachment

8 0
3 years ago
Why or why not the following materials will make good candidates for the construction of
zvonat [6]

Answer:

Answer explained below

Explanation:

3.] a] A turbine blade is the individual component which makes up the turbine section of a gas turbine. The blades are responsible for extracting energy from the high temperature, high pressure gas produced by the combustor.

The turbine blades are often the limiting component of gas turbines. To survive in this difficult environment, turbine blades often use exotic materials like superalloys and many different methods of cooling, such as internal air channels, boundary layer cooling, and thermal barrier coatings. The blade fatigue failure is one of the major source of outages in any steam turbines and gas turbines which is due to high dynamic stresses caused by blade vibration and resonance within the operating range of machinery.

To protect blades from these high dynamic stresses, friction dampers are used.

b] Thermal barrier coatings (TBC) are highly advanced materials systems usually applied to metallic surfaces, such as on gas turbine or aero-engine parts, operating at elevated temperatures, as a form ofexhaust heat management.

These 100μm to 2mm coatings serve to insulate components from large and prolonged heat loads by utilizing thermally insulating materials which can sustain an appreciable temperature difference between the load-bearing alloys and the coating surface.

In doing so, these coatings can allow for higher operating temperatures while limiting the thermal exposure of structural components, extending part life by reducing oxidation and thermal fatigue.

In conjunction with active film cooling, TBCs permit working fluid temperatures higher than the melting point of the metal airfoil in some turbine applications.

Due to increasing demand for higher engine operation (efficiency increases at higher temperatures), better durability/lifetime, and thinner coatings to reduce parasitic weight for rotating/moving components, there is great motivation to develop new and advanced TBCs.

3 0
3 years ago
if you had 100 B size sheets and you cut them into A size sheets, how many sheets of A size paper would you have
castortr0y [4]

Answer:

200

Explanation:

A size sheets (also known as letter size) are 8.5 inches by 11 inches.

B size sheets (also known as ledger size) are 11 inches by 17 inches.

One B size sheet is twice as large as a A size sheet.  So if you have 100 B size sheets and cut each one in half, you'll get 200 A size sheets.

8 0
3 years ago
Which of the following can effect LRO?
aleksley [76]

Answer:

The lunar radiation environment, allowing scientists to determine potential impacts to astronauts and other life. It also will test models on the effects of radiation and measure radiation absorption by a type of plastic that is like human tissue. The results could aid in the development of protective technologies to help keep future lunar crew members safe. CRaTER was built and developed by Boston University and the Massachusetts Institute of Technology in Boston.

7 0
2 years ago
Which of the following elements of the CIA triad refers to maintaining and assuring the accuracy of data over its life-cycle?
kenny6666 [7]

Answer:

Integrity: involves maintaining and assuring the accuracy of data over its life-cycle

Explanation:

Confidentiality: This is a CIA triad designed to prevent sensitive information from reaching the wrong people, while making sure that the right people have access to it.

Integrity: This is a CIA triad that involves maintaining the consistency, accuracy, and trustworthiness of data over its entire life cycle.

Availability: This is a CIA triad that involves hardware repairs and maintaining a correctly functioning operating system environment that is free of software conflicts.

Authentication:This is a security control that is used to protect the system with regard to the CIA properties.

4 0
3 years ago
Other questions:
  • What does the following program segment do? Declare Count As Integer Declare Sum As Integer Set Sum = 0 For (Count = 1; Count &l
    15·1 answer
  • If you know that the change in entropy of a system where heat was added is 12 J/K, and that the temperature of the system is 250
    10·1 answer
  • Find the equivalent impedance Zeq seen by the source when Vs = 2 cos (5t) v, C = 0.2 F, R = 1 Ω and L = 0.1 H. (Give angles in d
    12·1 answer
  • At the end of a power distribution system, a certain feeder supplies three distribution transformer, each one supplying a group
    8·1 answer
  • The design for a new cementless hip implant is to be studied using an instrumented implant and a fixed simulated femur.
    11·1 answer
  • What is your employer required to have on fixed ladders that extend more than 24 feet in the workplace?
    15·2 answers
  • A compressed-air drill requires an air supply of 0.25 kg/s at gauge pressure of 650 kPa at the drill. The hose from the air comp
    6·1 answer
  • I really need a good grade please help
    13·1 answer
  • How can input from multiple individuals improve design solutions for problems that occur because of a natural disaster, such as
    5·1 answer
  • Find the mean deviation of the set of numbers<br> (a) 12, 6, 7, 3, 15, 10, 18,5
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!