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
Ray Of Light [21]
1 year ago
14

Implement a class Product. A product has a name and a price, for example new Product("Toaster", 29.95). Supply methods getName,

getPrice. Supply a program ProductDemo that makes two products and prints each name and price.
Computers and Technology
2 answers:
IrinaK [193]1 year ago
6 0
<h2>Answer:</h2><h2></h2>

================================================================

//Create class definition for Product class

public class Product {

   //Product class has a name and a price property

   //Declare those properties as follows

   String name;

   double price;

   

   //The Product class has a constructor to initialize the name and price

   //properties .

   //Declare the constructor as follows

   public Product(String name, double price){

       //Initialize the variables

       this.name = name;

       this.price = price;

   }

   //Write a getName method to retrieve the name of a Product object

   public String getName() {

       //This method returns the name value of the Product object

       return name;

   }

   //Write a getPrice method to retrieve the price of a Product object

   public double getPrice() {

       //This method returns the price value of the Product object

       return price;

   }

   

   

}

===============================================================

//Create the definition for the ProductDemo class

public class ProductDemo {

   //Create a main method for the application

   public static void main(String[] args) {

       //Create an object of the Product class

       Product product1 = new Product("Toaster", 29.95);

       

       //Create another object of the Product class

       Product product2 = new Product("Machine", 89.89);

       

       //Print out the name of the first product

       System.out.println("Name of product 1 " + product1.getName());

       

       //Print out the price of the first product

       System.out.println("Price of product 1 " + product1.getPrice());

       

       //Print out the name of the second product

       System.out.println("Name of product 2 " + product2.getName());

       

       //Print out the price of the second product

       System.out.println("Price of product 2 " + product2.getPrice());

       

       

  }      // End of main method

   

}          // End of class definition

=================================================================

<h2 /><h2>Sample Output:</h2><h2 />

>> Name of product 1 : Toaster

>> Price of product 1 : 29.95

>> Name of product 2 : Machine

>> Price of product 2 : 89.89

=================================================================

<h2>Explanation:</h2>

The above program has been written in Java and contains comments explaining every part of the program. Please go through the comments.

The program contains two classes and these classes have been written above. The first class is the <em>Product</em> class and the second is the <em>ProductDemo</em> class.

The actual lines of the code have been written in bold face to enhance readability and distinguish from comments.

Sample output of a run of the program has been provided also.

soldier1979 [14.2K]1 year ago
4 0

Answer:

class Product{

   private String name;

   private double price;

   public Product(String name, double price) {

       this.name = name;

       this.price = price;

   }

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this.name = name;

   }

   public double getPrice() {

       return price;

   }

   public void setPrice(double price) {

       this.price = price;

   }

}

Explanation:

The class Product is implemented above in Java with the set and get methods as well the constructor.

The ProductDemo program is given below:

public class num9 {

   public static void main(String[] args) {

       Product product1 = new Product("Paties", 4.55);

       Product product2 = new Product ("jamies", 5.99);

       System.out.println("Product 1 is "+product1.getName()+" The price is " +

               ""+product1.getPrice());

       System.out.println("Product 2 is "+product2.getName()+" The price is " +

               ""+product2.getPrice());

}

}

You might be interested in
Program documentation _____. Group of answer choices describes the inputs, outputs, and processing logic for all program modules
valentinak56 [21]

Answer:

In the given question the first line is correct, i.e. "Describes the inputs, outputs, and processing logic for all program modules".  

Explanation:

The documentation is a recorded text or image, which is preceding or in the code base of the programs, whether it describes how well the program works and how it is being used, and things in various positions can be influenced by people, and the wrong option can be described as follows:

  • In the documentation, it can't consist of rules and data.
  • In can't include a dictionary, flow maps, screen designs and device requests that began the program.
  • In can't provide links within the program.
6 0
2 years ago
Write a python 3 function named words_in_both that takes two strings as parameters and returns a set of only those words that ap
s344n2d4d5 [400]

Answer:

def words_in_both(a, b):

 a1 = set(a.lower().split())

 b1 = set(b.lower().split())

 return a1.intersection(b1)

common_words = words_in_both("She is a jack of all trades", 'Jack was tallest of all')

print(common_words)

Explanation:

Output:

{'all', 'of', 'jack'}

5 0
2 years ago
Read 2 more answers
Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
Alex787 [66]

Answer:

One of the strategies to avoid nested conditional is to use logical expressions such as the use of AND & operator.

One strategy is to use an  interface class with a method. That method can be created to be used for a common functionality or purpose. This is also called strategy design pattern. You can move the chunk of conditional statement to that method. Then each class can implement that interface class and use that shared method according to their own required task by creating objects of sub classes and call that common method for any such object. This is called polymorphism.

Explanation:

Nested conditionals refers to the use of if or else if statement inside another if or else if statement or you can simply say a condition inside another condition. For example:

if( condition1) {  

//executes when condition1 evaluates to true

  if(condition2) {

//executes when condition1  and condition2 evaluate to true

  }  else if(condition3) {

 //when condition1 is true and condition3 is true

} else {

 //condition1  is true but neither condition2 nor conditions3 are true

}  }

The deeply nested conditionals make the program difficult to understand or read if the nested conditionals are not indented properly. Also the debugging gets difficult when the program has a lot of nested conditionals.

So in order to avoid nested conditionals some strategies are used such as using a switch statement.

Here i will give an example of the strategies i have mentioned in the answer.

Using Logical Expressions:

A strategy to avoid nested conditionals is to use logical expressions with logical operators such as AND operator. The above described example of nested conditionals can be written as:

if(condition1 && condition2){  //this executes only when both condition1 and condition2 are true

} else if(condition1 && condition3) {

this executes only when both condition1 and condition3 are true

} else if(condition1 ){

//condition1  is true but neither condtion2 nor condtion3 are true  }

This can further be modified to one conditional as:

if(!condition3){

// when  condition1 and condition2 are true

}

else

// condition3 is true

Now lets take a simple example of deciding to go to school or not based on some conditions.

if (temperature< 40)

{

   if (busArrived=="yes")

   {

       if (!sick)

       {

           if (homework=="done")

           {

               printf("Go to school.");

           }

       }                    

   }

}

This uses nested conditionals. This can be changed to a single conditional using AND logical operator.

if ((temperature <40) && (busArrived=="yes") &&

(!sick) && (homework=="done"))

{    cout<<"Eligible for promotion."; }

The second strategy is to use an interface. For example you can

abstract class Shape{

//declare a method common to all sub classes

  abstract public int area();

// same method that varies by formula of area for different shapes

}

class Triangle extends Shape{

  public int area() {

     // version of area code for Triangle

return (width * height / 2);

  }

}

class Rectangle extends Shape{

  public int area() {

     // version of area code for Rectangle

    return (width * height)

  }

}

// Now simply create Rectangle or Triangle objects and call area() for any such object and the relevant version will be executed.

4 0
2 years ago
A company has a number of employees. The attributes of EMPLOYEE include Employee ID (identifier), Name, Address, and Birthdate.
IgorLugansk [536]

Answer:

The ERD is attached.

Explanation:

See the attached document for ERD

Download docx
4 0
1 year ago
"Describe how implementation of a RAID Level 2 system would be beneficial to a university payroll system. In your own words, des
Darina [25.2K]

Answer:

In RAID 2 Hamming Code ECC Each piece of the information word is kept in touch with an information plate drive . Every datum word has its Hamming Code ECC word recorded on ECC circles. On Read, the ECC code confirms the right information or revises the single plate blunders.  

Strike Level 2 is one of the two innately equal mapping and assurance strategies characterized in the Berkeley paper. It has not been broadly sent in the business to a great extent since it requires an extraordinary plate highlights. Since plate creation volumes decides the cost, it is increasingly practical to utilize standard circles for the RAID frameworks.  

Points of interest: "On the fly" it gives information blunder amendment. Amazingly high information move rates is possible.Higher the information move rate required,better the proportion of information circles to ECC plates. Moderately basic controller configuration contrasted with the other RAID levels 3,4 and 5.  

Impediments: Very high proportion of the ECC plates to information circles with littler word sizes - wasteful. Passage level expense are extremely high - and requires exceptionally high exchange rate prerequisite to legitimize. Exchange rate is equivalent to that of the single plate, best case scenario (with shaft synchronization). No business executions can't/not industrially suitable.

4 0
2 years ago
Other questions:
  • Writing a program in a language such as c or java is known as _____ the program.
    10·1 answer
  • Initialize a list. ACTIVITY Initialize the list short.names with strings 'Gus', Bob, and 'Ann'. Sample output for the given prog
    9·1 answer
  • The computer component that makes sure that instructions are decoded and executed properly is the ___________.
    11·2 answers
  • Write an expression that executes the loop body as long as the user enters a non-negative number. Note: If the submitted code ha
    7·1 answer
  • Using Amdahl’s Law, calculate the speedup gain of an application that has a 60 percent parallel component for (a) two processing
    11·1 answer
  • Organizations that have no physical ("brick and mortar") presence, but only exist because of communication and computer technolo
    9·1 answer
  • Assume you have a project with seven activities labeled A-G (following). Derive the earliest completion time (or early finish-EF
    15·1 answer
  • Which best compares and contrasts visual and performing arts? Both careers use communication skills; however, people involved in
    15·2 answers
  • Write a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the output is
    14·1 answer
  • Which Artificial Intelligence (AI) term is used to describe extracting information from unstructured text using algorithms?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!