Need help with max/min'ing multiply

Reply

Join Date: Oct 2008
Posts: 37
Reputation: IMtheBESTatJAVA has a little shameless behaviour in the past 
Solved Threads: 0
IMtheBESTatJAVA IMtheBESTatJAVA is offline Offline
Light Poster

Need help with max/min'ing multiply

 
0
  #1
Dec 1st, 2008
I've been given a project in which I have to find the highest and lowest possible product using 3 2-digit numbers without repeating any numbers.

For example, the algorithm for the highest would be:
7n * 8n * 9n where the n's would be 4, 5, or 6.
The algorithm for the lowest would be:
1n * 2n * 3n where the n's would be 4, 5, or 6.

So far, I know I will have to give an option of finding the lowest or highest, so I would ask the user to put in 0 to minimize and 1 to maximize. Now, I have thought of using an if statement for reading their input, but I need some kind of loop that will rearrange the 4's, 5's, or 6's. I thought of attaching the values of 4, 5, and 6 to the 90, 80, 70, or 10, 20, 30, but am unsure of how I would code a proper loop or simple if statement to find the best answer by trying each combination. In theory, I could make some really over-extensive amount of code to do it right, but it wouldn't follow curriculum.

The code I have so far is


  1. public class Powers
  2. {
  3. public static void main(String[] args);
  4.  
  5. int input;
  6. int numOneTensLow = 10;
  7. int numTwoTensLow = 20;
  8. int numThreeTensLow = 30;
  9. int numOneOnesLow = 4;
  10. int numTwoOnesLow = 5;
  11. int numThreeOnesLow = 6;
  12. int numOneTensHigh = 90;
  13. int numTwoTensHigh = 80;
  14. int numThreeTensHigh = 70;
  15. int numOneOnesHigh = 6;
  16. int numTwoOnesHigh = 5;
  17. int numThreeOnesHigh = 4;
  18. int numOneLow;
  19. int numTwoLow;
  20. int numThreeLow;
  21. int numOneHigh;
  22. int numTwoHigh;
  23. int numThreeHigh;
  24. int lowproduct = (numOneLow * numTwoLow * numThreeLow);
  25. int highprodcut = (numOneHigh * numTwoHigh * numThreeHigh);
  26.  
  27. ConsoleIO console = new ConsoleIO();
  28. System.out.println("This program will calculate three two-digit" +
  29. " numbers that create the lowest and highest possible products " +
  30. "using the numbers 1 through 9 once in each.");
  31. System.out.println("To calculate the highest input 1, to calculate" +
  32. " the lowest, input 0: ");
  33. input = console.readInt();
  34.  
  35. if(int input = 0);
  36. {
  37. do
  38. {
  39. numOneTensLow + NumOneOnesLow;
  40. numTwoTensLow + NumTwoOnesLow;
  41. numThreeTensLow + NumThreeOnesLow;
  42. System.out.println((numOneTensLow + numOneOnesLow) * (NumTwoTensLow + NumTwoOnesLow)
  43. * (NumThreeTensLow + NumThreeOnesLow));
  44. }
  45. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Need help with max/min'ing multiply

 
0
  #2
Dec 1st, 2008
Base condition - use any java editor or IDE (NetBeans,Eclipse,BlueJ....)
What is this ? public static void main(String[] args); Post formally proper code.

quuba
Last edited by quuba; Dec 1st, 2008 at 10:15 am. Reason: adding:Post formally proper code.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: Need help with max/min'ing multiply

 
0
  #3
Dec 1st, 2008
I could help you with a little bit of help from your side first.Pls detail your problem and also comment your code wherever appropriate.
Last edited by verruckt24; Dec 1st, 2008 at 10:15 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Need help with max/min'ing multiply

 
0
  #4
Dec 1st, 2008
would love to help you imbestatjava, but i have no clue what you are trying to do

multiply by numbers by products of 7,8,9 and 1,2,3?
that part is understandable, but what is this?
90, 80, 70, or 10, 20, 30
i don't get what these values have to do with anything
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 37
Reputation: IMtheBESTatJAVA has a little shameless behaviour in the past 
Solved Threads: 0
IMtheBESTatJAVA IMtheBESTatJAVA is offline Offline
Light Poster

Re: Need help with max/min'ing multiply

 
0
  #5
Dec 2nd, 2008
The values 90, 80, 70 and 10, 20, 30 have a lot to do with the program because im trying to find the highest possible combination of 9n, 8n, and 7n so it'd be (90 + n) * (80 + n) * (70 + n) where every n must be either 4, 5, or 6. So far the only error I can actually see is in the line of code
  1. public static void main(String[] args);
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: Need help with max/min'ing multiply

 
0
  #6
Dec 2nd, 2008
I think you need to do something like this :
  1. highProduct1 = (numOneTensHigh + numOneOnesHigh) *
  2. (numTwoTensHigh + numTwoOnesHigh) *
  3. (numThreeTensHigh + numThreeOnesHigh);
  4.  
  5. highProduct2 = (numOneTensHigh + numTwoOnesHigh) *
  6. (numTwoTensHigh + numOneOnesHigh) *
  7. (numThreeTensHigh + numThreeOnesHigh);
  8.  
  9. highProduct3 = (numOneTensHigh + numThreeOnesHigh) *
  10. (numTwoTensHigh + numTwoOnesHigh) *
  11. (numThreeTensHigh + numOneOnesHigh);
  12.  
  13. highProduct4 = (numOneTensHigh + numOneOnesHigh) *
  14. (numTwoTensHigh + numThreeOnesHigh) *
  15. (numThreeTensHigh + numTwoOnesHigh);
  16.  
  17. // This way try all combinations, if there are left any others ;-)
  18. // then get the max of them.
  19.  
  20. if (max < highProduct1)
  21. max = highProduct1;
  22.  
  23. if (max < highProduct2)
  24. max = highProduct2;
  25.  
  26. if (max < highProduct3)
  27. max = highProduct3;
  28.  
  29. if (max < highProduct4)
  30. max = highProduct4;
  31.  
  32. // In the end print out the highest product
  33. System.out.println("Highest product is : " + max);

You can do the same way for the Lowest product.
Last edited by verruckt24; Dec 2nd, 2008 at 10:44 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Need help with max/min'ing multiply

 
0
  #7
Dec 2nd, 2008
read again #2
quuba
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Need help with max/min'ing multiply

 
0
  #8
Dec 2nd, 2008
Your theme posted here is interesting. Min/max, combinatoric algorithms.
Line public static void main(String[] args); change to
public static void main(String[] args){
Add }} at end of program.
Download from http://www.netbeans.org/ NetBans IDE 6.5, select Java SE 37 MB.
and Java SE Development Kit (JDK) 6 Update 11 from http://java.sun.com/javase/downloads/index.jsp ,

or

JDK 6 Update 11 with NetBeans 6.5 from http://java.sun.com/javase/downloads/index.jsp .
It's free.
Install and work.
Advanced editor show to You all wrong points in code before compiling.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 37
Reputation: IMtheBESTatJAVA has a little shameless behaviour in the past 
Solved Threads: 0
IMtheBESTatJAVA IMtheBESTatJAVA is offline Offline
Light Poster

Re: Need help with max/min'ing multiply

 
0
  #9
Dec 3rd, 2008
I'm supposed to use BlueJ and its supposed to be a three-way multiplication, so I was hoping there could be some kind of loop I could use for this. An example for the maximization would be:
(90 + 6) * (80 + 5) * (70 +4)
And minimization would look like:
(10 + 5) * (20 + 6) * (30 + 4)
And somehow in a loop I would have to try each combination, so if I were to do each individually it would look like a bunch of lines of this:
14 * 25 * 36
14 * 26 * 35
15 * 26 * 34
15 * 24 * 36
16 * 25 * 34
16 * 24 * 35

...and that's just minimization.

Update: Now I get an error of ".class expected" for:
  1. if(int input = 0);
Last edited by IMtheBESTatJAVA; Dec 3rd, 2008 at 9:10 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Need help with max/min'ing multiply

 
0
  #10
Dec 3rd, 2008
Originally Posted by IMtheBESTatJAVA View Post
Update: Now I get an error of ".class expected" for:
  1. if(int input = 0);
that's to be expected, remove the ;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC