Question

In: Computer Science

ITAP2005 Java Programming Fundamentals Healthy Eat Bakery Healthy Eat bakery is a family owned business. It...

ITAP2005 Java Programming Fundamentals

Healthy Eat Bakery

Healthy Eat bakery is a family owned business. It is renowned for the healthy bread baked since generations in the family. In HealthyEat bakery, there are three types of bread sold: Rye Bread, Multi seeds bread, Brown Bread. It is not only known for the healthy bread but also for the economical prices of the bread.

The prices of the bread

-> Rye Bread (RB) – $1.3 ,

-> Multiseeds bread (MB) - $1.2 and

-> Brown bread (BB) - $1.

Each bread has predefined price, amount sold and name (the abbreviations).

The person holds 2 data fields:

➔ the type of the bread bought (the abbreviations)

➔ the money they have

You are required to develop program as below by applying OOP principles and constructs:

1) That calculates the total earning of each type of bread;

2) That calculates your total earnings;

3) That shows a person, who has a definite amount of money, how much of a particular type of bread may buy.

4) Draw the class diagram showing the relationship among the classes

The required output as follows.

Input: 4,"RB" -> Output: Rye bread: 5.2

Input: 10, "MB" -> Output: Multiseeds Bread: 12.0

Input: 4, "BB" -> Output: Brown Bread: 4.0 Total earnings: 21.2

Input: (for a person) 22.0,"RB" -> Output: You may buy 16 loaves of this type of bread

Solutions

Expert Solution

Hello Here is the java code implementated for Bread, Person and Bakery class(Main test). User can enter number of inputs and find individual and total earnings. Hope you like it.

Source Code:

Person.java:

public class Person extends Bread {


private double amount;

private String bread_type;

public Person(double amount, String bread_type) {

this.amount = amount;

this.bread_type = bread_type;

}

public int calculateLoaves(double amount, String breadType) {

int loaves = 0;

if(breadType.equalsIgnoreCase("RB"))

loaves = (int) (amount / RB);

else if(breadType.equalsIgnoreCase("MB"))

loaves = (int) (amount / MB);

else

loaves = (int) (amount/BB) ;

return loaves;

}

}

Bread.java:

public class Bread {


private double price = 0.0;

private int amount_sold;

private String name;

final double RB = 1.3;

final double MB = 1.2;

final float BB = 1;

public Bread()

{
public Bread(int amount_sold, String name) {

this.amount_sold = amount_sold;

this.name = name;

}

public String gettBreadType() {

if(name.equalsIgnoreCase("RB"))

return "Rye Bread";

else if(name.equalsIgnoreCase("MB"))

return "Multiseeds Bread";

else

return "Brown Bread";  

}

  
public double calculateTotalEarnings() {

if(name.equalsIgnoreCase("RB"))

price = RB * amount_sold;

else if(name.equalsIgnoreCase("MB"))

price = MB * amount_sold;

else

price = BB *amount_sold;

return price;   

}

@Override

public String toString() {

return gettBreadType() + " : " + calculateTotalEarnings();

}

}

****************************************************************************
Bakery.java:

import java.util.ArrayList;

import java.util.Scanner;

public class Bakery {

public static void runBakery() {

Scanner sc = new Scanner(System.in);

String choice ="y" ;

ArrayList<Bread> breads = new ArrayList<Bread>();

while (choice.equalsIgnoreCase("y")) {

System.out.println("Enter the amount sold: ");

int amountSold = sc.nextInt();

System.out.println("Enter the bread type: ");

String breadType = sc.next();

Bread newBread = new Bread(amountSold,breadType);


breads.add(newBread);

System.out.println("Do want to add another bread(Y/N)?: ");

choice= sc.next();

}

double totalEarnings = 0.0;

for(Bread bread : breads) {

System.out.println(bread);

totalEarnings += bread.calculateTotalEarnings();

}

System.out.println("Total Earnings: "+ totalEarnings);

System.out.println("\nEnter the amount sold: ");

double amountPerson = sc.nextInt();

System.out.println("Enter the bread type bought: ");

String boughtBreadType = sc.next();

Person p = new Person(amountPerson, boughtBreadType);

int loaves = p.calculateLoaves(amountPerson, boughtBreadType);

System.out.println("You may buy " + loaves + " loaves of this type of bread");

sc.close();

}

public static void main(String[] args) {

runBakery();

}

}

Class Diagram :


Related Solutions

what can we eat to be healthy
what can we eat to be healthy
Fundamentals of Programming USING JAVA Please copy here your source codes, including your input and output...
Fundamentals of Programming USING JAVA Please copy here your source codes, including your input and output screenshots. Please upload this document along with your source files (i.e., the .java files) on Blackboard by the due date. 1. (Display three messages) Write a program that displays Welcome to Java, Welcome to Computer Science, and Programming is fun. 2. (Convert feet into meters) Write a program that reads a number in feet, converts it to meters, and displays the result. One foot...
IHRM in Action Case 2.1 Establishing a branch of a family business in China A family-owned...
IHRM in Action Case 2.1 Establishing a branch of a family business in China A family-owned carbon steel company from Germany has extended its business to Hong Kong. The owners bought a small traditional Chinese firm and decided to copy the successful structure they had developed at home. This struc- ture was headed by three general managers who equally shared the responsibilities for the business activities of the firm. The consequences were as follows. 1 Now the Chinese employees were...
ABC Limited is a family owned business that has been in operation for the past ten...
ABC Limited is a family owned business that has been in operation for the past ten years. The company based in Kabwe manufactures one product: desks. ABC limited Managing Director, Mr. Aubrey Bwalwa Chuungu has been away on a business trip to China for the past three months. He is worried that the current outbreak of the Corona virus and the subsequent restrictions imposed on commerce by the Zambian government may have had adverse financial consequences for the company. You...
            Kiko Ltd is a family owned Asian grocery business that specialises in selling a variety...
            Kiko Ltd is a family owned Asian grocery business that specialises in selling a variety of Japanese products. The company has recently started to receive orders from hotels across the state. It is now 1 October, and Mr Seike, the owner, is very pleased with his growing business. He compiled data on the business’ revenue and purchases for the past three months, and prepared forecasts for the upcoming three months as shown below: Sales Revenue Purchases Actual data: July...
Read the following scenario. A family-owned business can have special complications. The line separating family relationships...
Read the following scenario. A family-owned business can have special complications. The line separating family relationships and legal responsibilities can be unclear. It is important for directors, officers, and owners of a family-owned business to be aware of the issues to avoid misunderstandings and unintended liability and to preserve familial relationships. You are a consultant advising a "mom and pop" grocery store owned by Jeff and Joan, a married couple, and their two adult children, Martha and Henry. The grocery...
Magi Chen is the managing director of Sun Construction Pty Ltd, a family owned business that...
Magi Chen is the managing director of Sun Construction Pty Ltd, a family owned business that provides construction services. As Magi is interested in purchasing some new constructionequipment’s for her business, she has approached her local bank for finance. The bank has asked that Magi provide an audited financial statement to assist them in considering her loan application. Magi has approached your audit firm for this service and you have been allocated the task of auditing Sun Construction for the...
Magi Chen is the managing director of Sun Construction Pty Ltd, a family owned business that...
Magi Chen is the managing director of Sun Construction Pty Ltd, a family owned business that provides construction services. As Magi is interested in purchasing some new construction equipment’s for her business, she has approached her local bank for finance. The bank has asked that Magi provide an audited financial statement to assist them in considering her loan application. Magi has approached your audit firm for this service and you have been allocated the task of auditing Sun Construction for...
Acme Manufacturing, Inc. was originally a family owned operation that has been in business for several...
Acme Manufacturing, Inc. was originally a family owned operation that has been in business for several generations. It has grown steadily and is now listed on the stock exchange with family members still owning a substantial portion of the shares. Over the years, the company has acquired a reputation for exceptional quality and has won awards from major customers. The firm is 75% equity financed; shares currently trade at $37 and do not pay a dividend. Debt capital is provided...
A small family-owned business is rapidly expanding. Payroll is currently processed by the owner's wife but...
A small family-owned business is rapidly expanding. Payroll is currently processed by the owner's wife but she can no longer keep up. You've been hired to evaluate whether or not the company should outsource the payroll function. What questions must be answered for you to make a recommendation? What are the advantages and disadvantages of outsourcing payroll? What factors should be considered in outsourcing payroll to a payroll service bureau? Discuss the advantages and disadvantages of using a payroll service...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT