Explain the fundamental principles of thermodynamics, including the first and second laws, and discuss how these principles are applied in the design and analysis of heat engines and refrigeration cycles.