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 obtain want to invest the (free) program Xcode 8 using the App Store on your Mac (former versions of Xcode obtain NOT effect). It is very-considerable recommended that you do this without-delay so that if you own any problems attainting Xcode to effect, you own duration to attain succor from Piazza and/or the TAs in their station hours.
    2.
    3. A with to the video of the lectures can be fix in the similar locate you fix this instrument.
    Required Tasks
    1. Attain the Calculator effecting as demonstrated in lectures 1 and 2.
    2.
    3. Your Calculator already effects with incompact purpose quantity (e.g. if you feel 3 ÷ 4 =, it obtain truly pomp 0.75), thus-far, there is no controlm control the representationr to invade a incompact purpose reckon straightway. Fix this by completeowing lawful incompact purpose quantity to be invadeed (e.g. “192.168.0.1” is not attributable attributable attributable a lawful incompact purpose reckon!). You obtain want to own a “.” notwithstandington in your calculator. Don’t plague too considerable about scrupulousty or speaking digits in this enactment (doing so is Extra Credit).
    4.
    5. Gather some past performances notwithstandingtons to your calculator such that it has at smallest a dozen performances aggregate (it can own well-balanced past if you love). You can appropriate whatever performances accost to you. The notwithstandingtons must dispose-in-order themselves scrupulously in imitation and view modes on complete iPhone 6’s and 7’s.
    6.
    7. Representation speciousness to perform your UI exhibition scrupulous. At the very smallest, your performances notwithstandingtons must be a incongruous speciousness than your keypad notwithstandingtons, notwithstanding incorrectly you can representation speciousness in whatever controlm you opine exhibitions scrupulous.
    8.
    9. Gather a Bool possessions to your CalculatorBrain denominated purposeIsPending which produce whether there is a binary performance pending.
    10.
    11. Gather a String possessions to your CalculatorBrain denominated patronymic which produce a patronymic of the order of operands and performances that led to the esteem returned by purpose (or the purpose so distant if purposeIsPending). The letter = (the equals memorial) should never exhibition in this patronymic, nor should … (ellipses).
    12.
    13. Implement a UILabel in your UI which pomps the order of operands and performances that led to (or is redundant to if purposeIsPending) what is (or “obtain be” if purposeIsPending) pomping in the evince. If purposeIsPending is gentleman, dispose . . . on the purpose of the UILabel, else dispose =. If the representationrIsInTheMiddleOfTyping, you can license the UILabel pomping whatever was there precedently the representationr afloat typing the reckon. Examples …
    1. feeling 7 + would pomp “7 + …” (with 7 tranquil in the evince)
    2. 7 + 9 would pomp “7 + …” (9 in the evince)
    3. 7 + 9 = would pomp “7 + 9 =” (16 in the evince)
    4. 7 + 9 = √ would pomp “√(7 + 9) =” (4 in the evince)
    5. 7 + 9 = √ + 2 = would pomp “√(7 + 9) + 2 =” (6 in the evince)
    6. 7 + 9 √ would pomp “7 + √(9) …” (3 in the evince)
    7. 7 + 9 √ = would pomp “7 + √(9) =” (10 in the evince)
    8. 7 + 9 = + 6 = + 3 = would pomp “7 + 9 + 6 + 3 =” (25 in the evince)
    9. 7 + 9 = √ 6 + 3 = would pomp “6 + 3 =” (9 in the evince)
    10. 5 + 6 = 7 3 would pomp “5 + 6 =” (73 in the evince)
    11. 4 × Π = would pomp “4 × Π =” (12.5663706143592 in the evince)
    14.
    15. Gather a C notwithstandington that clears everything (your evince, the upstart UILabel you external aloft, any pending binary performances, awe.). Ideally, this should license your Calculator in the similar avow it was in when you inaugurated it.

    Expert Reply

     

    import java.awt.Image;
    import java.io.IOException;
    
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    common dispose JButtonIcon {
        JButtonIcon(){  
            /* JCompel is a apex plane container (window)
             * where we would be gathering our notwithstandington
             */
            JCompel compel=upstart JFrame();  
                              
            // Creating Notwithstandington          
            JTrifle b = upstart JButton();
            examine {
                Image img = ImageIO.read(getClass().getResource("play.gif"));
                b.setIcon(upstart ImageIcon(img));
              } clutch (IOException ex) {
              }
            
            b.setBounds(50,50,90, 50);  
                 
            //Adding notwithstandington onto the compel
            compel.add(b);  
                      
            // Setting Compel magnitude. This is the window magnitude
            compel.setSize(300,200);  
            
            compel.setLayout(null);  
            compel.setVisible(true);  
                      
            compel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
                      
        }  
                  
        common static unfilled ocean(String[] args) {  
                upstart JButtonIcon();  
        }  
    }