Skip to content

Instantly share code, notes, and snippets.

@lb7n
Last active August 29, 2015 14:05
Show Gist options
  • Save lb7n/4d0ac3826dafde995d7d to your computer and use it in GitHub Desktop.
Save lb7n/4d0ac3826dafde995d7d to your computer and use it in GitHub Desktop.
Chapter 4
import java.util.ArrayList;
public class mainclass {
public static void main(String[] args)
{
String Name1 = "Milo";
String Name2 = "Artemis";
String Name3 = "Prudence";
String Res1 = "Boat Rental";
String Res2 = "Hotel Rental";
String Res3 = "Jet Plane Rental";
double price1 = 420.99;
double price2 = 123.45;
double price3 = 666.69;
/*
* the way you create an object is first the object type then the object
* name equals new object type()
*/
reservation myreservation1 = new reservation(Name1, Res1, price1);
reservation myreservation2 = new reservation(Name2, Res2, price2);
reservation myreservation3 = new reservation(Name3, Res3, price3);
System.out.println(myreservation1.getTITLE());
System.out.println(myreservation2.getTITLE());
System.out.println(myreservation3.getTITLE());
myreservation1.setTITLE("Tyson");
myreservation1.setRESERVATIONS("Boat");
System.out.println(myreservation1.getTITLE());
System.out.println(myreservation1.getRESERVATIONS());
double total = myreservation1.getCOST() + myreservation2.getCOST()
+ myreservation3.getCOST();
reservation bigreservation = new reservation(Name1, Res2, total);
System.out.println("The total of all of the numbers is " + total);
ArrayList<reservation> multiplereservations = new ArrayList<reservation>();
multiplereservations.add(myreservation1);
multiplereservations.add(myreservation2);
multiplereservations.add(myreservation3);
}
}
public class reservation {
/* this is where instance variables belong */
/*
* instance variables begin with an access specifier (private, public) then
* the variable type (String, int, etc)
*
* and then the variable name
*/
private String TITLE;
private String RESERVATIONS;
private double COST;
/*
* this is the constructor, the code in the constructor is executed every
* time you make an object
*/
public reservation(String TITLE, String RESERVATIONS, double COST) {
this.TITLE = TITLE;
this.RESERVATIONS = RESERVATIONS;
this.COST = COST;
}
/*
* methods are written with your access specifier first (public) then the
* return value of the
*
* method (void, String, int, etc) then the method name
*/
public String getTITLE() {
return this.TITLE;
}
public String getRESERVATIONS() {
return this.RESERVATIONS;
}
public double getCOST() {
return this.COST;
}
public void setTITLE(String cat) {
this.TITLE = cat;
}
public void setRESERVATIONS(String dog) {
this.RESERVATIONS = dog;
}
public void setCOST(double ganja) {
this.COST = ganja;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment