Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**Will Rate Lifesaver** Create a class. Create a class named snow with the follo

ID: 3622984 • Letter: #

Question


**Will Rate Lifesaver**
Create a class.

Create a class named snow with the following minimum requirements:

Data members: 2 - inches (how many inches did we get), type (fluffy, wet, yellow and whatever else you want)
Default Constructor: 2 – 1 with no parameters and 1 with at least 1 parameter
Class methods (not including default constructor): 6 – 1 set/get pair for each data member (4 methods), 1 to display all data members and 1 that modifies a data member based on the evaluation of criteria you pass to the method (an “if” statement). You will add an additional method that will make use of a one-dimensional array that is passed to it from the test program. This can be something like printArray, which will print the contents of the array defined in the test program.

Create a test program.

You will modify another program to test the functionality of the class you have modified. The test program will have the following minimum requirements:

Create a one-dimensional array – Once your class object is instantiated with the default constructor with no parameters, you will create a one-dimensional array that will be passed to the method you created in the class template. The array will be initialized with at least 5 values.

Flow of the Test program:

Create and initialize a one-dimensional array
Instantiate the class object with no parameters
Sentinel-value while loop
Get data member 1 and assign it to a variable
Display the variable contents
Get data member 2 and assign it to a different variable
Display the variable contents
Set data member 1
Set data member 2
Use display method to show variable contents
Use modify method to change a data member
Use display method to show variable contents
Check sentinel value to see if you want to continue
End loop
Instantiate another class with parameters
Use display method to show variable contents
Use new array method to show array contents
End of program

Explanation / Answer


import java.util.Scanner;


public class snow {
    // Data members: 2 - inchess, type
    private int inches;
    private String type;
    // Default Constructor with no parameter
    public snow()
    {
        this.inches = 0;
        this.type = "NULL";
    }
    // Default Constructor with atleast one parameter
    public snow(int inches, String type) {
        this.inches = inches;
        this.type = type;
    }
    // set method
    public void setInches(int inches) {
        this.inches = inches;
    }
    // set method
    public void setType(String type) {
        this.type = type;
    }
    // get method
    public int getInches() {
        return inches;
    }
    // get method
    public String getType() {
        return type;
    }
    // display all
    public void dislay()
    {
        System.out.println("Total no of inches " + inches);
        System.out.println("And its Type is " + type);
    }
    // modify value based on if statement
    public void modify()
    {
        if(inches > 20)
            inches = inches+ 10;
    }
    // print values
    public void printArray(int[] k)
    {
        System.out.println("array elements are");
        for(int i=0; i<k.length; i++)
        {
            System.out.println("array"+ "[" + i+ "]=" + k[i]);
        }
    }

    public static void main(String[] args) {
        int od[]={73,85,95,90,98}; //Create a one-dimensional array
        int d1;
        String d2;
        snow s1 = new snow(); // class object is instantiated with the default constructor with no parameters
        s1.printArray(od);
        int k=1;
        while(k!=0)
        {
            d1 = s1.getInches(); //Get data member 1 and assign it to a variable
            System.out.println("inches we got is " + d1); // Display the variable contents
            d2 = s1.getType(); //Get data member 2 and assign it to a different variable
            System.out.println("type we got is " + d2); // Display the variable contents
            s1.setInches(44);   // Set data member 1
            s1.setType("yellow"); // Set data member 2
            s1.dislay(); // Use display method to show variable contents
            s1.modify(); //Use modify method to change a data member
            s1.dislay(); // Use display method to show variable contents
            Scanner in = new Scanner(System.in);
            System.out.println("if you wanted to end loop enter 0"); // Check sentinel value to see if you want to continue
            k = in.nextInt();
        } // End loop
        snow s2 = new snow(13,"wet"); // Instantiate another class with parameters
        s2.dislay(); // Use display method to show variable contents
        s2.printArray(od); // Use new array method to show array contents

    }

}