Last active
August 29, 2015 14:14
-
-
Save ImDevinC/f7b0061be511d5612ad4 to your computer and use it in GitHub Desktop.
Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Invoice { | |
private String partNumber = ""; | |
private String partDescription = ""; | |
private int quantity = 0; | |
private double pricePerItem = 0; | |
public Invoice(String partNumber, String partDescription, int quantity) { | |
this.partNumber = partNumber; | |
this.partDescription = partDescription; | |
this.quantity = quantity; | |
} | |
public Invoice(String partNumber, String partDescription, int quantity, double pricePerItem) { | |
this.partNumber = partNumber; | |
this.partDescription = partDescription; | |
this.quantity = quantity; | |
this.pricePerItem = pricePerItem; | |
} | |
public String getPartNumber() { | |
return partNumber; | |
} | |
public void setPartNumber(String partNumber) { | |
this.partNumber = partNumber; | |
} | |
} | |
public void main() { | |
// Make a new invoice using the default constructor options | |
Invoice invoice1 = new Invoice("a1234", "A new item", 2, 1.99); | |
// Get the part number and store it in a variable | |
String szNumber = invoice1.getPartNumber(); | |
// Print out the number | |
System.out.println(szNumber); | |
// Set the part number to something else | |
invoice1.setPartNumber("4321a"); | |
// Print out the new part number | |
number = invoice1.getPartNumber(); | |
System.out.println(szNumber); | |
// Fails because of private | |
invoice1.partNumber = "a1234567"; | |
// Succeeds because public | |
invoice.setPartNumber("a1234567"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment