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
aleksklad [387]
3 years ago
7

Define a public class named Sample with two instance variables: an int called count and a String called name. Provide a complete

constructor that allows both fields to be initialized when instances of Sample are created with count as its first parameter and name as its second. Neither count nor name should be public. Rather, you should provide: Both a getter and a setter for count Only a getter for name: this is how you can create a read-only variable in Java. Your getters and setters should follow the naming convention we have been using in class: get or set followed by the name of the field, capitalized. Getters should have the same return type as the variable that they are returning. Setters should not return a value.
Computers and Technology
1 answer:
Firlakuza [10]3 years ago
7 0

Answer:

The code to this question can be given as:

class Sample  //define class Sample.

{  

   //define private member.

 private int count;            

 private String name;

 Sample(int count, String name)           //define parameterized constructor.  

 {

   this.count = count;               //holding values.

   this.name = name;

 }

 public int getCount()                   //define function with returntype.

 {

   return count;

 }

 public String getName()         //define function with returntype.

 {

   return name;

 }

 public void setCount(int count)       //define function with no returntype.

 {

   this.count = count;

 }

public void setName(String name)         //define function with no returntype.

 {

   this.name = name;

 }

}

Explanation:

In the above code firstly we define the class that is Sample. In this class, we define two variable that is not public. Then we define the constructor. This code we parameterized constructor because it takes the values as a parameter. To assign the value in the constructor we use this keyword.  Then we used the get and set method. when we use get method because it returns a value (getcount and getname).  When we use the set method it does not return any value (setcount and setname).

You might be interested in
Which of the following will increase the level of security for personal and confidential information on a mobile device if the d
Soloha48 [4]
I believe is a and c.
8 0
4 years ago
My friend Leo wants to have an emergency plan for his final exams on University of Southern Algorithmville. He has N subjects to
leonid [27]

Answer:

Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. Greedy algorithms are used for optimization problems. An optimization problem can be solved using Greedy if the problem has the following property: At every step, we can make a choice that looks best at the moment, and we get the optimal solution of the complete problem.

If a Greedy Algorithm can solve a problem, then it generally becomes the best method to solve that problem as the Greedy algorithms are in general more efficient than other techniques like Dynamic Programming. But Greedy algorithms cannot always be applied. For example, the Fractional Knapsack problem (See this) can be solved using Greedy, but 0-1 Knapsack cannot be solved using Greedy.

The following are some standard algorithms that are Greedy algorithms.

1) Kruskal’s Minimum Spanning Tree (MST): In Kruskal’s algorithm, we create an MST by picking edges one by one. The Greedy Choice is to pick the smallest weight edge that doesn’t cause a cycle in the MST constructed so far.

2) Prim’s Minimum Spanning Tree: In Prim’s algorithm also, we create an MST by picking edges one by one. We maintain two sets: a set of the vertices already included in MST and the set of the vertices not yet included. The Greedy Choice is to pick the smallest weight edge that connects the two sets.

3) Dijkstra’s Shortest Path: Dijkstra’s algorithm is very similar to Prim’s algorithm. The shortest-path tree is built up, edge by edge. We maintain two sets: a set of the vertices already included in the tree and the set of the vertices not yet included. The Greedy Choice is to pick the edge that connects the two sets and is on the smallest weight path from source to the set that contains not yet included vertices.

4) Huffman Coding: Huffman Coding is a loss-less compression technique. It assigns variable-length bit codes to different characters. The Greedy Choice is to assign the least bit length code to the most frequent character. The greedy algorithms are sometimes also used to get an approximation for Hard optimization problems. For example, the Traveling Salesman Problem is an NP-Hard problem. A Greedy choice for this problem is to pick the nearest unvisited city from the current city at every step. These solutions don’t always produce the best optimal solution but can be used to get an approximately optimal solution.

6 0
3 years ago
Which is true about routers and switches?
Julli [10]

Answer:

Routers control traffic between networks while switches control traffic within a network

Explanation:

There are different devices involves in computer networking. These devices include hub, switch, router and other components.

Switch is used to connect the computer with in the network. It controls the traffic between different computers within the network. Different computers are connected with each other through different cables with the help of switch.

On the other hand, different LAN's connected through the cable with a router to communicate with each other. This device is used to control the traffic between different networks.

 

8 0
3 years ago
Which top-level domain can be used by anyone, regardless of their affiliation?
Firdavs [7]

Answer:

C. org

Explanation:

org is an open domain so anyone is allowed to register a .org domain

7 0
3 years ago
Wireless internet is an example of telecommunications.
lawyer [7]
Anything is telecommunication if it has a <span>transmitter</span> and receiver. If you're a Host, then you're hosting (Transmitting) a connection. If you have a router as a customer or service, then you're receiving their signal (transmitting). You're the receiver. 
7 0
3 years ago
Other questions:
  • PLEASE HELP PROGRAMMING WILL GIVE BRAINLIEST
    6·1 answer
  • Write a program that will calculate the following function:
    14·1 answer
  • Which structure is sometimes called the "gateway to memory"?
    14·1 answer
  • Objectivity is only a small part of assessing a Web site. <br> a. True<br> b. False
    10·1 answer
  • Design a 4-to-16 line Decoder by using the two 3*8 decoder-line decoders. The 3-to-8 line decoders have an enable input ( '1' =e
    13·1 answer
  • What is virtual memory?
    11·1 answer
  • A window frame will expand to fill the entire desktop when you
    15·1 answer
  • Select the true statement from the choices below. Group of answer choices Invalid code may cause browsers to render the pages sl
    11·1 answer
  • How to fix this? Zoom it in to see it better
    8·1 answer
  • Please help me on this it’s due now
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!