Question

Using the following create the nessecary static methods to pass random arrays with the TempartureWithArrays and Temperature classes

e next 5 static methods in it. (These static methods could also be in the Dem demonstrate passing arrays and returning arrays: Passing Array random number generator as described on the bottom of page 4 o class.) On my website are two example programs that s using static metl 402 to create 3 hods and ChangeArgumentDemo. Use the arrays of random sizes of 1 to 5 elements. is called 3 times to read in Temperature values for each array. I) Create a static void method that has an array parameter and 2) Create a static method that computes and returns the average Iemperature for each array and is also called 3 times. 3) Create a static method that prints the Temperatures of an array 4) Create a static helper method that has 3 array parameters and either returns the largest array or the largest size. 5) Create a static method that returns an array of Temperatures that has the same number of elements as the largest of the three arrays. This method will have 3 array parameters and possibly an integer parameter. It determines the largest Temperature value from the three arrays at each index and creates a copy of this Temperature and stores it at that index of the new array This array is then returned. 6) As this program is running it should generate user friendly text for input and output explaining what the program is doing. Create a set of test value Temperatures that demonstrate that your program runs correctly. (My website gives sample output to follow.)

--------------------------------------------------------------------------------------

public class TemperatureWithArrays
{
   public static final int ARRAY_SIZE = 5;
   public static void main(String[] args)
   {
       int x;
       Temperature temp1 = new Temperature(120.0, 'C');
       Temperature temp2 = new Temperature(100, 'C');
       Temperature temp3 = new Temperature(50.0, 'C');
       Temperature temp4 = new Temperature(232.0, 'K');
       Temperature tempAve = new Temperature(0.0, 'C');
       Temperature[] tempArray = new Temperature[ARRAY_SIZE];//create pointer to array
       Temperature t1;
       for(x = 0; x < tempArray.length; x++)
       {
           t1 = new Temperature();
           tempArray[x] = t1;// fill the array with Temperatures
       }

       System.out.println("Temp1 is " + temp1);
       //temp1 = temp1.toKelvin();
       temp2.toKelvin();
       System.out.println("Temp1 to Kalvin is " + temp1);
       if (temp1.equals(temp3))
       {
           System.out.println("These two temperatures are equal");
       }
       else
       {
           System.out.println("These two temperature are not equal");
       }
       System.out.println("Temp1 is " + temp1);
       System.out.println("Temp2 is " + temp2);
       System.out.println("Temp3 is " + temp3);
       System.out.println("Temp4 is " + temp4);

       tempAve = tempAve.add(temp1);
       tempAve = tempAve.add(temp2);
       tempAve = tempAve.add(temp3);
       tempAve = tempAve.add(temp4);
       tempAve = tempAve.divide(4);
       System.out.println("the average temperatrure is " + tempAve );

       Temperature[] temperatureArrayOne;
       Temperature[] temperatureArrayTwo;
       Temperature[] temperatureArrayThree;
      
       temperatureArrayOne = new Temperature[getRandomArraySize()];
       readTemperatureArray(temperatureArrayOne);
       printTemperatureArray(temperatureArrayOne);
       t1 = getAverage(temperatureArrayOne);
       System.out.println("the average of temperature array one is " + t1);
      
       temperatureArrayTwo = new Temperature[getRandomArraySize()];
       readTemperatureArray(temperatureArrayTwo);
       printTemperatureArray(temperatureArrayTwo);
       t1 = getAverage(temperatureArrayTwo);
       System.out.println("the average of temperature array two is " + t1);
      
       temperatureArrayThree = new Temperature[getRandomArraySize()];
       readTemperatureArray(temperatureArrayThree);
       printTemperatureArray(temperatureArrayThree);
       t1 = getAverage(temperatureArrayThree);
       System.out.println("the average of temperature array three is " + t1);
      
      
       Temperature[] largest = getLargestArray(temperatureArrayOne, temperatureArrayTwo,
               temperatureArrayThree);
       Temperature[] arrayWithLargestValues;
      
       if(temperatureArrayOne == largest)
           arrayWithLargestValues = createArrayWithLargestValues(largest,
                   temperatureArrayTwo, temperatureArrayThree);
       else if(temperatureArrayTwo == largest)
           arrayWithLargestValues = createArrayWithLargestValues(largest,
                   temperatureArrayOne, temperatureArrayThree);
       else// fractionArrayThree is largest
           arrayWithLargestValues = createArrayWithLargestValues(largest,
                   temperatureArrayOne, temperatureArrayTwo);
       System.out.println("An array with the largest values from the 3 arrays is");
       printTemperatureArray(arrayWithLargestValues);
   }    
}

----------------------------------------------------------------------------------------------------

Temperature.java

// declaring headers

import java.io.*;

// declaring class Temperature
public class Temperature
{
// declaring local variables
public double kelv;
public double cels;
public double fahr;
public double temp;
public char scale;

// declaring function temperature
public Temperature(double temp, char scale)
{
  // setting the temperature value
  setTemperature(temp , scale);

  
}
// declaring function Switcherooski
public Temperature Switcherooski(Temperature t){
  
  // checking the condition using switch case
  switch (this.scale)
  {
  
   // checking case condition
   case 'K':
    // calling toKelvin function
    t.toKelv();
    break;
   case 'C':
    // calling celsius function
    t.toCels();
    break;

   case 'F':
    // calling fahrenheit
    t.toFahr();
    break;
   default:
    //displaying
    System.out.println("temperature is Too hot or cold");
    System.exit(0);
    break;
  }
  return this;
}
// setting temperature
private void setTemperature(double temp, char scale) {
   
   // indicate current object
   this.temp = temp;
   this.scale = scale;
}
// adding temperature value
public void add( Temperature t){
  Temperature p = t.Switcherooski(t);
  this.temp += p.temp;
  
}

// subtraction temperature value
public void subtract( Temperature t){
  Temperature p = t.Switcherooski(t);
  this.temp -= p.temp;
}

// multiply temperature value
public void multiply( Temperature t ){
  Temperature p = t.Switcherooski(t);
  this.temp *= p.temp;
}

// divide temperature value
public void divide( int x ){
  this.temp = this.temp / x;
}

// checking boolean condition
public boolean equals(Temperature n) {
  
  if( this.temp == n.temp ){
   return false;
  }else{
   return true;
  }
  
}

// checking the temperature whether its greater than or not
public boolean greaterThan(Temperature n) {
  return this.temp > n.temp;
}

// converting value to string
public String toString(){
  return ""+ this.temp;
}

// calculating kelvin value
public Temperature toKelv()
{
  if( this.scale == 'C')
  {
   this.temp = (this.temp+273.15);
   
  }
  else if( this.scale == 'F')
  {
   this.temp = (((this.temp-32)*5)/9)+273.15;
  }
  
  return new Temperature(this.temp , 'K');
}

// calculating celsius value
public Temperature toCels()
{
  if( this.scale == 'F')
  {
   this.temp =(this.temp - 32) / 1.8;
  }
  else if(this.scale == 'K')
  {
   this.temp = this.temp-273.15;
  }
  
  return new Temperature(this.temp , 'C');
}

// calculating fahrenheit value
public Temperature toFahr()
{
  if( this.scale == 'C')
  {
   this.temp = ( this.temp *1.8)+32;
  }
  else if( this.scale == 'K')
  {
   this.temp = ((this.temp-273.15)*1.8)+32;
  }

  return new Temperature(this.temp , 'F');
}

// reading the value
public String read(){
  return "" + this.temp +" " + this.scale;
  
}
}


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Using the following create the nessecary static methods to pass random arrays with the TempartureWithArrays and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • This is the assignment..... Write a class DataSet that stores a number of values of type...

    This is the assignment..... Write a class DataSet that stores a number of values of type double. Provide a constructor public DataSet(int maxNumberOfValues) and a method public void addValue(double value) that add a value provided there is still room. Provide methods to compute the sum, average, maximum and minimum value. ​This is what I have, its suppose to be using arrays also the double smallest = Double.MAX_VALUE; and double largest = Double.MIN_VALUE;​ are there so I don't need to create...

  • In java Se8 i am trying to write a program convert temperature between celsius, fahrenheit and...

    In java Se8 i am trying to write a program convert temperature between celsius, fahrenheit and kelvin, but i am stuck at how to return the proper result without chage the frame, and I cnould not figure out how to use those three settemp method. import java. uti1. Arrays public class Temperature different scale names/ public static Stringll scales -Celsius", "Fahrenheit", "Kelvin private double temperature private char scale; public Temperature (double temp temp 273. 15; this. scale-C if (temp <-273....

  • pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...

    pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...

  • Ch. 09: Exclusive find in Array (Arrays, conditional, counter) Write a method that will receive an...

    Ch. 09: Exclusive find in Array (Arrays, conditional, counter) Write a method that will receive an array of integers and an integer value as a parameter. The integer value received as the second parameter will be searched within the Array received as the other parameter. The method will return true if the value appears only once in the Array. Use the "documentation shown in the program as a guide". As an example, if the array received was the sequence of...

  • import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new...

    import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //ask the user for a temperature System.out.println("Enter a temperature:"); double temp = scnr.nextDouble(); //ask the user for the scale of the temperature System.out.println("Is that Fahrenheit (F) or Celsius (C)?"); char choice = scnr.next().charAt(0); if(choice == 'F') { //convert to Celsius if given temperature was Fahrenheit System.out.println(temp + " degrees Fahrenheit is " + ((5.0/9) * (temp-32)) + " degrees Celsius"); } else {...

  • must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int...

    must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...

  • departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...

    departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee;    } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...

  • I have a program that reads a file and then creates objects from the contents of...

    I have a program that reads a file and then creates objects from the contents of the file. How can I create a linked list of objects and use it with the package class instead of creating and using an array of objects? I am not allowed to use any arrays of objects or any java.util. lists in this program. Runner class: import java.util.Scanner; import java.io.*; class Runner { public static Package[] readFile() { try { File f = new...

  • // 1. Add methods to get and set, Data and Link. Data should be any Comparable...

    // 1. Add methods to get and set, Data and Link. Data should be any Comparable object. class Node { Integer data; // Integer is Comparable Node link; public Node(Integer data, Node link) { this.data = data; this.link = link; } public Integer getData() { return data; } public void setData(Integer data) { this.data = data; } public Node getLink() { return link; } public void setLink(Node link) { this.link = link; } } // b. Create MyLinkedList class and...

  • Need help Purpose Calculate mileage reimbursements using arrays and methods. The Mathematical Association of America hosts...

    Need help Purpose Calculate mileage reimbursements using arrays and methods. The Mathematical Association of America hosts an annual summer meeting. Each state sends one official delegate to the section officers’ meeting at this summer session. The national organization reimburses the official state delegates according to the scale below. Write a Java program to calculate the reimbursement values, satisfying the specifications below. Details on array and method usage follow these specs. 1. The main method should declare all the variables at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT