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
Ray Of Light [21]
2 years 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]2 years 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]2 years 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
If you wanted to divide an integer variable by 2, which of the following lines of code would you use? total = int + 2 total = in
Lesechka [4]

Answer:

Yes

Explanation:

Because all answers are intotal (2)

8 0
3 years ago
14<br> Select the correct answer.<br> Which activity is a marketing technique?
Alex Ar [27]

Answer:

Growth Hacking.

Referral Programs.

Earned Media and PR.

Networking Events.

Search Engine Marketing.

Account Based Marketing and Retargeting.

Social Media Marketing.

Search Engine Optimization.

Explanation:

Growth Hacking.

Referral Programs.

Earned Media and PR.

Networking Events.

Search Engine Marketing.

Account Based Marketing and Retargeting.

Social Media Marketing.

Search Engine Optimization.

7 0
3 years ago
Where do animators work?
mrs_skeptik [129]
1. Most animators work in big cities where movie and television studios, animation studios, software developers, and video game design firms are located.
2. I’m confused about this one.
3. An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. ... The dominant general-purpose desktop operating system is Microsoft Windows with a market share of around 76.45%.
4. A database is an organized collection of data, generally stored and accessed electronically from a computer system.
5. An app, which is short for "application," is a type of software that can be installed and run on a computer, tablet, smartphone or other electronic devices. An app most frequently refers to a mobile application or a piece of software that is installed and used on a computer.
5 0
3 years ago
Derek found that the CPU was running several processes. While Derek was looking at Task Manager, the computer crashed. Derek res
wlad13 [49]

Answer: d. Run a virus scan

Explanation: Running a virus scan will reveal if the trojan virus or any other malware has been launched and the clearing the virus when detected. These will make the computer to start working well again. The unexplainable processes that started when the computer was rebooted can be viruses.

8 0
3 years ago
Read 2 more answers
Defination of formula bar​
laila [671]

Answer:

formula bar shows the contents of the current cell and allows you to create and view the formulas

6 0
3 years ago
Other questions:
  • Write a function max arguments. write a program that reads three floating-point numbers, uses the max function, and displays the
    5·1 answer
  • The ____ category of apps makes the computer easier for blind people to use.
    9·1 answer
  • Once you select select a crop boundary, you can no
    15·1 answer
  • You're setting up some VMs to test an application you're considering making available to employees of the small company you work
    11·1 answer
  • What does the following code segment do?
    13·1 answer
  • Unleashes the ability of each person on their team to improve performance, solve problems, and
    6·2 answers
  • What is wrong with this code and correct it.
    12·1 answer
  • What tool can you use to discover vulnerabilities or dangerous misconfigurations on your systems and network
    5·1 answer
  • How is internet connection made possible.​
    7·1 answer
  • A(n) ___________________ is a set of characters that the originator of the data uses to encrypt the text and the recipient of th
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!