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]
3 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]3 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]3 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
Draw the final structure that will house the electronic system​
Natasha_Volkova [10]

Answer:

1. TECHNOLOGY GRADE 9 TERM 3. In this chapter, you will revise the work you did on electrical systems and control

Explanation:Circuits can be found in just about every electronic device you ... An electric circuit is in many ways similar to your circulatory system

4 0
3 years ago
Suppose a book author can be identified by an AuthorID and each book can be identified by an ISBN. Besides the identifier, an au
Scrat [10]

Answer:

a) We know that atleast one or more author writes a book.

Symbol to indicate one or more is (B)

So the correct option is B

b) We know that zero to multiple books are written by any author.

Symbol to indicate zero or more is (A)

So the correct option is A

c) The fourth option is correct if we replace by many to many relationship and generate a new entity.

So the relationship betweem author and contract is one to many. So we know that there is atleast one author that represent in symbol d and books has atleast 0 that represent in symbol c.

So Fourth Option is correct d at blue side and c at red side.

d) There are two forirgn keys in table Contract one is from AuthorId and other is ISBN.

So correcct option is C

6 0
3 years ago
After the security breach at CardSystems Solutions, a security assessment of the security measures used at the company proved th
Verizon [17]

Answer:

Was not PCI DSS- compliant.

Explanation:

This is a payment Card industry data security standard which is an information security standard that deal with branded credit card.

8 0
3 years ago
Given the 32-bit binary number:
Aliun [14]

Answer:

b. an unsigned integer? (convert it to decimal)

Explanation:

Computer systems represent data and instructions in bits to be stored and processed by the processor. The buses in the computer system transfer data and instructions to various locations. Some buses can be 32 or 64 bits wide, transporting data like the 32-bit number above which covert to an unsigned integer of 2,903,506,944.

3 0
3 years ago
What is the name of the file created after a successful compilation of myclass.java?
umka21 [38]
Myclass.class






---------------------------------
8 0
3 years ago
Other questions:
  • Ryan wants to ensure that all the words in this document are evenly spaced so that they look neat and readable . Which option in
    12·1 answer
  • What are the meaning master files<br>​
    8·1 answer
  • A forensics workstation consisting of a laptop computer with almost as many bays and peripherals as a stationary workstation is
    10·1 answer
  • Create a style rule for the page body that sets the width to 95% of the browser window ranging from 640 pixels up to 960 pixels.
    11·1 answer
  • Would these statements cause an error? Why or why not? int year = 2019; int yearNext = 2020; int &amp; ref = year; &amp; ref = y
    7·1 answer
  • How do you make the task bar and e-mail read in larger print
    13·1 answer
  • A friend complains that she is always running out of money even though she “never buys anything expensive.” What advice would yo
    5·2 answers
  • Given a scanner reference variable named input that has been associated with an input source consisting of a sequence of strings
    14·2 answers
  • To create an SSL connection, a Web server requires a ________, which is an electronic document that confirms the identity of a w
    12·1 answer
  • 9- Write a program in MARIE to add three numbers.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!