hi i got one problem to solve am almost did but facing problem for my last for loop iteration can any one help me

this is the problem i received

University of Newcastle
School of Electrical Engineering and Computer Science
SENG1110/6110 Programming Assignment 1 – Semester 1, 2010
Due: By electronic submission (Blackboard) by 11:59pm on Mon April 12
Mate’s coffee replenishment system
Problem Description
Mate’s coffee has asked you to create a system to enable them manage the replenishment of different products
they sell. Each product has the following information: name, demand rate, setup cost, unit cost, inventory cost and
selling price. Demand rate is a fixed demand per week. The setup cost is a fixed cost that Mate’s coffee needs to
pay every time they make an order, regardless the quantity. The inventory cost is the cost for each product unit in
the inventory per week.
The dilemma is if the Mate’s Coffee asks a big quantity order to cover the whole month, for example, they will
spend a lot of money in inventory. If they decide to make an order every week they will spend a lot in setup, since
every time they ask an order they need to pay a setup cost.
There is a method named EOQ (Economic Order Quantity) which calculates the optimal order quantity, if you
know:
Demand rate
Inventory cost/unit
Setup cost
The EOQ method calculates the optimal order quantity that would minimize total variable costs, by using the
formula below
Q =
h
2sd
Where s = setup cost
d = demand/week
h= inventory cost/unit/week
An example:
Suppose that you know that demand rate for coffee is 45/week, h = 0.60 (inventory cost per unit per week) and s =
132 (setup cost). With these values, you can calculate the value of Q which will be 140.71. Suppose that you can
just order integer values, so rounding 140.71 we will have Q=141. Now, you can tell the replenishment strategy for
next n weeks. Let’s suppose 6 weeks. In the first week the order will be 141 units, but the demand is only 45 units,
then it will have 96 units in the inventory. In the second week the demand is 45 units and we have 96 units in the
inventory from week 1. So, the second week will finish with 51 units. The week 3 will finish with 6 units in the
inventory. In the week 4, it does not have enough units in the inventory, so we need to make a new order, and so
on. So, the replenishment strategy for next 6 weeks will be
Week Quantity Order Demand Inventory

1 141 45 96
2 0 45 51
3 0 45 6
4 141 45 102
5 0 45 57
6 0 45 12

Notice that the inventory finishes with 12 units. This is not necessary; it is better the inventory finishes with 0 units.
So, we can do some arrangements. Just change the last order from 141 to (141-12). So the new replenishment
strategy for next 6 weeks will be
Week Quantity Order Demand Inventory

1 141 45 96
2 0 45 51
3 0 45 6
4 129 45 90
5 0 45 45
6 0 45 0

Now, let’s calculate the total cost and the total profit. Suppose the unit cost is 1 and the selling price is 3. The total
cost will be

Purchase = (132+132) + (141+129)*1 = 264+270 = 534
Inventory = (96+51+6+90+45)*0.6 = 172.80
Total cost = 534+172.8 = 706.80

The profit will be

Profit = 45*6*3 – 706.8 = 810 – 706.8 = 103.20

The system will print the replenishment strategy for the product for n weeks and inform the total profit. In the end,
the program will ask the user if he/she would like to restart for another product. When the user chooses to finish the
program, then it will output the best replacement strategy, which will be the product with the highest profit. The
output will be name of the product and its profit.
Programming Requirements
The input name must be a String from the set = {coffee, chocolate, tea, cake, pie}. The user can use lower case or
upper case, but the program will always convert to lower case. If the user inputs a string that does not belong to the
set, then the program will show an error message and ask the input again.
For the other inputs, if the user inputs a negative number, the program will show a message and ask the input
again.
Note that for some inputs, the EOQ method will not give a feasible plan. For example, if setup cost is 5, demand
rate is 100 and inventory cost is 1, then the Q = 31.6, which does not cover even the demand for the first week. If
the value of Q is not a feasible value (if is less the demand rate), then the program will give an error message to
the user, saying that is not possible to have a replacement strategy with the inputs given and ask the user inputs
that data again.
Your program must consist of only one class (MatesCoffee.java) and only one method (the main method). You can
choose between a TerminalIO interface or a GUI. Your program also needs to display all information such that is
easy to read. Your code also must be very well commented. Do not use arrays.
An input and output example
Welcome to Mate’s coffee replenishment system
Please, input the name of the product:
Coffe
Sorry, coffe is not included in our list of products, input the name of the product
again:

Coffee
Please, input the demand rate of coffee:
45
Please, input the setup cost of coffee:
132
Please, input the unit cost of coffee:
1
Please, input the inventory cost of coffee:
0.6
Please, input the selling price of coffee:
3
Please, input the number of weeks:
6
The replacement strategy is
Week Quantity
Order
Demand Inventory
1 141 45 96
2 0 45 51
3 0 45 6
4 129 45 90
5 0 45 45
6 0 45 0
The total cost is: 706.80
The total profit is: 103.20
Would you like to calculate the replenishment system for another product?
setup unit cost
Yes
Please, input the name of the product:
chocolate
Please, input the demand rate of chocolate:
45
Please, input the setup cost of chocolate:
50
Please, input the unit cost of chocolate:
1
Please, input the inventory cost of chocolate:
0.6
Please, input the selling price of chocolate:
3
Please, input the number of weeks:
6
The replacement strategy is
Week Quantity
Order
Demand Inventory
1 87 45 42
2 87 45 84
3 0 45 39
4 87 45 81
5 0 45 36
6 9 45 0
The total cost is: 639.20
The total profit is: 170.80
Would you like to calculate the replenishment system for another product?
No
The best replacement strategy is for chocolate with a profit of 170.80.

Note that this example does not include all possibilities of inputs and outputs. It is your task to test your program
with all possible scenarios.
What to submit.
Submit the Java code and the assignment cover sheet electronically under Assignment 1 link in Blackboard. Note:
although you can save multiple versions of your program, you can only ‘submit’ your assignment once
electronically. The lab demonstrators will show you how to do this.
Extra Work for SENG6110 students
You will give the user the option to ‘save’ the output of the program in a file. Saving to an external file will not be
covered in Lectures before this assignment is due, so part of your task is to research how to program this
functionality. Note that writing to file is covered towards the end of Chapter 3 of the textbook.
In the Blackboard you will find a new forum in the discussion board: “Assignment1”. Any question about
the assignment 1 you can post there. Check this forum regularly.
Dr. Regina Berretta
Mar-2010

this is code i developed

package com.coffee;

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class MatesCoffee {

    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Welcome to Mate’s coffee replenishment system :");
        System.out.println("Please, input the name of the product:");
        boolean result=true;
        int demandRate,unitCost,sellingPrice,weeks;
        float setUpCost = 0,inventoryCost;
        String product=br.readLine();


           String sLowerCase=product.toLowerCase();
        // System.out.println("product name:"+sLowerCase);
           Set collection = new HashSet();
            collection.add("coffee");    
            collection.add("chocolate");   
            collection.add("tea");   
            collection.add("cake");
            collection.add("pie");
            //System.out.println(collection);
            Iterator itr = collection.iterator();

             while (itr.hasNext()){
                String s=(String)itr.next();
                if(product.equalsIgnoreCase(s)){
                    System.out.println("product name:"+s);
                result=false;
                }
             }
                if(result)
                {

              System.out.println("Sorry," + product + "is not included in our list of products, input the name of the product again:");

                }


            System.out.println("Please, input the demand rate of "+product+" ");
            demandRate =Integer.parseInt(br.readLine());
            if(!(demandRate>0))
              {
                System.out.println("Invalid Input, Please, input the demand rate of " + product + ":");
                setUpCost=Integer.parseInt(br.readLine());
                }

            System.out.println("Please, input the setup cost of "+product+" ");
            setUpCost=Integer.parseInt(br.readLine());
          if(!(setUpCost>0))
            {
                System.out.println("Invalid Input ,Please, input the setup cost of "+product+" ");
                setUpCost=Integer.parseInt(br.readLine());
            }


            System.out.println("Please, input the unit cost of "+product+" ");
            unitCost=Integer.parseInt(br.readLine());
            if(!(unitCost>0))
            {
                System.out.println("Invalid Input ,Please, input the unit cost of "+product+" ");
                unitCost=Integer.parseInt(br.readLine());
            }


           System.out.println("Please, input the inventory cost of "+product+" ");
           inventoryCost=Float.parseFloat(br.readLine());
           if(!(inventoryCost>0))
           {
               System.out.println("Invalid Input  ,Please, input the inventory cost of "+product+" ");
               inventoryCost=Float.parseFloat(br.readLine()); 
           }

            System.out.println("Please, input the selling price of "+product+" ");
            sellingPrice=Integer.parseInt(br.readLine());
            if(!(sellingPrice>0))
            {
                System.out.println("Invalid Input  ,Please, input the selling price of "+product+" ");
                sellingPrice=Integer.parseInt(br.readLine());
            }

            System.out.println("Please, input the number of weeks:");
            weeks=Integer.parseInt(br.readLine());
            if(!( weeks>0))
            {
                System.out.println("Invalid Input ,Please, input the number of weeks:");
                weeks=Integer.parseInt(br.readLine());
            }

            System.out.println("The replacement strategy is");

            float q1=(float)((2*demandRate*setUpCost)/inventoryCost);
            //System.out.println(Math.sqrt(q1));
            float m= (float) Math.sqrt(q1);
            int quantityOrder =(int) (m + 0.5f);
            System.out.println("Quantity Order:" +quantityOrder);
            int p=quantityOrder;
            // int i = (int)(f + 0.5f)
            int inventory =(quantityOrder-demandRate);
            int j=inventory;
            int w=weeks;
            System.out.println("\tWeek\tQuantityOrder\tDemand\tInventory");
            int qo,s,i,n=w;

            for( i=1; i<=w; i++)
            {
                n--;
                if(i==(w-n))
                    {   

                        System.out.println("\t"+i+"\t"+quantityOrder+"\t\t"+demandRate+"\t"+inventory);
                        quantityOrder=0;
                        if(inventory>=demandRate)
                            inventory=(inventory-demandRate);
                        else
                            {

                        quantityOrder=p;
                        //quantityOrder=(p-(2*inventory)); 
                        inventory=(quantityOrder+inventory-demandRate);
                        //System.out.println("inventory0:"+inventory); 
                        //System.out.println("inventory1:"+(inventory-j)); 
                            }
                        if(w==i)
                        {
                            s=inventory;
                            //quantityOrder=(p-inventory); 
                            System.out.println("inventory2:"+s);
                            System.out.println("inventory3:"+(inventory-j)); 
                            int s1=(inventory-j);
                            System.out.println("val:"+s1);
                            //inventory=(quantityOrder+inventory-demandRate);
                        }

                    }


            }



    }

    //private static void exit() {
        // TODO Auto-generated method stub

    }

pls... can any one help me

Recommended Answers

All 3 Replies

pls... can any one help me

Yes. Start by reading the sticky threads at the top of this page. If you haven't found the link to and finished reading the Eric Raymond piece on "Asking Questions the Smart Way", you haven't finished yet.
Once you've read that, try again: come back with a specific question about your code, with any error messages you're encountering if you are encountering any.

That will help you to get a useful answer, which is harder to get if you don't ask a reasonable question. It might also help you to understand your problem, by forcing you to think about what exactly you're asking for.

Im sorry, this is off topic but does anyone else think that the requirements are kind of odd? A university asks the students to solve, a rather large problem, in only the main method. And also, they are not allowed to use arrays but can use hashsets.
Why would they encourage students not to declare own methods, I mean, that is the way it's supposed to be done.

And I also remember from my first programming courses at uni that some problems involving sets were explicitly supposed to be solved with arrays. No sets, arraylists or whatever was allowed to make the students grasp the concept of arrays before moving on to more complex data structures.

Again, sorry for off topic but I just wanted to know if anyone else reacted to this.

Didn't react to it, only because I didn't read it. But what you describe does sound odd, and counterproductive, and for exactly the reasons you describe.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.