-2

I'm new at Java and I'm trying to call a get method from a different public class. The code processes but 'answer' returns "WineTempTime$Winechiller@45ee12a7" for some reason I can't figure out.

Is there an issue in my method definition or is it a problem with the method constructor? Grateful for help!

Here's the code:

import java.util.Scanner;

public class WineTempTime {

public static void main(String[] args) {

   // code that inputs double wineTemp, preferedTemp, chillTemp here

        Winechiller answer = new Winechiller();
        answer.getChillingtime(wineTemp, preferedTemp, chillTemp);

        System.out.print("It takes " + answer + " minutes for wine to 
reach desired temperature.");
    }   
}

public static class Winechiller {

// constructors
static final double DELTA_MINUTES = 0.1;
static final int TAO = 50;
WineTempTime wineTemp = new WineTempTime();
WineTempTime preferedTemp = new WineTempTime();
WineTempTime chillTemp = new WineTempTime();
double timeCount = 0;

// equation for minutes until reaches temperature 
public int getChillingtime(double wineTemp, double preferedTemp, double 
chillTemp) {
    while (wineTemp > preferedTemp) {
        double tempDecrease = ( (wineTemp - chillTemp) / TAO ) 
        * DELTA_MINUTES;
        wineTemp -= tempDecrease;
        ++timeCount; }
    timeCount /= 10;
    Math.round(timeCount);
    int minutes = (int)timeCount;
    return minutes;     
    }
}
}
Pang
  • 9,564
  • 146
  • 81
  • 122
ooo
  • 21
  • 2
  • 1
    It's not a duplicate of that question, the OP doesn't know that she should assign the result of the method to a variable to print it - she wants to print an integer, not the `answer` object! – Erwin Bolwidt Jun 24 '17 at 13:52

2 Answers2

1

You should print out the result of the method answer.getChillingtime, instead of answer.

int minutes = answer.getChillingtime(wineTemp, preferedTemp, chillTemp);
System.out.print("It takes " + minutes + " minutes for wine to reach desired temperature.");
Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
1

In you code you have printed the answer directly Don't print it directly .

print as

 System.out.print("It takes " + answer.getChillingtime(wineTemp, preferedTemp, 
    chillTemp) + " minutes for wine to reach desired temperature.");

and you called the function getChillingtime() without storing it Because it returns an integer. so you exclude the line

 answer.getChillingtime(wineTemp, preferedTemp, chillTemp);

In your program you printed answer As answer is an object of Winechiller class ,So while you try to print answer you will get the information of the answer object because the statement

System.out.println(answer);

gets converted to form

 System.out.println(answer.toString());

where toString() is the method of Object class which is the super of all java classes.

Madhusudan chowdary
  • 543
  • 1
  • 12
  • 20