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
Dzięńdobry kto ogarnia komędy w minicraft bardzo dobrze i by mi pomógł w stworzeniu serwera [dostanie w zamian range właścieciel
mojhsa [17]

Playing Minecraft on a public server can take the game to a whole. This will help your kid learn social skills, such as cooperating, while there are some family-friendly servers for the Pocket Edition most server admins can “roll back” your building to the state it was in.

Explanation:

  • For Minecraft, you'll need to forward TCP port 25565 . You'll also need to enter your server's local IP address as the Output IP or Server IP for the forwarded port. This tells the router which device to point at. To find your server's local IP, open a command prompt and enter ipconfig.
  • They are safe for the most part, however they do expose you to the following risks, which can generally be negated by simply joining reputable servers. Some servers may ask users to set up an AuthMe password. If you decide to enter a password here, never ever enter the password of your Minecraft account.
  • You can divide public Minecraft servers into two types:
  1. Whitelisted servers are protected by a whitelist — that is, a list of usernames that are allowed to join the server. To join a whitelisted server, you need to apply to have your Minecraft username added to the whitelist. Typically, this involves filling out a form and waiting a few hours or days.
  2. Non-whitelisted servers do not have a whitelist, which means anyone can join the server simply by entering the server’s address in their Minecraft client, as shown above.
  • Applying for a whitelisted server can be a bit of a drag especially when you have an impatient eight-year-old tugging at your sleeve but it does provide an extra degree of reassurance that all the players on the server are known to the server administrators.
8 0
3 years ago
A technician wants to replace a failing power supply on a high-end gaming computer. which form factor should the technician be l
Semmy [17]

A technician need to use the form factor or the  technician be looking for what we call EPS12V.

<h3>What is an EPS power connector?</h3>

The EPS connector is known to be used to supply power to the  motherboard CPU socket and the PCI is known to be one that functions to express connector.

Note that this is said to be a server standard (EPS12V) and it is also known to be one that can be said to be a desktop standard (ATX12V).

Note that the EPS12V is one that is known to always be seen in an 8-pin CPU connector and therefore, A technician need to use the form factor or the  technician be looking for what we call EPS12V.

Learn more about technician from

brainly.com/question/2328085

#SPJ1

5 0
1 year ago
How would I view the ruler on my document if it was not visible
svlad2 [7]
For MS Word 2010 and higher
Go to "View" and find checkbox "Ruler"
8 0
3 years ago
How can templates be made available to other users?
Daniel [21]

Answer:

b

Explanation:

4 0
3 years ago
Output a table that show the cube of the numbers 1-15<br> (C++)
Rainbow [258]

Answer:

The c++ program to display cube of numbers from 1 to 15 is given below.

#include <iostream>

using namespace std;

int main() {    

   // variables declared and initialized  

   int num = 15, k, cube;    

   cout << " Cubes of numbers from 1 to 15 are shown below " << endl;    

   for( k = 1; k <= num; k++ )

   {

       // cube is calculated for each value of k and displayed

       cube = k * k * k ;

       cout << " \t " << cube << endl;

   }

return 0;

}

 

OUTPUT

Cubes of numbers from 1 to 15 are shown below  

  1

  8

  27

  64

  125

  216

  343

  512

  729

  1000

  1331

  1728

  2197

  2744

  3375

Explanation:

The variables are declared and initialized for loop, cube and for condition in the loop – k, cube, num respectively.

Inside for loop which executes over k, beginning from 1 to 15, cube of each value of k is calculated and displayed. The loop executes 15 times. Hence, cube for numbers from 1 to 15 is displayed after it is calculated.

   for( k = 1; k <= num; k++ )

   {

      cube = k * k * k ;

       cout << " \t " << cube << endl;

   }

In the first execution of the loop, k is initialized to 1 and variable cube contains cube of 1. Hence, 1 is displayed on the screen.

In the second execution, k is incremented by 1 and holds the value 2. The variable cube contains cube of 2, which is calculated, and 8 gets displayed on the screen.

After each execution of the loop, value of k is incremented.

After 15 executions, value of k is incremented by 1 and k holds the value 16. This new value is greater than num. Hence, the loop terminates.

3 0
3 years ago
Other questions:
  • What is the function of series-parallel circuit
    9·1 answer
  • Which of the following best explains why some people invest their saving in the stock market and others put their saving in bank
    5·2 answers
  • Submit your 300-word essay describing the equipment usedI in a well-equipped studio’s audio department and the training and expe
    8·2 answers
  • Engineers involved in product design and manufacturing use computer-aided design/computer-aided manufacturing (CAD/CAM) systems,
    13·1 answer
  • The mathematical constant Pi is an irrational number with value approximately 3.1415928... The precise value of this constant ca
    12·1 answer
  • The __________ tag is used to create a forced line break without starting a new paragraph.
    13·1 answer
  • Which is a basic job requirement for a career in corrections services?
    13·1 answer
  • Where can i watch bnha movie 2 online for free, with no sign up or pay?
    6·2 answers
  • Instead of sending an entire file in one big chunk across the​ Internet, __________ is used which dices the file up into little
    12·1 answer
  • Stephen is looking through some design diagrams created for a specific application. He spots a diagram which uses a parallelogra
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!