Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Need some help with my code...

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need some help with my code...

    this is the original assignment : The daily sales amount of a company product for seven days is as follows: 175, 225, 0, 200, 325, 275, 60. Write a program so that the average of sales is increased by x units from the 8th day to the 14th day. x = 1 or 2 or 5 or 10 etc.


    heres what i got so far:

     
    import java.util.Scanner;
     
    public class sales2{
       public static void main(String[] args){
       Scanner user_Input = new Scanner(System.in);
              double []sales = {175, 225, 0, 200, 325, 275, 60};
              double sum = 0, avg;
              double newSum = 0;
              int averageIncrease;
              double newSales = 0;
     
              int i, k;
     
              for (i = 0; i < 7; ++i){
                 sum = sum + sales[i];
                 System.out.println("sales[" + i + "] = " + sales[i]);
              }
              avg = sum/i;
              System.out.println("average  = " + avg);
     
     
              for (k = 8; k < 15; k++) {
     
             System.out.println("How much would you like to increase average sales by?");
             averageIncrease = user_Input.nextInt();
     
              avg = avg + averageIncrease; 
     
              newSum = avg * k ;
     
     
             newSales = newSum - sum;
     
     
                System.out.println("New sales for day[" + k + "] = " +newSales);
              }
     
     
    }
       }


    Still having a hard time to figure out how to calculate the right amount of sales for days 9-14. I was able to figure out day 8 by subtracting the new sum from the old sum but cant figure out how to get it to subtract the old sum from the first sales array as well as the previous days sorry if this sounds a little confusing.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some help with my code...

    average of sales is increased by x units from the 8th day to the 14th day. x = 1 or 2 or 5 or 10 etc.
    Can you explain the algorithm for computing the desired results. What you have posted does not make sense.
    When increased by 1, when by 2, when by 5, when by 10
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some help with my code...

    Ok the problem gives me the the amount of sales for the first seven days. I need to figure out the average of those days which I have done. But then I need to figure out what the amount of sales would be on day 8 - 14 if I increase the total average by a certain amount. For example If i increase the total average by 5 on day eight how much would I need in sales to get the average increased by that amount. Hope this clarifies it a bit.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some help with my code...

    Sounds like you need to use some algebra to get the required formula for the program to use.

    Use a piece of paper and write down the values and work on formulas to compute the values you want.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: Need some help with my code...

    .

Similar Threads

  1. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  2. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  3. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 04:38 PM
  4. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM