Skip to Main Content

Introduction to Computer Science

Computer Science Department

Solar Panels – 70 course points

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

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.

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.

  • See this video on how to import the project into VSCode and how to submit into Autolab.

The assignment has two components:

  1. Coding (70 points) submitted through Autolab. (Due 11/22)

  2. Reflection (3 points) submitted through a form. (Due 11/27)

    • 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 netid, 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 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 AnimatedDriver and TextDriver classes are used to test your methods interactively. Follow the prompts in the terminal or your screen to use the driver. Feel free to edit this file, as it is provided only to help you test your code. It is not submitted and it is not used to grade your code. Do not submit to Autolab.
    • In AnimatedDriver, once on a screen (like the map view), press any key to move to the next screen.
    • 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.
  • Multiple input files are included; they store [varies information depending on what method you’re testing]. You are welcome to create your own input files, as they will not be submitted to Autolab.

SolarPanels.java

  • DO NOT add new import statements.
  • DO NOT change any of the method’s signatures.

Methods to be implemented by you:

setupStreetMap

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 parameters by using StdIn.setFile.
  • Read the length of the array, given as an integer on one line
  • Read the width of the array, given as an integer on one line
  • Update streetMap to be an l x w array of Strings
  • You will then see l x w Strings representing each value in a position (say [i][j]). Update each [i][j] value in the 2D array with the proper String value.

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 (whether the value is in the current line or in the next line).
  • StdIn.readDouble() reads the next double value from the opened file (whether the value is in the current line or in the next line).
  • StdIn.readString() reads the next String value from the opened file.

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

setupParkingLots

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 parameters by using StdIn.setFile.
  • Read the number of items, say n (given as an integer on one line).
  • You will see n lines (one line represents one lot) with the following, space-separated. Read each value and add a ParkingLot object containing all values in each line to the Array lots.
    • 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
  • Be sure to initialize lots to be a new Array.

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

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

insertPanels

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 to be the same dimensions as streetMap. Panels will contain Panel objects.
  • 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 lot’s name.
      • Adding a new panel doesn’t give you a negative balance (exactly zero is okay).
      • The number of panels so far does not exceed the maximum panels in this lot.
    • If those conditions are met, add a new panel containing the lot’s efficiency and energy capacity; for whether or not the panel works, we will randomly generate this value.
      • 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.

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}.

updateActualEfficiency

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 through a method that passes in a temperature and coefficient we use for efficiency loss.

We calculate efficiency loss as follows: coefficient * (temperature - 77). Note that if temperatures are colder than 77 degrees then we will have an efficiency gain. Your task is to update all panels to account for efficiency losses or gains compared 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, to reflect the amount of electricity generated in one day by each solar panel in a project.

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 are 1.5 square meters in size. Direct solar radiation is about 1000 watts per square meter. At 100% efficiency, your panels should produce 1500 watts of electricity. However, at 20% efficiency, for example, your panels are only converting (20 / 100) * 1500 of this potential energy into electricity. That is 300 watts.

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

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

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

This method counts and returns the number of working panels in a parking lot. Note that the method will pass in a parking lot number for you to use.

As you traverse your array of panels, check that you are (1) in the specified parking lot and (2) whether the panel 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 map (ALL panels) 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 project 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 totaling the amount of electricity generated in one year by all of the panels in a project and determining what percent of Rutgers’ electricity needs this meets.

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 watt-hours each solar panel generates in one day. In this method, you will be totaling the amount of electricity generated by all of the panels in a project for the year in kilowatt-hours.

  • To find total electricity, add up the electricity used on 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 60 million to calculate the portion 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.

Implementation Notes

  • YOU MAY only update the methods with the WRITE YOUR CODE HERE line.
  • COMMENT all print statements you have written from SolarPanels.java
  • DO NOT add any instance variables to the SolarPanels class.
  • DO NOT add any public methods to the SolarPanels 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 SolarPanels.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 through VSCode 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
  • If you choose the Terminal:
    • first navigate to SolarPanels directory/folder
      • to compile: javac *.java
      • to execute: java SolarPanels

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 TAs 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.

By Jessica de Brito and Kal Pandit

VSCode Extensions

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