LogoLogo
  • 🌽Introduction
  • 🤖FRC Basics
    • FTC vs FRC
    • Season Timeline
    • Team Resources
  • 📋Team Administration
  • 💼Business
    • Fundraising
      • Sponsors
      • Other Fundraising Opportunities
    • Recruitment
  • 🏫Outreach
    • Summer Camp Planning Guide
      • Junior Bots
      • Junior Bots Challenge
      • Junior Game Jam
      • Mini Bots Workshops
    • Girl Scouts Robotics Badge
      • Programming Robots
      • Designing Robots
      • Showcasing Robots
    • GoBabyGo Instructions
    • FIRST LEGO League
      • Team Quickstart Guide
  • 🏆Awards
    • Machine Creativity Awards
    • Team Attribute Awards
    • Submitted Awards
      • Impact Award
        • Impact Essay
        • Executive Summaries
        • Judging Interview
        • Sample Questions
        • Binder
        • Video
      • Dean's List Award
      • Woodie Flower's Finalist Award
  • ⚙️Mechanical Design
    • CAD
      • FRC Setup
      • FRC CAD Tutorials
      • OnShape Tutorials
      • Getting Started with OnShape
  • ⚡Electrical
    • Basics
  • ⛑️Safety
    • Safety Glasses
    • Shop Safety
      • Machine Tools
        • Drills
        • Drill Press
        • Band Saw
  • 💻Programming
    • Java Programming
      • What is Java?
      • Hello World
      • Printing and Commenting
        • Project: Face Paint
      • Variables
        • Project: Temperature Converter
      • Conditionals
      • Loops and Recursion
      • Object-Oriented Programming
      • Visibility and Statistics
      • Polymorphism
      • Arrays and Collections
      • Miscellaneous
    • How to Solve Programming Problems
    • Version Control
      • Google Drive
      • Git
        • What is Git?
        • How do you use Git?
        • How to use Git (Option 1): Type commands yourself
        • How to use Git (Option 2): Use GitHub Desktop
    • Web Development
  • 📊Scouting & Strategy
    • Basics of Scouting
  • ⚽Competitions
    • Regionals
      • Setup & Practice Matches
      • Qualifications
      • Alliance Selection
      • Playoff Matches
  • 😀Contribute
Powered by GitBook

Iowa City Robotics 2024

On this page

Was this helpful?

Export as PDF
  1. Programming
  2. Java Programming
  3. Variables

Project: Temperature Converter

This project will test your skills creating variables, using arithmetic operators, and casting.

Assignment

The goal of this project is to write a Java program that converts Celsius temperatures to Fahrenheit and Kelvin temperatures.

Recall that the Fahrenheit temperature \( F(c) \) given a Celsius temperature \( c \) is defined as: \[ F(c) = \frac{9}{5}c + 32 \] Additionally, the Kelvin temperature \( K(c) \) given a Celsius temperature \( c \) is defined as: \[ K(c) = c + 273.15 \]

To begin, create a Repl called TemperatureConverter. Copy the following line into the main method:

int celsiusTemp = Integer.parseInt(System.console().readLine("Enter an integral Celsius temperature: "));

This line asks the user for a Celsius temperature as an integer. When the user is done typing the value, they can press the enter key. The integer value is stored inside the variable celsiusTemp.

After that line, create a variable to store the Fahrenheit temperature and another variable to store the Kelvin temperature. Make sure to use the correct data types for these variables, keeping in mind that an integral input in Celsius might lead to a decimal output in Fahrenheit or Kelvin. Use the arithmetic operators you learned and the above formulas to give these variables their values.

Next, print the Fahrenheit and Kelvin temperatures to the console.

If the user enters anything other than an integer as the Celsius temperature, the program will crash. You do not have to worry about this. You can assume that the user input is valid.

Output

This embedded Repl illustrates how your program should work. It also shows the exact format that the output should be in.

Reference Implementation

If you are stuck, you can look at the reference implementation below to see how to write this program.

Click to reveal the reference implementation
class Main {
  public static void main(String[] args) {
    int celsiusTemp = Integer.parseInt(System.console().readLine("Enter an integral Celsius temperature: "));

    // Calculate the temperatures in Fahrenheit and Kelvin
    double fahrenheitTemp = ((double) 9 / 5) * celsiusTemp + 32;
    double kelvinTemp = celsiusTemp + 273.15;

    // Print the output to the console
    System.out.println("The temperature in Fahrenheit is: " + fahrenheitTemp);
    System.out.println("The temperature in Kelvin is: " + kelvinTemp);
  }
}
PreviousVariablesNextConditionals

Last updated 1 year ago

Was this helpful?

💻