Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6232421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:06:50+00:00 2026-05-24T10:06:50+00:00

Ok so my program compiles and runs perfectly well, but the purpose is to

  • 0

Ok so my program compiles and runs perfectly well, but the purpose is to convert between celsius, fahernheit, and Kelvin, and when the program runs with the client, it shows the correct units (F,C,K) but gives a value of 50 for all temperatures. How do I fix this?

public class Temperature
{
private double value;
private String scale;

public Temperature()  // default constructor
{
  this.value = 0;
  this.scale = "C";
}

public Temperature(double value, String scale)
{
 this.value = value;
 this.scale = scale;     
}

public double getValue()
{
 return this.value;
}

 public String getScale()
 {
 return this.scale;
 }

 public double getCelsius()
 {

 if (scale.equalsIgnoreCase ("C"))
 {
     return this.value;
 }
 else if (scale.equalsIgnoreCase("F"))
 {
     double faren = ((this.value - 32) * (5/9));
     return faren;
 }
 else
 {
     double kelvin = (this.value - 273.15);
     return kelvin;
 }
 } // end getCelcius

 public double getFaren()
 {
 if (scale.equalsIgnoreCase ("F"))
 {
     return this.value;
 }
 else if (scale.equalsIgnoreCase("C"))
 {
     double celsius = ((this.value * 1.8) + 32);
     return celsius;
 }
 else
 {
     double kelvin = ((this.value * 1.8) - 459.67);
     return kelvin;
 }
 } // ene getFaren

 public double getKelvin()
 {
 if (scale.equalsIgnoreCase("K"))
 {
     return this.value;
 }
 else if (scale.equalsIgnoreCase("C"))
 {
     double celsius = (this.value + 273.15);
     return celsius;
 }
 else
 {
     double faren = ((this.value + 459.67) * (5/9));
     return faren;
 }
 } // end getKelvin

 public void setTemperature(Temperature t)
 {
 this.value = t.value;
 }

 public void setType(double degree, String measure)
 {
 this.value = degree;
 this.scale = measure;
 }

 public void setValue(double degree)
 {
 this.value = degree;
 }

 public void setScale(String measure)
 {
 this.scale = measure;
 }

 public double convertToCelsius()
 {
 this.scale = "C";
 return this.value = getCelsius();
 }

 public double convertToFaren()
 {
 this.scale = "F";
 return this.value = getFaren();
 }

 public double convertToKelvin()
 {
 this.scale = "K";
 return this.value = getKelvin();
 }

 public Temperature clone()
 {
 return new Temperature(this.value, this.scale);
 }

 public boolean equals()
 {
 return this.value == this.value && this.scale == this.scale; 
 }

 public String toString()
 {
 String temps = ("The temperature is " + this.value + "(" + this.scale + ")");
 return temps;
 }

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:06:51+00:00Added an answer on May 24, 2026 at 10:06 am

    You should change

    public double convertToKelvin() {
        this.scale = "K";
        return this.value = getKelvin();
    }
    

    to

    public double convertToKelvin() {
        this.value = getKelvin()
        this.scale = "K";
        return value;
    }
    

    The same for other scales.
    You are setting the scale first, so the object see that the scale is the same and don’t do the conversion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small java program in Netbeans. It compiles and runs perfectly. But
I have an MPI program which compiles and runs, but I would like to
This program in C runs and compiles well : #ifdef HAVE_CONFIG_H #include <config.h> #endif
I'm writing a program for a homework assignment. The program compiles and runs, but
My program compiles and runs correctly but after the execution, my program crashes. Below
My program compiles and runs, but here is my problem. I have a checkbox
when i run my program it compiles fine but when it runs i get
The following C++ program compiles and runs as expected: #include <stdio.h> int main(int argc,
I have a C program which compiles and runs fine under Linux without any
I can't seem to figure this one out. My program compiles and runs successfully,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.