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
ipn [44]
2 years ago
10

Questions 5 - 7 refer to the following code: public class Whatchamacallit { private double price; private String title; public W

hatchamacallit() { this (0, "none"); } public Whatchamacallit(double p, String t) { price = 0; if (p > 0) { price = p; } title = t; } public String toString() { return title + " costs $" + price; } } The following code segment appears in another class: ArrayList list = new ArrayList(); list.add(new Whatchamacallit()); list.add(new Whatchamacallit(3.5, "book")); list.add(new Whatchamacallit(-17, "CD")); list.add(new Whatchamacallit(18.95, "sweater")); list.add(new Whatchamacallit(5, "notebook")); /* Missing Code */ Suppose the following line is used to replace /* Missing Code */. System.out.println(list.get(0)); What is printed as a result of executing the code segment?
Computers and Technology
1 answer:
viva [34]2 years ago
3 0
Some code formatting is required to understand this question

<span>Whatchamacallit {
   private double price;
   private String title;
   public Whatchamacallit()
   {
     this (0, "none");
   }
   public Whatchamacallit(double p, String t)
   {
     price = 0;
     if (p > 0)
     {
         price = p;
      }
      title = t;
    }
  public String toString()
   { return title + " costs $" + price; }
}

The following code segment appears in another class:

  ArrayList list = new ArrayList();
  list.add(new Whatchamacallit());
  list.add(new Whatchamacallit(3.5, "book"));
  list.add(new Whatchamacallit(-17, "CD"));
  list.add(new Whatchamacallit(18.95, "sweater"));
   list.add(new Whatchamacallit(5, "notebook"));
  /* Missing Code */
Suppose the following line is used to replace /* Missing Code */. System.out.println(list.get(0)); 

The answer is 'none</span> costs $0'

This is because the line:
'System.out.println(list.get(0))'
gets the first item (index 0) in the array, which was :
'list.add(new Whatchamacallit()) '
and Whatchamacallit() sets price = 0 and title = 'none' in the class Whatchamacallit

The specific output of the  'get(0)' is because of the 'toString()' method in 
Whatchamacallit
 
You might be interested in
Consider the following method, which is intended to return an array of integers that contains the elements of the parameter arr
Gennadij [26K]

Code:

public static int[] reverse(int [] arr){

Int [] newArr = new int[arr.length];

for (int k = 0; k<arr.length;k++){

/*Missing statement */

}

return newArr;

Answer:

Replace the comment with:

newArr[k] = arr[arr.length-k];

Explanation:

Required

Complete the code

In the given code:

The first line of the given code defines the method

public static int[] reverse(int [] arr){

The next line declares array newArr withe same length as array arr

Int [] newArr = new int[arr.length];

The next line iterates through the elements of array arr

for (int k = 0; k<arr.length;k++){

The /* Missing statement */ is then replaced with:

newArr[k] = arr[arr.length-k];

The above statement gets the elements of array arr in reversed order.

This is so because, as the iteration iterates through array arr in ascending order, arr.length-k gets the element in reversed order

6 0
2 years ago
The __________ contains a list of all the resources owned by the library.
Ira Lisetskai [31]

The catalog contains a list of all the resources owned by the library.

- Mabel <3

5 0
2 years ago
Sharon reads two different articles about avocados. The first article, in a weight loss magazine, claims that avocados are unhea
padilas [110]
The first and third.
3 0
2 years ago
Read 2 more answers
When you reboot your system, the computer follows start-up instructions stored in this type of memory. multiple choice dram sdra
MA_775_DIABLO [31]
<span>A computer’s start-up instructions are stored in a type of memory called Flash. Flash memory can be written to and read from, but its contents are not erased after the computer powers down. This Flash memory is more commonly referred to as the BIOS (Basic Input Output System).</span>
4 0
2 years ago
Read 2 more answers
Universal Containers has the following requirements:
Arisa [49]

Answer:

The answers is B

Explanation:

In order for the architect to meet the following requirements;

# A custom Loan object requires Org-Wide Defaults set to Private.

# The owner of the Loan record will be the Loan Origination Officer.

# The Loan record must be shared with a specific Underwriter on a loan-by-loan basis.

# The Underwriters should only see the Loan records for which they are assigned.

The architect should recommend

(B.) Creating a lookup relationship from the Loan object to the User object. Use a trigger on the Loan object to create the corresponding record in the Loan_share object

5 0
2 years ago
Other questions:
  • A telephone-repair technician uses a meter to measure voltage on a phone line. This meter is an example of _____. hardware softw
    10·2 answers
  • my headphones have a mic and the mic and headset don't work at the same time what do i do to make them work together
    8·2 answers
  • 5. You just bought a new hard drive for youYou plan to use this as a secondary hard drive to store allcomputeryour UMA files. On
    8·1 answer
  • Select the correct answer. Rachel needs to make a presentation on ethics and etiquettes in college. She has about 30 minutes to
    13·1 answer
  • In a particular jurisdiction, taxi fares consist of a base fare of $4.00, plus $0.25 for every 140 meters traveled. Write a func
    11·1 answer
  • Initialize the list short_names with strings 'Gus', 'Bob', and 'Zoe'. Sample output for the givenprogram:Gus Bob Zoeshort_names
    13·1 answer
  • "In about 100 words, discuss the technologies that Walmart’s trucking fleet might use to better manage their operations. Include
    7·1 answer
  • In this challenge, write a function to add two floating point numbers. Determine the integer floor of the sum. The floor is the
    8·1 answer
  • Which OS function does a CLI fulfill? A User interface B Running applications C Hardware interface D Booting
    8·1 answer
  • A reputable, world-renowned auction house uses blockchain to verify the authenticity of paintings prior to placing them up for s
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!