In: Computer Science
Many dog owners see the benefit of buying natural dog food and treats. Dog Day Afternoon is a local company that creates its own dog food and treats. Their products are made locally and with natural ingredients. Sales are up and the owners of Dog Day Afternoon have decided to expand their business. Currently they are manually calculating sales. They need a computer program to help speed up the process.
The owners of Dog Day Afternoon decided to get some help. They approached the Career Center and posted numerous temporary programming positions. You are eager to get some experience as a programmer so you apply and get the job.
Your portion of the project is to create a class called DogDay that will take in the quantity and the size of the dog treat. Store these values in attributes called quantity (integer) and size (string). The class will also contain three methods. One method will determine the cost of one dog bone. Name this method DeterminePrice. The cost of the different size natural raw hide bones is as follows:
Store the cost of each individual dog bone in an attribute called price.
Your second method will be called DetermineTotal. This method will calculate the total cost (quantity * cost) and round this value to 2 decimal places. It will store this value in an attribute called total.
Your final method will return the total.
When creating this class start coding in VS Code or IDLE. To test your class create an object. Send in the values 6 and C. Next call your method DeterminePrice followed by DetermineTotal. Finally print the method ReturnTotal to the screen. Your code should print the following: 29.7
CODE:
class DogDay
{
int quantity;
String size;
DogDay(int i, String j)
{
quantity = i;
size = j;
}
double price;
void DeterminePrice(){
if(size=="A")
price = 2.29;
else if(size=="B")
price = 3.50;
else if(size=="C")
price = 4.95;
else if(size=="D")
price = 7.00;
else
price = 9.95;
}
double total;
void DetermineTotal() {
total = price * quantity;
}
void display() {
System.out.printf("%.2f", total);
}
}
public class Dog {
public static void main(String[] args) {
DogDay d1 = new DogDay(6,
"C");
d1.DeterminePrice();
d1.DetermineTotal();
d1.display();
}
}
OUTPUT:
29.70
I have tried to
answer the question as briefly and simply as possible if you find
any problem in the solution provided ask in
comment.