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

  • SEARCH
  • Home
  • 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 8836321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:28:11+00:00 2026-06-14T09:28:11+00:00

I am in this Java class and I am basically trying to be an

  • 0

I am in this Java class and I am basically trying to be an overachiever but I have spent most of the time trying to figure out things and its not working.

I am creating an ArrayList of the Temperature class.

List<Temperature> templist = new ArrayList<Temperature>();
Temperature t1 = new Temperature ();

for (number of loops user wants) 
{
 templist.add(t1)
}

But my Temeperature class has both the number and the scale. So when I dispay t1 it looks this

Temperature [degrees=43.0, scale=F]  

how to I utilized my getDegrees() and getScale() method to just extract just the degrees and scales separately. also i need to get a min, max and avg. I know how to do that using for loop but since there are instance of classes involved can that still possible ?

So basically this is what i have

Temperature.java

import java.util.Scanner;

/*
 * This class represents a temperature value.
 */
    public class Temperature {

private double degrees;
private char scale;
Scanner s = new Scanner (System.in);



public Temperature (){
this.degrees = 0 ;
this.scale = 'F' ;
    }



public double getDegrees() {
    return degrees;
}

//public double getDegreesF(){
//  return degrees;
//}

public double getDegreesC(Temperature temperature)

{
         if (scale == 'C') 
             return degrees;
         else if (scale == 'F')
           degrees = ((degrees - 32)*(5)/(9));
           return degrees;


}



public void setDegrees(double degrees) {
    this.degrees = degrees;
}

public char getScaleC() {
     scale = 'C';
    return scale;
}



    public void setScale(char scale) {

    while  ((scale != 'C') && (scale !='F') )

       {

        System.out.println("Please enter correct value");
        scale = s.next().charAt(0);
      } 

    this.scale = scale;
}


@Override
public String toString() {
    return "Temperature [degrees=" + degrees + ", scale=" + scale + "]";
}


    }

 Test Temperature.java

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;




public class TestTempreture {

    /**
     * @param args
     */
    public static void main(String[] args) {

        int numberoftimes = 0 ;


        Scanner s = new Scanner (System.in);

        Temperature t1 = new Temperature ();
        List<Temperature> templist = new ArrayList<Temperature>();

        for (int i = 0; i < numberoftimes; i ++  )

        {

            t1.setDegrees(s.nextInt());
            t1.setScale(s.next().charAt(0));
            templist.add(t1);


        }


        System.out.println(templist.get(0));
  • 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-06-14T09:28:13+00:00Added an answer on June 14, 2026 at 9:28 am

    The problem is, ArrayList doesn’t know how to calculate min, max, and average. You could use a loop in your main code, or you could use composition…

    public class AllTemps {
        private static final ArrayList<Temperature> temps = new ArrayList<Temperature>();
        private Temperature min = null;
    
        public AllTemps() { }
    
        public boolean add(Temperature t) {
            updateMin(t);
            return temps.add(t);
        }
    
        // Here you would implement any other methods to access the ArrayList that you need
    
        private void updateMin(Temperature t) {
            if (min == null) {
                min = t;
            } else {
                if(min.getDegrees() > t.getDegrees()) min = t;
            }
        }
    }
    

    And then you can implement calculating the max, average, etc. the same way.

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

Sidebar

Related Questions

I have spent most of a day trying to understand why Java cannot compile
I have a file in .gz format. The java class for reading this file
I have an application which resides in ROOT. This application has a java class(in
I have a short question i have wrote this in java. Old code: class
I'm trying to figure out a way to make a Java application invisible to
I am new into java world.. But basically I am trying to write a
I know this is a messy implementation, but I basically have this code (I
I am trying to implement A* in Java but i have hit a brick
This is my gridview.java class public class TextGridActivity extends Activity { String[] _cataId=new String[100]
Considering this part of a Java class, private List<Object> components = new ArrayList<Object>(); private

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.