answer.
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
asambeis
2 months ago
14

Days of the week are represented as three-letter strings ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"). Write a javaScript f

unction solution that, given a string S representing the day of the week and an integer K (between 0 and 500), returns the day of the week that is K days later. For example, given S = "Wed" and K = 2, the function should return "Fri". Given S = "Sat" and K = 23, the function should return "Mon".
Computers and Technology
1 answer:
Harlamova29_29 [1K]2 months ago
3 0

Answer:

function getDay(s, k) {

var weekDays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];

var index = weekDays.findIndex(function(day) { return day === s; });

return weekDays[(index + k) % 7];

}

Explanation:

// This function takes two parameters:

// s: a string representing the current day of the week

// k: an integer indicating how many days after s to find the result

function getDay(s, k) {

var weekDays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];

// Find the index of day s in weekDays array

var index = weekDays.findIndex(function(day) { return day === s; });

// Calculate the new index by adding k and using modulo 7 to wrap around

return weekDays[(index + k) % 7];

}

You might be interested in
Write the state of the elements of each of the following arrays after each pass of the outermost loop of the selection sort algo
Natasha_Volkova [1026]

Answer:

Below is the explanation provided.

Elaboration:

In the first array => 8, 5, -9, 14, 0, -1, -7, 3.

  • 8, 5, -9, 14, 0, -1, -7, 3 For the first iteration, find the smallest from the first to the eighth and reposition the third element in the first place.
  • -9, 8, 5, 14, 0, -1, -7, 3 In the second round, identify the smallest from the second to eighth and adjust the penultimate element in the second slot.
  • -9, -7, 8, 5, 14, 0, -1, 3 For the third pass, find the least from third to eighth and move the second last item from that segment.
  • -9, -7, -1, 8, 5, 14, 0, 3 For the fourth pass, find the minimum from the fourth to eighth and shift the last second item from that section.
  • -9, -7, -1, 0, 8, 5, 14, 3 For the fifth pass, seek for the smallest from the fifth to eighth and place the last element from that portion.
  • -9, -7, -1, 0, 3, 8, 5, 14 For the sixth pass, identify the smallest from the sixth to eighth and shift the last second element from that group.
  • -9, -7, -1, 0, 3, 5, 8, 14 are in order now.

In the second array => 15, 56, 24, 5, 39, -4, 27, 10.

  • 15, 56, 24, 5, 39, -4, 27, 10 In the first iteration, identify the smallest item from the first to the eighth and reposition the last third item in that section.
  • -4, 15, 56, 24, 5, 39, 27, 10 In the second round, find the minimum item from second to eighth and interchange the last fourth item in that segment.
  • -4, 5, 15, 56, 24, 39, 27, 10 For the third pass, select the smallest from the third to eighth and shift the last item from that set.
  • -4, 5, 10, 15, 56, 24, 39, 27 For the fourth stage, determine the smallest from the fourth to eighth and do not shift its position as it is already sorted.
  • -4, 5, 10, 15, 56, 24, 39, 27 For the fifth iteration, check for the smallest from the fifth to the eighth and intersperse the last third item from that section.
  • -4, 5, 10, 15, 24, 56, 39, 27 For the sixth phase, find the smallest from the sixth to the eighth and exchange the last item in the sixth.
  • -4, 5, 10, 15, 24, 27, 56, 39 are in order now.
4 0
13 days ago
Olivia needs to get permission to use a graph of data gathered by a trade association she plans to include the graph in a report
Natasha_Volkova [1026]

She can locate the copyright notice on the webpage that features the graph.

Explanation: ~Apex~

3 0
1 month ago
Read 2 more answers
Brendan is examining a report using the Design view. Which section in the Design view is going to appear only once on the first
maria [1035]

The Report Header Section is the part in Design view that appears only on the first page and may include logos and title details.

Clarification:

In Design view, the Create tab allows for report creation with just a click. The Report Wizard can also assist in generating reports with various options.

After initiating a report, you will realize that it contains multiple sections, requiring decisions on the data to be included in each section.

The Report Header Section shows at the top of the first page and only once during the report generation. It features elements like the logo, report title, and current date.

3 0
1 month ago
There are N bulbs numbered from 1 to N, arranged in a row. The first bulb is plugged into the power socket and each successive b
ivann1987 [1066]

Answer:

The code example provided has relevant comments included.

Explanation:

// Implementation of the TestSolution class

import java.util.Arrays;

public class TestSolution

{

  // Implementing the solution function

  public static int solution(int[] arr)

  {

      // Define local variables

      int i, j, count = 0;

      boolean shines;

     

      // Using nested loops to tally the instances where every lit bulb shines

      for (i = 0; i < arr.length; i++)

      {

          shines = true;

          for (j = i + 1; j < arr.length && shines; j++)

          {

              if (arr[i] > arr[j])

                  shines = false;

          }

          if (shines)

              count++;

      }

      // Return the count of instances where every lit bulb shines

      return count;

  } // End of solution function


  // Main function begins

  public static void main(String[] args)

  {

      // Arrays A, B, and C are created

      int[] A = {2, 1, 3, 5, 4};

      int[] B = {2, 3, 4, 1, 5};

      int[] C = {1, 3, 4, 2, 5};

     

      // Generate a random number N in the range of [1..100000]

      int N = 1 + (int)(Math.random() * 100000);

     

      // Create an array D of size N

      int[] D = new int[N];

     

      // Fill array D with distinct random numbers in the [1..N] range

      int i = 0;

      while(i < N)

      {

          int num = 1 + (int)(Math.random() * N);

          boolean found = false;

          for(int j = 0; j < i && !found; j++)

          {

              if(D[j] == num)

                  found = true;

          }

         

          if(!found)

          {

              D[i] = num;

              i++;

          }

      }          

     

      // Display elements and moments of arrays A, B, and C

      System.out.println("Array A: " + Arrays.toString(A) + " and Moments: " + solution(A));

      System.out.println("Array B: " + Arrays.toString(B) + " and Moments: " + solution(B));

      System.out.println("Array C: " + Arrays.toString(C) + " and Moments: " + solution(C));

     

      // Output the size and moments of array D

      System.out.println("Size(N) of Array D: " + N + " and Moments: " + solution(D));

     

  } // End of main function

} // End of TestSolution class

3 0
2 months ago
In this lab, you complete a Java program with the provided data files. The program calculates the amount of tax withheld from an
oksian1 [950]

Response:

// Payroll.java

public class Payroll

{

int numOfDependents;

double salary;

double salaryToHome;

double Federal_Tax,TAX_RATE,Depen_tax;

Payroll(double salry,int nod)

{

numOfDependents=nod;

salary=salry;

Federal_Tax=6.5;

TAX_RATE=28.0;

Depen_tax=2.5;

}

double getTAX_RATE()

{

return TAX_RATE*salary/100;

}

double Federal_Tax()

{

return Federal_Tax*salary/100;

}

double getDepenAmount()

{

return numOfDependents*(Depen_tax*salary/100);

}

double getTakeHomeSalary()

{

return salary+getDepenAmount()-(getTAX_RATE()+Federal_Tax());

}

void printOutput()

{

System.out.print("\nState Tax: $"+getTAX_RATE());

System.out.print("\nFederal Tax: $"+Federal_Tax());

System.out.print("\nDependents: $"+getDepenAmount());

System.out.print("\nSalary: $"+salary);

System.out.println("\nTake Home Pay: $"+getTakeHomeSalary());

}

public static void main(String args[])

{

Payroll obj=new Payroll(1250,2);

obj.printOutput();

}

}

// ModifiedPayroll.java

import java.util.Scanner;

public class ModifiedPayroll

{

 

int numOfDependents;

double salary;

double salaryToHome;

double Federal_Tax,TAX_RATE,Depen_tax;

ModifiedPayroll(double salry,int nod)

{

//initialize variables

numOfDependents=nod;

salary=salry;

Federal_Tax=6.5;

TAX_RATE=28.0;

Depen_tax=2.5;

}

double getTAX_RATE()

{

return TAX_RATE*salary/100;

}

double Federal_Tax()

{

return Federal_Tax*salary/100;

}

double getDepenAmount()

{

return numOfDependents*(Depen_tax*salary/100);

}

double getTakeHomeSalary()

{

return salary+getDepenAmount()-(getTAX_RATE()+Federal_Tax());

}

void printOutput()

{

System.out.print("\nState Tax: $"+getTAX_RATE());

System.out.print("\nFederal Tax: $"+Federal_Tax());

System.out.print("\nDependents: $"+getDepenAmount());

System.out.print("\nSalary: $"+salary);

System.out.println("\nTake Home Pay: $"+getTakeHomeSalary());

}

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("\nEnter Salary: $");

double salary=sc.nextDouble();

System.out.print("\nEnter number Of Dependents:$");

int nob=sc.nextInt();

ModifiedPayroll obj=new ModifiedPayroll(salary,nob);

obj.printOutput();

}

}

Results:

// From Payroll.java

State Tax: $350.0

Federal Tax: $81.25

Dependents: $62.5

Salary: $1250.0

Take Home Pay: $881.25

// From ModifiedPayroll.java

Enter Salary:$1550.0

Enter number of Dependents:$3

State Tax: $434.0

Federal Tax: $100.75

Dependents: $116.25

Salary: $1550.0

Take Home Pay: $1131.5

6 0
1 month ago
Other questions:
  • Describe how the process of sampling, RGB pixels, and binary sequences work together to display a digital color image
    14·1 answer
  • Write an expression to print each price in stock_prices. Sample output with inputs: 34.62 76.30 85.05
    9·1 answer
  • In this project, you’ll create a security infrastructure design document for a fictional organization. The security services and
    9·1 answer
  • A technician with a PC is using multiple applications while connected to the Internet. How is the PC able to keep track of the d
    8·2 answers
  • When a CPU executes instructions as it converts input into output, it does so with
    12·1 answer
  • You are given a string of n characters s[1 : : : n], which you believe to be a corrupted text document in which all punctuation
    12·1 answer
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    7·1 answer
  • Dan is a Civil Engineer for a company that builds nuclear power plants throughout the world. Which best describes the places he
    14·2 answers
  • Which statement best describes the Tell Me feature in PowerPoint 2016?
    12·1 answer
  • During which stage does the central processing unit analyze the instruction and encode it in the form of a number, and then gene
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!