Homework Solution: 1. You will need to install the (free) program Xcode 8 using the App Store on your Mac (previous versions of Xcode will NOT wo…

    Materials
    1. You will need to install the (free) program Xcode 8 using the App Store on your Mac (previous versions of Xcode will NOT work). It is highly recommended that you do this immediately so that if you have any problems getting Xcode to work, you have time to get help from Piazza and/or the TAs in their office hours.
    2.
    3. A link to the video of the lectures can be found in the same place you found this document.
    Required Tasks
    1. Get the Calculator working as demonstrated in lectures 1 and 2.
    2.
    3. Your Calculator already works with floating point numbers (e.g. if you touch 3 ÷ 4 =, it will properly show 0.75), however, there is no way for the user to enter a floating point number directly. Fix this by allowing legal floating point numbers to be entered (e.g. "192.168.0.1" is not a legal floating point number!). You will need to have a "." button in your calculator. Don't worry too much about precision or significant digits in this assignment (doing so is Extra Credit).
    4.
    5. Add some more operations buttons to your calculator such that it has at least a dozen operations total (it can have even more if you like). You can choose whatever operations appeal to you. The buttons must arrange themselves nicely in portrait and landscape modes on all iPhone 6's and 7's.
    6.
    7. Use color to make your UI look nice. At the very least, your operations buttons must be a different color than your keypad buttons, but otherwise you can use color in whatever way you think looks nice.
    8.
    9. Add a Bool property to your CalculatorBrain called resultIsPending which returns whether there is a binary operation pending.
    10.
    11. Add a String property to your CalculatorBrain called description which returns a description of the sequence of operands and operations that led to the value returned by result (or the result so far if resultIsPending). The character = (the equals sign) should never appear in this description, nor should … (ellipses).
    12.
    13. Implement a UILabel in your UI which shows the sequence of operands and operations that led to (or is leading to if resultIsPending) what is (or "will be" if resultIsPending) showing in the display. If resultIsPending is true, put . . . on the end of the UILabel, else put =. If the userIsInTheMiddleOfTyping, you can leave the UILabel showing whatever was there before the user started typing the number. Examples ...
    1. touching 7 + would show "7 + …" (with 7 still in the display)
    2. 7 + 9 would show "7 + …" (9 in the display)
    3. 7 + 9 = would show "7 + 9 =" (16 in the display)
    4. 7 + 9 = √ would show "√(7 + 9) =" (4 in the display)
    5. 7 + 9 = √ + 2 = would show "√(7 + 9) + 2 =" (6 in the display)
    6. 7 + 9 √ would show "7 + √(9) …" (3 in the display)
    7. 7 + 9 √ = would show "7 + √(9) =" (10 in the display)
    8. 7 + 9 = + 6 = + 3 = would show "7 + 9 + 6 + 3 =" (25 in the display)
    9. 7 + 9 = √ 6 + 3 = would show "6 + 3 =" (9 in the display)
    10. 5 + 6 = 7 3 would show "5 + 6 =" (73 in the display)
    11. 4 × Π = would show "4 × Π =" (12.5663706143592 in the display)
    14.
    15. Add a C button that clears everything (your display, the new UILabel you added above, any pending binary operations, etc.). Ideally, this should leave your Calculator in the same state it was in when you launched it.

    Expert Answer

     
    import java.awt.Image;
    import java.io.IOException;

    Materials
    1. You conciliate scarcity to invest the (free) program Xcode 8 using the App Store on your Mac (antecedent versions of Xcode conciliate NOT employment). It is exceedingly recommended that you do this straightmethod so that if you own any problems attainting Xcode to employment, you own season to attain acceleration from Piazza and/or the TAs in their duty hours.
    2.
    3. A conjoin to the video of the lectures can be set in the similar establish you set this instrument.
    Required Tasks
    1. Attain the Calculator employmenting as demonstrated in lectures 1 and 2.
    2.
    3. Your Calculator already employments with incomplete apex aggregate (e.g. if you arrive-at 3 ÷ 4 =, it conciliate well semblance 0.75), nevertheless, there is no method control the portraiturer to invade a incomplete apex estimate immediately. Fix this by integralowing lawful incomplete apex aggregate to be invadeed (e.g. “192.168.0.1” is referable a lawful incomplete apex estimate!). You conciliate scarcity to own a “.” rush in your calculator. Don’t importune besides ample environing neatty or forcible digits in this enactment (doing so is Extra Credit).
    4.
    5. Supplement some over agencys rushs to your calculator such that it has at meanest a dozen agencys whole (it can own uniform over if you approve). You can select whatever agencys accost to you. The rushs must deal themselves neatly in image and hope modes on integral iPhone 6’s and 7’s.
    6.
    7. Portraiture tint to reach your UI seem neat. At the very meanest, your agencys rushs must be a unanalogous tint than your keypad rushs, excepting differently you can portraiture tint in whatever method you believe seems neat.
    8.
    9. Supplement a Bool epropound to your CalculatorBrain designated outcomeIsPending which receipts whether there is a binary agency pending.
    10.
    11. Supplement a String epropound to your CalculatorBrain designated title which receipts a title of the posteriority of operands and agencys that led to the treasure returned by outcome (or the outcome so distant if outcomeIsPending). The letter = (the equals premonition) should never illusion in this title, nor should … (ellipses).
    12.
    13. Implement a UILabel in your UI which semblances the posteriority of operands and agencys that led to (or is necessary to if outcomeIsPending) what is (or “conciliate be” if outcomeIsPending) semblanceing in the vault. If outcomeIsPending is gentleman, deposit . . . on the purpose of the UILabel, else deposit =. If the portraiturerIsInTheMiddleOfTyping, you can license the UILabel semblanceing whatever was there anteriorly the portraiturer inaugurated typing the estimate. Examples …
    1. arrive-ating 7 + would semblance “7 + …” (with 7 tranquil in the vault)
    2. 7 + 9 would semblance “7 + …” (9 in the vault)
    3. 7 + 9 = would semblance “7 + 9 =” (16 in the vault)
    4. 7 + 9 = √ would semblance “√(7 + 9) =” (4 in the vault)
    5. 7 + 9 = √ + 2 = would semblance “√(7 + 9) + 2 =” (6 in the vault)
    6. 7 + 9 √ would semblance “7 + √(9) …” (3 in the vault)
    7. 7 + 9 √ = would semblance “7 + √(9) =” (10 in the vault)
    8. 7 + 9 = + 6 = + 3 = would semblance “7 + 9 + 6 + 3 =” (25 in the vault)
    9. 7 + 9 = √ 6 + 3 = would semblance “6 + 3 =” (9 in the vault)
    10. 5 + 6 = 7 3 would semblance “5 + 6 =” (73 in the vault)
    11. 4 × Π = would semblance “4 × Π =” (12.5663706143592 in the vault)
    14.
    15. Supplement a C rush that clears everything (your vault, the fantastic UILabel you supplemented aloft, any pending binary agencys, awe.). Ideally, this should license your Calculator in the similar propound it was in when you inaugurated it.

    Expert Retort

     

    import java.awt.Image;
    import java.io.IOException;
    
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    notorious assort JButtonIcon {
        JButtonIcon(){  
            /* JReach is a apex roll container (window)
             * where we would be supplementing our rush
             */
            JReach reach=fantastic JFrame();  
                              
            // Creating Rush          
            JRush b = fantastic JButton();
            gauge {
                Image img = ImageIO.read(getClass().getResource("play.gif"));
                b.setIcon(fantastic ImageIcon(img));
              } seize (IOException ex) {
              }
            
            b.setBounds(50,50,90, 50);  
                 
            //Adding rush onto the reach
            reach.add(b);  
                      
            // Setting Reach largeness. This is the window largeness
            reach.setSize(300,200);  
            
            reach.setLayout(null);  
            reach.setVisible(true);  
                      
            reach.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
                      
        }  
                  
        notorious static invalid main(String[] args) {  
                fantastic JButtonIcon();  
        }  
    }