Solar Panels – 70 course points

In this assignment, you will use OOP to represent, manipulate, and work with solar panels and parking lot projects.

Start your assignment early!
You need time to understand the assignment and to answer the many questions that will arise as you read the description and the code provided.

Refer to our Programming Assignments FAQ for instructions on how to install VSCode, how to use the command line and how to submit your assignments.

The assignment has two components:

  1. Coding (77 points) submitted through Autolab due 11/25 at 11PM

  2. Reflection (3 points) submitted through a form due 11/30 at 11PM

    • Submit the reflection AFTER you have completed the coding component.

    • Be sure to sign in with your RU credentials! (netid@scarletmail.rutgers.edu)

    • You cannot resubmit reflections but you can edit your responses before the deadline by clicking the Google Form link, signing in with your net id, and selecting “Edit your response”

Overview

Rutgers has hired you as a solar panel consultant – congrats! You’re in charge of setting up solar panels on top of parking lots – right now, Rutgers has a large number of solar panels to generate electricity and reduce carbon emissions, but you’ll need to work to lay out more panels given a set of maps.

More specifically, you will work with the following:

  • A street map containing parking lots (always labeled “P#” where # is a number) and other road features that are solely meant for decorations. Don’t place a solar panel in the middle of a road!

  • An Array of parking lot objects, containing info like budget, parking lot, max panels, and capacity.

  • An array of Panel objects that contain individual solar panels at particular positions. This array has the same size as the street map, and a certain position [i][j] refers to THE SAME position in the street map.

Implementation

Overview of files provided

  • The SolarPanels class contains the methods you will use to work with the panels; you will submit this file to Autolab.

  • The Panels class contains information about a SINGLE solar panel. Do not edit or submit to Autolab.

    • The Panel class comes with the following implemented methods:

      • getRatedEfficiency: returns the rated efficiency.

      • setRatedEfficiency(double ratedEfficiency): sets the rated efficiency to the parameter value.

      • getActualEfficiency(): returns the actual efficiency of the panel.

      • setActualEfficiency(double actualEfficiency): sets the actual efficiency of the panel to the parameter value.

      • getElectricityGenerated(): returns the electricity generated by the panel.

      • setElectricityGenerated(int electricityGenerated): sets the amount of electricity generated by the panel to the parameter value.

      • isWorking(): returns true if the panel is working, false otherwise.

      • setIsWorking(boolean isWorking): sets isWorking status of the panel to parameter value.

  • The ParkingLot class contains information about a parking lot and the project to build panels on that lot. Do not edit or submit to Autolab.

    • The ParkingLot class comes with the following implemented methods:

      • getLotName(): returns the name of the parking lot.

      • getMaxPanels(): returns the maximum number of panels that can be installed.

      • getBudget(): returns the budget allocated for the parking lot.

      • getEnergyCapacity(): returns the energy capacity of the parking lot.

      • setEnergyCapacity(int energyCapacity): sets the energy capacity of the parking lot to the parameter value.

      • getPanelEfficiency(): returns the efficiency of the solar panels.

      • setPanelEfficiency(double panelEfficiency): sets the panel efficiency to the parameter value.
         

  • Multiple input files are included to test your code; You are welcome to create your own input files, as they will not be submitted to Autolab.

  • The AnimatedDriver and TextDriver classes are used to test your methods interactively. Do not submit to Autolab.

    • USE TextDriver to test first, it is simpler to use. We suggest that you start with the text driver but once you have a good understanding of the assignment then you may use the graphic driver.

    • Both drivers function the same way – if it works on one driver it’ll work on the other.

  • Go to TextDriver.java and run by clicking the play button in the top right hand corner. It’ll prompt you to enter the name of the input file you want to test, once you enter the input file name, it should give you the following testing options:

Enter the number corresponding to the method you want to test to proceed.

Similarly, go to the file AnimatedDriver.java and run by clicking the play button in the top right hand corner.

The image above shows what the AnimatedDriver looks like when you first run it. Enter the number corresponding to the method you want to test to proceed.

SolarPanels.java

  • DO NOT add new import statements.

  • DO NOT change any of the method’s signatures.

  • YOU MAY only update the methods with the WRITE YOUR CODE HERE line.

  • COMMENT all additional print statements you have written from SolarPanels.java

  • DO NOT add any instance variables to the SolarPanels.java class.

  • DO NOT add any public methods to the SolarPanels.java class.

  • DO NOT add/rename the project or package statements.

  • DO NOT change the SolarPanels.java class name.

  • YOU MAY add private methods to the SolarPanels.java class.

  • DO NOT use System.exit()

 Methods to be implemented by you:

 setupStreetMap(String streetMapFile)

This method updates the instance variable streetMap to be a 2D array of Strings (each String is a label representing a road feature or parking lot label).

To complete this method:

  • Set standard input to the file name in the parameter by using StdIn.setFile.

  • Read the length of the array, given as an integer

  • Read the width of the array, given as an integer

  • Update streetMap to be a 2D array of strings of size l x w 

  • Read the next l x w strings from the input file and store each string in its corresponding position in the streetMap.

Use the StdIn library to read from a file:

  • StdIn.setFile(filename) opens a file to be read.

  • StdIn.readInt() reads the next integer value from the opened file 

  • StdIn.readDouble() reads the next double value from the opened file

  • StdIn.readString() reads the next String value from the opened file.

Testing:

Here is the expected output for this method in the TextDriver using street1.in. NOTE that both drivers will give you the same output — using one is equivalent.

  • P#: represents a parking lot, where # indicates the parking lot number. (Ex: P1 represents parking lot 1)
  • RD: represents a horizontal road.
  • VR: represents a vertical road.
  • JN: represents a junction that connects 2 or more roads.
  • CR: represents a construction area. 

To test using the AnimatedDriver, run the AnimatedDriver.java class, enter 1 and type the input file name:

Once you hit enter, you should see the following output if your method is implemented correctly:

 

setupParkingLots(String parkingLotFile)

This method updates the instance variable lots to store information about the lots you’ll build solar panels on. This way, you use your budgeted amounts of panels and money correctly.

To complete this method:

  • Set standard input to the file name in the parameter by using StdIn.setFile.

  • Read the number of parking lots, given as an integer (n).

  • Initialize the instance variable lots as an array of ParkingLot object of size n. 

  • You will see n lines in the input file, each line represents one lot. (the values on each line are separated by spaces) Read the values in the following order:

    • The name, as one string

    • The maximum number of panels, as an int

    • The budget you have, as a double

    • The energy capacity, as an int

    • The panel efficiency, as a double

  • For each line, create a ParkingLot object using these values and add it to the corresponding position in the lots array.

Here is the expected output for this method using street1.in and lots1.in for the TextDriver. Run setupStreetMap followed by setupParkingLots IN that order.

Lots are formatted as {lotName, maxPanels, budget, energyCapacity, panelEfficiency}.

To test using the AnimatedDriver, run the AnimatedDriver.java class. Run setupStreetMap, once you see the output for setupStreetMap, hit enter and the driver should give you the following options:

Hit 2 to test setUpParkingLots and enter the input file name.

Once you hit enter again, you should see the following output if your method was implemented correctly. (Make sure to run setupStreetMap before testing setUpParkingLots.)

insertPanels(double costPerPanel)

In this method, you’ll go ahead and build the panels on each lot! You will be given a cost per panel.

To complete this method:

  • Initialize the instance variable panels as a 2D array of Panel objects with the same dimensions as streetMap. 

  • For each parking lot:

    • Keep track of the current budget and current panels so far (right now, that’s 0).

    • Traverse the streetMap and for each cell, check if:

      • The cell equals the current parking lot’s name.

      • Adding a new panel doesn’t give you a negative balance (exactly zero is okay).

      • The number of panels installed so far is less than the maximum number of panels allowed for this lot.

    • If those conditions are met:

      • We will randomly generate a value to determine whether or not the panel works.

      • StdRandom.uniform() returns a double from 0 up to but not including 1. Use this to get a random double – if it’s less than 0.95 the panel works, if greater than or equal to the panel is broken.

    • Create a new Panel object using the parking lot’s panel efficiency, energy capacity, and the randomly generated working status. 

    • Store the new Panel in the corresponding position in the panels array.

    • Make sure to update the number of current panels and budget accordingly after inserting the panel.

Here is the expected output for this method using street1.in, lots1.in and a cost per panel of $1,000. Run setupStreetMap and setupParkingLots in the driver before running this method.

Panels are formatted as {ratedEfficiency, actualEfficiency, electricityGenerated, maxOutput, works}.

Here is what the expected output should be for the AnimatedDriver (Make sure to run methods 1 and 2 before running insertPanels):

Blue indicates the panel works and red indicates it does not.

updateActualEfficiency(int temperature, double coefficient)

Panels are most optimal at a temperature of 77 degrees Fahrenheit. They tend to perform worse in hotter temperatures and better in colder temperatures.

We will simulate this behavior through a method that takes in a temperature and a coefficient.

We calculate change in efficiency as follows:

coefficient * (temperature – 77).

Note: when the temperature is below 77 degrees, the panels will experience an efficiency gain. When the temperature is above 77 degrees, the panels will experience an efficiency loss.

For example:

  • Temperature = 85, coefficient = -0.35

    • Change in efficiency = -0.35 * (85 – 77) = -2.8

    • If the rated efficiency is 20.2, the actual efficiency becomes 20.2 + (-2.8) = 17.4

  • Temperature = 70, coefficient = -0.35

    • Change in efficiency = -0.35 * (70 – 77) = 2.45

    • If the rated efficiency is 20.2, the actual efficiency becomes 20.2 + (2.45) = 22.65

Your task is to update the actual efficiency of every existing panel in the panels 2D array to account for the efficiency loss or gain, relative to their rated efficiency.

Here is the expected output for this method using street1.in, lots1.in and a cost per panel of $1,000, as well as a temperature of 85 degrees and a coefficient of -0.35. Run all previous methods before running this.

Panels are formatted as {ratedEfficiency, actualEfficiency, electricityGenerated, maxOutput, works}.

updateElectricityGenerated()

This method updates the instance variable, electricityGenerated of each panel, to reflect the amount of electricity it generates in one day.

We calculate the amount of electricity generated by a solar panel in one day using the following formula: power output in watts * average hours of peak sunlight = daily watt-hours.

The power output of a solar panel is determined by its efficiency. The panels you are installing have an area of 1.5 square meters. Direct solar radiation provides about 1000 watts per square meter. At 100% efficiency, your panels should produce 1500 watts of electricity. However, solar panels do not operate at 100% efficiency. For example, a panel with 20% efficiency, converts only about 20% of its potential power input into electricity, hence:

(20 / 100) * 1500 = 300 watts

Therefore, we calculate the power output of a solar panel using the following formula:
power output = (actual efficiency / 100) * 1500.

Note that on average New Jersey receives approximately 4 hours of peak sunlight. 

To complete this method:

  • Traverse through the panels 2D array.

  • For each working panel, calculate its electricity generated for one day using its actual efficiency and the average of 4 hours of peak sunlight. 

  • Updated the electricityGenerated instance variable for each panel.

    • Make sure to convert the result into an integer and round down.

Here is the expected output for this method using street1.in, lots1.in and a cost per panel of $1,000, as well as a temperature of 85 degrees and a coefficient of -0.35. Run all previous methods before running this.

Panels are formatted as {ratedEfficiency, actualEfficiency, electricityGenerated, maxOutput, works}.

countWorkingPanels(String parkingLot)

This method counts and returns the number of working panels in a parking lot. Note that the method will pass in a String indicating the parking lot name.

Traverse the streetMap array, check that you are (1) in the specified parking lot and (2) whether the panel at that corresponding position is working. As you find working panels in the specified parking lot, increment your count.

Here is the expected output for this method using street1.in, lots1.in and a cost per panel of $1,000. Run setupStreetMap, setupParkingLots, and insertPanels before testing.

Use P2 as the lot name.

 

updateWorkingPanels()

Upon installation, solar panels have a 95% chance of working. In this method, you will find the broken panels in the panels 2D array, and repair them.

Once you find a broken panel, update the instance variable, isWorking, to reflect the working status of the panel. This method should return the number of working panels in the array after the repairs have been made.

Here is the expected output for this method using street1.in, lots1.in and a cost per panel of $1,000. Run setupStreetMap, setupParkingLots, and insertPanels before testing.

Panels are formatted as {ratedEfficiency, actualEfficiency, electricityGenerated, maxOutput, works}.

Blue indicates a panel works.

calculateSavings()

This method calculates and returns how much money Rutgers will save on electricity in one year with the installation of a solar panel project.

Rutgers spends approximately $60 million funding approximately 4.27 million kilowatt-hours of electricity a year.

We calculate the money Rutgers will save by determining what percentage of Rutgers’ yearly electricity needs can be met by the electricity generated by all the panels in a Project.

For example, imagine one solar panel project can produce enough electricity to cover 10% of Rutgers’ yearly electricity needs. Since Rutgers needs 10% less power from their utility provider, their electricity bill would be down to $54 million, meaning they will save $6 million a year on electricity.

Note that in updateElectricityGenerated(), you calculated the amount of electricity each solar panel generates in one day, measured in watt-hours. In this method, you will be calculating the amount of electricity generated by all panels in the project in one year, measured in kilowatt-hours.

To calculate the yearly savings:

  • Find total electricity by adding up the electricity generated by all panels and multiply by 0.001 to convert to kilowatt-hours.

  • Then, multiply that amount by 365 to capture a year’s worth of electricity. Divide that by 4270000 to compare against Rutgers’ needs, and multiply the result by 60000000 to calculate the portion of money saved.

Finally return the total amount of money saved. 

Here is the expected output for this method using street1.in, lots1.in and a cost per panel of $1,000, as well as a temperature of 85 degrees and a coefficient of -0.35. Run all previous methods besides countWorkingPanels and updateWorkingPanels before testing.

By Jessica de Brito and Kal Pandit

Implementation Notes

  • YOU MAY only update the methods with the WRITE YOUR CODE HERE line.

  • COMMENT all additional print statements you have written from SolarPanels.java

  • DO NOT add any instance variables to the SolarPanels.java class.

  • DO NOT add any public methods to the SolarPanels.java class.

  • DO NOT add/rename the project or package statements.

  • DO NOT change the SolarPanels class name.

  • YOU MAY add private methods to the SolarPanels class.

  • YOU MAY use any of the libraries provided in the zip file.

  • DO NOT use System.exit()

VSCode Extensions

You can install VSCode extension packs for Java. Take a look at this tutorial. We suggest:

Importing VSCode Project

  1. Download Assignment7.zip from Autolab Attachments.

  2. Unzip the file by double clicking.

  3. Open VSCode

    • Import the folder to a workspace through File > Open Folder

Executing and Debugging

  • You can run your program in VS Code by clicking the run (play button) for both driver files. Or you can use the Terminal to compile and execute. We suggest running through VSCode because it will give you the option to debug.

  • How to debug your code

Before submission

Collaboration policy. Read our collaboration policy here.

Submitting the assignment. Submit SolarPanels.java separately via the web submission system called Autolab. To do this, click the Assignments link from the course website; click the Submit link for that assignment.

Getting help

If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza.

    • Find instructors office hours here

    • Find tutors office hours on Canvas -> Tutoring

    • Find head IAs office hours here

    • OOP Overview made by 112 TA Colin

    • Debugging Guide made by 112 TA Colin

    • In addition to office hours we have the Coding and Social Lounge (CSL) , a community space staffed with lab assistants which are undergraduate students further along the CS major to answer questions.