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
Alinara [238K]
3 years ago
8

Write a class called Product. The class should have fields called name, amount, and price, holding the product’s name, the numbe

r of items of that product in stock, and the regular price of the product. There should be a method get_price that receives the number of items to be bought and returns as the cost of buying that many items, where the regular price is charged for orders of less than 10 items, a 10% discount is applied for orders of between 10 and 99 items, and a 20% discount is applied for orders of 100 or more items. There should also be a method called make_purchase that receives the number of items to be bought and decreases amount by that much.
Computers and Technology
1 answer:
vichka [17]3 years ago
5 0

Answer:

public class Product {

//Declaring the fields

   private String name;

   private int amount;

   private double price;

   //Constructor

   public Product(String name, int amount, double price) {

       this.name = name;

       this.amount = amount;

       this.price = price;

   }

   // The method get_price

   public double get_price(int amount){

       // amount of goods less than 10

       if(amount<10){

           double zeroDiscPrice;

           zeroDiscPrice = this.price;

           return zeroDiscPrice;

       }

       // amount of goods less than 100

       else if(amount>=10 && amount<100){

           double tenPercentDiscPrice;

           tenPercentDiscPrice = this.price-(this.price*0.1);

           return tenPercentDiscPrice;

       }

       // amount of goods greater than 100

       else{

           double twentyPercentDiscPrice;

           twentyPercentDiscPrice = this.price-(this.price*0.2);

           return twentyPercentDiscPrice;

       }

   }

}

Explanation:

The class is implemented in Java programming language

Three member variables (fields) are declared as described in the question

A constructor is created to initialize an instance of the class

The method get_price() as created uses a combination of if...else if....else To determing the price based on the amount of items bought as described in the question.

You might be interested in
Write a Java method to delete a record from a B-tree of order n.
max2010maxim [7]

Answer:

Deleting a record on a B-tree consists of three main events:

- Searching the node where the key to be deleted exists

- Deleting the key

- Balancing the tree if required

Explanation:

q = NULL;

   p = tree;

   while (p) {

       i = nodesearch(p, key);

       q = p;

       if (i < used(p) -1 && key == k(p,i)) {

           found = TRUE;

           position = i;

           break;

       }

       p = son(p,i);

   }

   if (!found)

   else if (subtree(p)) {

         if (used(p) > ((n-1)/2)+1)

         delkey (p, position, key);

       else {

           replace (p, position, fsucc(p));

           p0 r1 p1 r2 p2 r3 ……. pn-1 rn-1 pn

           q = &fsucc(p);

           qpos = index of fsucc;

           if (used(rbrother(p)) > ((n-1)/2)+1)

               replace (q, qpos, sonsucc(q));

           else

               while (q && used(q) < (n-1)/2) {

                   concatenate(q, brother(q));

                   q = father(q);

               }

       }

   }

   else

   delkey(p, position, key);

}

6 0
3 years ago
You need to design a backup strategy. You need to ensure that all servers are backed up every Friday night and a complete copy o
cestrela7 [59]

Answer: (A) full backup

Explanation: A backup strategy is a term used to describe the various effective approach engaged in creating a backup for data or information.

A FULL BACK UP IS THE VARIOUS APPROACH AND SYSTEMS PUT IN PLACE BY A COMPUTER USER OR AN INFORMATION TECHNOLOGY EXPERT IN ORDER TO CREATE AN ADDITIONAL SAMPLE OR COPY OF AN INFORMATION OR A DATA IN S SINGLE BACKUP.

8 0
3 years ago
Write at least 4 sentences
elixir [45]

Answer:

I don't know who advance the evolution who is it!

8 0
3 years ago
Any Body have a zoom class goin on<br> i wanna bomb
Norma-Jean [14]

This site is only for education related questions. You should only answer or ask questions. That's what we are here for. Whoever is reading this answer, please spread it to stop people from zooming, hurting others, or just posting non-related to education questions. Thank you.

6 0
3 years ago
How to learn python ?
laila [671]

Answer:

https://www.python.org/about/gettingstarted/

Explanation:

its a site i used

7 0
3 years ago
Other questions:
  • Lawanda starts a new job today at a company that delivers thousands of packages each day. Identify three ways in which Lawanda's
    9·1 answer
  • In addition to the ping command, what other command is useful in displaying network delay and breaks in the path to the destinat
    5·2 answers
  • A router is a device that addresses a packet on a network to the next router along the line. Under which layer of the OSI model
    5·1 answer
  • What website can help you find antivirus software
    5·2 answers
  • Why is it important to have user accounts? describe the purpose, features and functions of user accounts (including administrato
    5·1 answer
  • This device is used to connect sections of large networks?
    12·2 answers
  • Discuss the different types of user-friendly interfaces and the types of users who typically use each.
    12·1 answer
  • What does “human-like” mean when we are talking about a machine?
    7·1 answer
  • Busco a talcotalco38
    14·2 answers
  • One way to check if a website is secure is to look for a/an<br> in the address bar.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!