Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by roywe on 9/4/2017.
- */
- public class SuperDelicacy {
- private Delicacy[] dc;
- private int Delicacies;
- private String Supermarket;
- public SuperDelicacy(String Supermarket)
- {
- this.Supermarket = Supermarket;
- this.dc = new Delicacy[1000];
- this.Delicacies = 0;
- }
- public Delicacy[] getDc() {
- return dc;
- }
- public void setDc(Delicacy[] dc) {
- this.dc = dc;
- }
- public int getDelicacies() {
- return Delicacies;
- }
- public void setDelicacies(int delicacies) {
- Delicacies = delicacies;
- }
- public String getSupermarket() {
- return Supermarket;
- }
- public void setSupermarket(String supermarket) {
- Supermarket = supermarket;
- }
- public void addDc()
- {
- if(this.Delicacies < this.dc.length)
- {
- this.dc[Delicacies] = new Delicacy();
- this.Delicacies++;
- System.out.println("Added a Delicacy");
- System.out.println();
- }
- else
- {
- System.out.println("Failed to add Delicacy");
- System.out.println();
- }
- }
- public void print()
- {
- System.out.println("SuperDelicacy: ");
- System.out.println("Supermarket: " + this.getSupermarket());
- System.out.println("Delicacy: " + this.getDelicacies());
- System.out.println();
- }
- public void cheapestDc()
- {
- double min = this.getDc()[0].getPrice();
- String name = "";
- String company = "";
- for(int i = 0; 1 < this.getDc().length; i++)
- {
- if(min > this.getDc()[i].getPrice())
- {
- min = this.getDc()[i].getPrice();
- name = this.getDc()[i].getName();
- company = this.getDc()[i].getCompany();
- }
- }
- System.out.println("The cheapest Delicacy is: " + name + " by " + company);
- System.out.println();
- }
- public boolean inStock(String name)
- {
- boolean temp = false;
- double price = 0;
- for(int i = 0; i < this.getDc().length; i++)
- {
- if(this.getDc()[i].getName().equals(name) == true)
- {
- temp = true;
- price = this.getDc()[i].getPrice();
- }
- }
- if(price == 0)
- {
- System.out.println(0);
- }
- else
- {
- System.out.println("The price is: " + price);
- }
- return temp;
- }
- public void companyDc(String company)
- {
- String[] check = new String[this.getDc().length];
- int counter = 0;
- for(int i = 0; i < this.getDc().length; i++)
- {
- if(company.equals(this.getDc()[i].getCompany()))
- {
- boolean flag = false;
- for(int j = 0; j < counter; j++) {
- if(check[j].equals(this.getDc()[i].getName()))
- {
- flag = true;
- }
- }
- if(!(flag))
- {
- check[counter] = this.getDc()[i].getName();
- counter++;
- }
- }
- }
- System.out.println("The delicacies by " + company + " are: ");
- System.out.println();
- for(int i = 0; i < counter; i++)
- {
- System.out.print(check[i]);
- }
- }
- }
Add Comment
Please, Sign In to add comment