You are expected to complete this assignment individually. If you need help, you are invited to come to virtual office hours and/or ask questions on Ed. Clarification questions about the assignments may be asked publicly. Once you have specific bugs related to your code, make the posts private.
Another note about Ed. Ed is your community resource - please use those as discussions amongst yourselves. We are not monitoring it all day, rather we each have check-in times once a day. Therefore, you need to start early enough to wait for feedback and/or build a vibrant, supportive community that helps each other while we are completing other necessary tasks (research, developing assignments, preparing for lecture, performing advising tasks, etc.).
In this homework, you'll implement a qubit. The first half of the course builds upon this code week by week.
You will submit several files for this assignment, which includes files from the warmup and the homework(Lab1SampleFunctions.java, Puppy.java, TestLab1.java, testlab1.txt, Qubit.java, TestQubit.java, testqubit1.txt, Makefile). You will submit your work in a zip file to Gradescope. More detailed submission instructions will come later.
Error handling capabilities vary by language, and what you want to do in an error varies by the situation. When an error occurs in a method, the question becomes, what should you do, and how do you notify the caller that an error occurred?
In Java, there is a construct for this. We'll use this when calling methods that use it but, right now, we won't implement them ourselves. This is an exercise because if you write a method, and it's used in a variety of different circumstances, it is bad programming practice to determine within the method what will be done. For example, one program might want to exit, whereas another might want to notify the user that there was bad input and to try again.
In this course, we will print the error message in a special way (see below). If there is an opportunity, we will designate a specific return value for an error condition. If there is no available return value, then we will exit from within the method.
System.out.println("error: too many widgets for the number of grommets"); System.out.println("error: need ten boondoggles, but only have "+ num_bds);
Sometimes, these lines will be followed by System.exit(1); This immediately exits the program and returns a code. If you were writing a large program, you might assign a different code to each type of error that would result in an exit.
make TestQubit
public float surface_area_cylinder(float height, float radius) { System.out.println("surface_area_cylinder not yet implemented"); return 0.0; }
int main(String[] args) { float fval; LabXMethods lxm = new LabXMethods(); fval = lxm.surface_area_cylinder(3.5, 7.9); }
First get this compiling and running. It won't do anything useful, but this will mean that your code will compile and execute with our infrastructure. This must work in order to get any points in this course. Do this first, not last.
Object-oriented design involves two steps: Identifying the elements of thestate to store and identifying the actions (which are the methods) to implement.
The Qubit holds the state of a single qubit. We are gradually building up knowledge of what that state is. For this week, we will only support single qubit operations and the white and black, |0> |1> states. Even if you are aware of full state, do not change the specifications for the state. For now, we will hold a single float value, which is 0 for the white state and 1 for the black state.
Along with the state, we implement a number of methods. First, we need constructor(s) to initialize the state. We will have three constructors - one is a default constructor with no input arguments, and two are constructors with a single input for value, but each with a different type. Unlike C, Java (and other object-oriented languages) allow multiple methods to have the same name as long as they have different arguments - either number of arguments or types of arguments. I have implemented the first two - you need to implement the last constructor.
Next, we need to implement any setters / getters that are not yet implemented. For any values we want to provide the programmer, instead of making them public, we provide the setter / getter. This is a Java convention that makes it easier to make changes to your implementation down the road - change the variable name, the variable type, etc. You only need to make sure that a conversion is provided in the method to support those who wanted direct access.
In week 1, we will implement a single operator - not - because that is the only single-bit operator that operates on such simple qubit state. This performs a not operation on the qubit. However, there is a constraint - you need to figure out a mathematical operation that will perform the operation properly regardless of whether the starting value is a 0 or 1.