Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      From Data To Decisions: UX Strategies For Real-Time Dashboards

      September 13, 2025

      Honeycomb launches AI observability suite for developers

      September 13, 2025

      Low-Code vs No-Code Platforms for Node.js: What CTOs Must Know Before Investing

      September 12, 2025

      ServiceNow unveils Zurich AI platform

      September 12, 2025

      DistroWatch Weekly, Issue 1139

      September 14, 2025

      Building personal apps with open source and AI

      September 12, 2025

      What Can We Actually Do With corner-shape?

      September 12, 2025

      Craft, Clarity, and Care: The Story and Work of Mengchu Yao

      September 12, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Optimizely Mission Control – Part III

      September 14, 2025
      Recent

      Optimizely Mission Control – Part III

      September 14, 2025

      Learning from PHP Log to File Example

      September 13, 2025

      Online EMI Calculator using PHP – Calculate Loan EMI, Interest, and Amortization Schedule

      September 13, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      DistroWatch Weekly, Issue 1139

      September 14, 2025
      Recent

      DistroWatch Weekly, Issue 1139

      September 14, 2025

      sudo vs sudo-rs: What You Need to Know About the Rust Takeover of Classic Sudo Command

      September 14, 2025

      Dmitry — The Deep Magic

      September 13, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: A Steady Ship

    CodeSOD: A Steady Ship

    April 10, 2025
    CodeSOD: A Steady Ship

    You know what definitely never changes? Shipping prices. Famously static, despite all economic conditions and the same across all shipping providers. It doesn’t matter where you’re shipping from, or to, you know exactly what the price will be to ship that package at all times.

    Wait, what? You don’t think that’s true? It must be true, because Chris sent us this function, which calculates shipping prices, and it couldn’t be wrong, could it?

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-built_in">double</span> <span class="hljs-title">getShippingCharge</span>(<span class="hljs-params">String shippingType, <span class="hljs-built_in">bool</span> saturday, <span class="hljs-built_in">double</span> subTot</span>)</span>
    {
        <span class="hljs-built_in">double</span> shCharge = <span class="hljs-number">0.00</span>;
        <span class="hljs-keyword">if</span>(shippingType.Equals(<span class="hljs-string">"Ground"</span>))
        {
            <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">29.99</span> && subTot > <span class="hljs-number">0</span>)
            {
                shCharge = <span class="hljs-number">4.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">99.99</span> && subTot > <span class="hljs-number">29.99</span>)
            {
                shCharge = <span class="hljs-number">7.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">299.99</span> && subTot > <span class="hljs-number">99.99</span>)
            {
                shCharge = <span class="hljs-number">9.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot > <span class="hljs-number">299.99</span>)
            {
                shCharge = subTot * <span class="hljs-number">.05</span>;
            }              
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(shippingType.Equals(<span class="hljs-string">"Two-Day"</span>))
        {
            <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">29.99</span> && subTot > <span class="hljs-number">0</span>)
            {
                shCharge = <span class="hljs-number">14.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">99.99</span> && subTot > <span class="hljs-number">29.99</span>)
            {
                shCharge = <span class="hljs-number">19.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">299.99</span> && subTot > <span class="hljs-number">99.99</span>)
            {
                shCharge = <span class="hljs-number">29.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot > <span class="hljs-number">299.99</span>)
            {
                shCharge = subTot * <span class="hljs-number">.10</span>;
            }              
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(shippingType.Equals(<span class="hljs-string">"Next Day"</span>))
        {
            <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">29.99</span> && subTot > <span class="hljs-number">0</span>)
            {
                shCharge = <span class="hljs-number">24.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">99.99</span> && subTot > <span class="hljs-number">29.99</span>)
            {
                shCharge = <span class="hljs-number">34.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">299.99</span> && subTot > <span class="hljs-number">99.99</span>)
            {
                shCharge = <span class="hljs-number">44.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot > <span class="hljs-number">299.99</span>)
            {
                shCharge = subTot * <span class="hljs-number">.15</span>;
            }              
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(shippingType.Equals(<span class="hljs-string">"Next Day a.m."</span>))
        {
            <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">29.99</span> && subTot > <span class="hljs-number">0</span>)
            {
                shCharge = <span class="hljs-number">29.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">99.99</span> && subTot > <span class="hljs-number">29.99</span>)
            {
                shCharge = <span class="hljs-number">39.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot <= <span class="hljs-number">299.99</span> && subTot > <span class="hljs-number">99.99</span>)
            {
                shCharge = <span class="hljs-number">49.95</span>;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(subTot > <span class="hljs-number">299.99</span>)
            {
                shCharge = subTot * <span class="hljs-number">.20</span>;
            }              
        }                                      
        <span class="hljs-keyword">return</span> shCharge;
    }
    

    Next you’re going to tell me that passing the shipping types around as stringly typed data instead of enums is a mistake, too!

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous Articleautoenv provides directory based environments
    Next Article 8 Best Free and Open Source Terminal-Based Flashcard Tools

    Related Posts

    News & Updates

    DistroWatch Weekly, Issue 1139

    September 14, 2025
    News & Updates

    Building personal apps with open source and AI

    September 12, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Mistral-Small-3.2-24B-Instruct-2506 is now available on Amazon Bedrock Marketplace and Amazon SageMaker JumpStart

    Machine Learning

    How to Shut Down Windows 11

    Operating Systems

    CVE-2025-7125 – iSourcecode Employee Management System SQL Injection

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-46823 – OpenMRS FHIR2 Privilege Escalation Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-46741 – Blueframe Session Fixation Vulnerability

    May 12, 2025

    CVE ID : CVE-2025-46741

    Published : May 12, 2025, 5:15 p.m. | 2 hours, 27 minutes ago

    Description : A suspended or recently logged-out user could continue to interact with Blueframe until the time-out period occurred.

    Severity: 5.7 | MEDIUM

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Found in the wild: 2 Secure Boot exploits. Microsoft is patching only 1 of them.

    June 10, 2025

    CVE-2025-42971 – SAPCAR Out-of-Bounds Memory Corruption Vulnerability

    July 7, 2025

    Microsoft Teams updated with a feature you probably thought already existed — “Can you hear me?” is now a thing of the past

    August 24, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.