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
Blababa [14]
3 years ago
14

8.6 Code Practice: Question 2

Computers and Technology
1 answer:
Julli [10]3 years ago
7 0

Answer:

In Java:

import java.util.*;

public class Main{

public static int sumArray(int []arr, int lent){

    int sum = 0;

    for(int i = 0; i<lent; i++){

     sum+=arr[i];

 }

 return sum; }

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 System.out.print("Number of elements: ");

 int lent = input.nextInt();

 Random rd = new Random();

 int [] intArray = new int[lent];

 for(int i = 0; i< lent; i++){

     intArray[i] = rd.nextInt(100)+1;

 }

 System.out.print("Total: "+sumArray(intArray,lent));

}

}

Explanation:

<em>No previous code was provided; So, I had to write the program from scratch (in Java)</em>

<em>Also, the elements of the array were generated randomly</em>

<em>See attachment for program source file where I used comments for explanatory purpose.</em>

Download txt
You might be interested in
The Magic Square is a grid with 3 rows and 3 columns with the following properties: The grid contains every number from 1 to 9.
riadik2000 [5.3K]
Umm I’m sorry but u don’t understand
8 0
3 years ago
Why hackers hack?? in other people?​
pshichka [43]
Could you please reword this question. i don’t get what you’re asking
8 0
3 years ago
Read 2 more answers
ABC Resort and Hotel has approached you to write a program to keep track of the number of rooms needed for an event. Customers c
nexus9112 [7]

Answer:

Check the explanation

Explanation:

/ Pseudocode for tracking the reservation of rooms for an event

Declaration

 

  string roomInput;

  string roomNames[4];

  number roomPrice[4];

  number roomCount[4];

  number i;

  boolean roomFound;

  number totalRevenue, avgRevenue;

  number totalRoomsNeeded;

Start

 

  // initialize the room names, and price for each room

  // array index starts from 0 and goes to n-1 where n is the total number of elements in the array

  roomNames[0] = "Single";

  roomNames[1] = "Single Deluxe";

  roomNames[2] = "Double";

  roomNames[3] = "Double Deluxe";

 

  roomPrice[0] = 79.95;

  roomPrice[1] = 99.95;

  roomPrice[2] = 149.95;

  roomPrice[3] = 179.95;

 

  // initialize each room count to 0 at the start

  for(i=0;i<4;i++)

  do

      roomCount[i] = 0;

  end for  

 

  // input the room type, user should type exit to indicate they are done

  Display "Enter room type ('exit' to quit ) : ";

  Input roomInput;

 

  // loop that continues till user types quit

  while(roomInput != "quit")

  do  

      roomFound = false;

      // loop to determine if user input is valid and increment the associated room count

      for(i=0;i<4;i++)

      do

          if(roomNames[i] == roomInput) then

              roomCount[i] = roomCount[i] + 1;

              roomFound = true;

          end if

      end for

     

      // if invalid room type, display error

      if(roomFound == false) then

          Display "Invalid input for Room type. Room type can be Single or Single Deluxe or Double or Double Deluxe ";

      end if  

     

      Display "Enter room type ('exit' to quit ) : ";

      Input roomInput;

  end while

 

  // set totalRevenue and totalRoomsNeeded to 0

  totalRevenue = 0;

  totalRoomsNeeded = 0;

  Display("Room Type Price($) Rooms Needed");

  // loop to display each room type details and calculate the totalRevenue and totalRoomsNeeded

  for(i=0;i<4;i++)

  do

      Display(roomNames[i],roomPrice[i],roomCount[i])

      totalRevenue = totalRevenue + (roomPrice[i]*roomCount[i]);

      totalRoomsNeeded = totalRoomsNeeded + roomCount[i];

  end for  

 

  // calculate average revenue

  if(totalRoomsNeeded > 0) then

      avgRevenue = totalRevenue/totalRoomsNeeded;

  else

      avgRevenue = 0;

  end if

 

  // display the total revenue and average revenue

  Display("Total revenue from all rooms : $",totalRevenue);

  Display("Average revenue from a room : $",avgRevenue);

 

End  

//end of pseudocode

5 0
4 years ago
Positive and negative points of Computer and Information Systems Managers
belka [17]

Answer:

Well the first advantage is they get paid very well with $115,000 a year in 2015. Which is projected to increase in the next 10 years. Having experience in this career will give you many options for other careers like this. This is not the job you would want if you plan on wanting to work with other people with this job you are a one man job.

Explanation:

6 0
3 years ago
A client-server relationship is the basic form of a ____?
adell [148]
<span>
A client-server relationship is the basic form of a computer network. 

-hope this helps.</span>
4 0
3 years ago
Other questions:
  • Two middle-order batsmen are compared based on their performance in their previous cricket match.
    7·1 answer
  • Which of the following is the best example of a manager with a delegator leadership style
    13·2 answers
  • What is meant by close to 75% of all viruses is contracted through friendly means?
    8·1 answer
  • Roblox published a series of videos to help their audience use their creation engine, what are they called?​
    9·2 answers
  • What are paragraphs separated by
    9·1 answer
  • Software that protects confidentiality by screening outgoing documents to identify and block transmission of sensitive informati
    12·1 answer
  • The primary benefit to the use of overlays in animation is that animators are able to
    12·2 answers
  • What is the Keyboard shortcut to change the case of selected text?
    6·1 answer
  • I need help in raft survival ocean nomad I was traveling and now I can't enter the island or go back home (raft). Please help me
    15·1 answer
  • What are the main features cyber law of Nepal​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!