SlideShare a Scribd company logo
1 of 9
Download to read offline
Topics: .Understanding and accessing instance variables Object construction Encapsulation
Your programming assignments require individual work and effort to be of any benefit. Every
student must wo independently on his or her assignments. This means that every student must
ensure that neither a soft copy nor hard copy of their work gets into the hands of another student.
Sharing your assignments with others in any way is NOT permitted. Violations of the University
Academic Integrity policy will not be ignored. policy is found at
http://www.asu.edu/studentlife/judicial/integrity, html The university academic integrity Use the
following Coding Guidelines: .Give identifiers Give identifers semantic meaning and make them
easy to read (examples num Students. gross Pay, etc) semantic meaning and make them easy to
read (examples numStudents, grossPay, etc). Keep identifiers to a reasonably short length. .User
upper case for constants. Use title cuse (first letter is upper case) for classes. Use lower case with
uppercase word separators fa all other identifiers (variables, methods, objects). .Use tabs or
spaces to indent code within blocks (code surrounded by braces). This includes classes, methods,
and code associated w ifs, switches and loops. Be consistent with the number of spaces or tabs
that you use to indent Use white space to make your program more readablec .Use comments
after the ending brace of classes, methods, and blocks to identity to which block it belongs
Assignments Documentation: At the beginning of each programming assignment you must have
a comment block with the following information /AUTHOR: your name / FILENAME: title of
the source file / SPECIFICATION: description of the program YOUR Lab Letter and Name of
the IA for your Closed lab // FOR. CSE I 10-homework #-days and time ofyour class
Solution
solution
package com.prt.test;
public class Customer {
private String firstName;
private String lastName;
private int idNumber;
private int noOfMatineeTickets;
private int noOfNormalTickets;
private double totalCost;
/**
* @param totalCost
* the totalCost to set
*/
public void setTotalCost(double totalCost) {
this.totalCost = totalCost;
}
/**
* @param firstName
* the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @param lastName
* the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @param idNumber
* the idNumber to set
*/
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
/**
* @param noOfMatineeTickets
* the noOfMatineeTickets to set
*/
public void setNoOfMatineeTickets(int noOfMatineeTickets) {
this.noOfMatineeTickets = noOfMatineeTickets;
}
/**
* @param noOfNormalTickets
* the noOfNormalTickets to set
*/
public void setNoOfNormalTickets(int noOfNormalTickets) {
this.noOfNormalTickets = noOfNormalTickets;
}
public Customer() {
this.firstName = firstName;
this.lastName = lastName;
this.idNumber = idNumber;
this.noOfMatineeTickets = noOfMatineeTickets;
this.noOfNormalTickets = noOfNormalTickets;
this.totalCost = totalCost;
}
public Customer(String firstName, String lastName, int idNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.idNumber = idNumber;
}
public Customer(String firstName, String lastName, int idNumber,
int noOfMatineeTickets, int noOfNormalTickets) {
this.firstName = firstName;
this.lastName = lastName;
this.idNumber = idNumber;
this.noOfMatineeTickets = noOfMatineeTickets;
this.noOfNormalTickets = noOfNormalTickets;
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @return the idNumber
*/
public int getIdNumber() {
return idNumber;
}
/**
* @return the noOfMatineeTickets
*/
public int getNoOfMatineeTickets() {
return noOfMatineeTickets;
}
/**
* @return the noOfNormalTickets
*/
public int getNoOfNormalTickets() {
return noOfNormalTickets;
}
/**
* @return the totalCost
*/
public double getTotalCost() {
return totalCost;
}
private static int getTickets() {
return 0;
}
private static int getNumCustomers() {
return 0;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((firstName == null) ? 0 : firstName.hashCode());
result = prime * result + idNumber;
result = prime * result
+ ((lastName == null) ? 0 : lastName.hashCode());
result = prime * result + noOfMatineeTickets;
result = prime * result + noOfNormalTickets;
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Customer other = (Customer) obj;
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (idNumber != other.idNumber)
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
return true;
}
public void computeTotalCost() {
int matineetickets = this.getNoOfMatineeTickets();
int normaltickets = this.getNoOfNormalTickets();
double totalcost = 5 * matineetickets + 7.5 * normaltickets;
System.out.println("totalcost $" + totalcost);
}
public Customer hasMore(Customer other) {
if (this.getNoOfMatineeTickets() == other.getNoOfMatineeTickets()
&& this.getNoOfNormalTickets() == other.getNoOfNormalTickets())
return this;
if ((this.getNoOfMatineeTickets() + this.getNoOfNormalTickets()) > (other
.getNoOfNormalTickets() + other.getNoOfMatineeTickets())) {
return this;
} else
return other;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "firstName=" + firstName + " " + "lastName=" + lastName + " "
+ "idNumber=" + idNumber + " " + "noOfMatineeTickets="
+ noOfMatineeTickets + " " + "noOfNormalTickets="
+ noOfNormalTickets;
}
}
package com.prt.test;
import java.util.Scanner;
public class Assignment6 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Customer customer1 = new Customer();
System.out.println(".......customer's info.....");
System.out.println(customer1.toString());
// call the mutator methods
customer1.setFirstName("Grace");
customer1.setLastName("Hopper");
customer1.setNoOfNormalTickets(30);
customer1.setIdNumber(12345);
System.out.println(".......customer's info.....");
System.out.println(customer1);
// instantiate another customer using overloaded constructor
Customer customer2 = new Customer("Morgan", "smith", 555666777);
// print custmer's info
System.out.println(".......customer's info.....");
System.out.println(customer2);
customer2.setNoOfMatineeTickets(25);
// cusotmers information using keyboard
System.out.println("enter fname");
String fname = scanner.next();
System.out.println("enter lname");
String lname = scanner.next();
System.out.println("enter id");
int id = scanner.nextInt();
System.out.println("enter noofmatineetickets");
int matineeTickets = scanner.nextInt();
System.out.println("enter noofmatineetickets");
int normalTickets = scanner.nextInt();
// overloaded constructor
Customer customer3 = new Customer(fname, lname, id, matineeTickets,
normalTickets);
// customers info using get methods
System.out.println(".....customers info using get methods........");
System.out.println("firstname" + customer3.getFirstName());
System.out.println("lastname" + customer3.getLastName());
System.out.println("matinee tickets"
+ customer3.getNoOfMatineeTickets());
System.out.println("normaltickets" + customer3.getNoOfNormalTickets());
customer3.computeTotalCost();
// who has more tickets
System.out.println("who has more tickets");
System.out.println(customer1.hasMore(customer3));
System.out.println("first comparison");
if (customer2.equals(customer3))
System.out.println("customer2 and customer3 are same");
else
System.out.println("customer2 and customer3 are not same");
System.out.println("second comparison");
customer2 = customer3;
if (customer2.equals(customer3))
System.out.println("customer2 and customer3 are same");
else
System.out.println("customer2 and customer3 are not same");
}
}
output
.......customer's info.....
firstName=null
lastName=null
idNumber=0
noOfMatineeTickets=0
noOfNormalTickets=0
.......customer's info.....
firstName=Grace
lastName=Hopper
idNumber=12345
noOfMatineeTickets=0
noOfNormalTickets=30
.......customer's info.....
firstName=Morgan
lastName=smith
idNumber=555666777
noOfMatineeTickets=0
noOfNormalTickets=0
enter fname
john
enter lname
helen
enter id
12345
enter noofmatineetickets
25
enter noofmatineetickets
36
.....customers info using get methods........
firstnamejohn
lastnamehelen
matinee tickets25
normaltickets36
totalcost $395.0
who has more tickets
firstName=john
lastName=helen
idNumber=12345
noOfMatineeTickets=25
noOfNormalTickets=36
first comparison
customer2 and customer3 are not same
second comparison
customer2 and customer3 are same

More Related Content

Similar to Topics .Understanding and accessing instance variables Object constr.pdf

F# Eye For The C# Guy - Seattle 2013
F# Eye For The C# Guy - Seattle 2013F# Eye For The C# Guy - Seattle 2013
F# Eye For The C# Guy - Seattle 2013Phillip Trelford
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo....NET Conf UY
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdffatoryoutlets
 
Lombokの紹介
Lombokの紹介Lombokの紹介
Lombokの紹介onozaty
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdfanokhijew
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003R696
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining ClassesIntro C# Book
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdfaplolomedicalstoremr
 
Use the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfUse the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfsales87
 
Keep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfKeep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfAroraRajinder1
 
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdfplease navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdfaioils
 
Create a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfCreate a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfarrowvisionoptics
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.pptEmanAsem4
 
So here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfSo here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfleolight2
 
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxAlcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxsimonlbentley59018
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongGrokking VN
 

Similar to Topics .Understanding and accessing instance variables Object constr.pdf (20)

F# Eye For The C# Guy - Seattle 2013
F# Eye For The C# Guy - Seattle 2013F# Eye For The C# Guy - Seattle 2013
F# Eye For The C# Guy - Seattle 2013
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
Lombokの紹介
Lombokの紹介Lombokの紹介
Lombokの紹介
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
Use the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfUse the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdf
 
Keep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfKeep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdf
 
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdfplease navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
 
Java2
Java2Java2
Java2
 
Create a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfCreate a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdf
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
So here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfSo here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdf
 
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxAlcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
 

More from izabellejaeden956

Explain the advantages and disadvantages of misuse-based and anomaly.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdfExplain the advantages and disadvantages of misuse-based and anomaly.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdfizabellejaeden956
 
E. coli takes up plasmid DNA by which of the following methodsple.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdfE. coli takes up plasmid DNA by which of the following methodsple.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdfizabellejaeden956
 
Consider the two genes described in Question 7. What is the probabili.pdf
Consider the two genes described in Question 7. What is the probabili.pdfConsider the two genes described in Question 7. What is the probabili.pdf
Consider the two genes described in Question 7. What is the probabili.pdfizabellejaeden956
 
A wireless technology that may someday replace barcodes through the u.pdf
A wireless technology that may someday replace barcodes through the u.pdfA wireless technology that may someday replace barcodes through the u.pdf
A wireless technology that may someday replace barcodes through the u.pdfizabellejaeden956
 
The director of special events for Sun City believed that he amount o.pdf
The director of special events for Sun City believed that he amount o.pdfThe director of special events for Sun City believed that he amount o.pdf
The director of special events for Sun City believed that he amount o.pdfizabellejaeden956
 
Write an application containing three parallel arrays that hold 10 e.pdf
Write an application containing three parallel arrays that hold 10 e.pdfWrite an application containing three parallel arrays that hold 10 e.pdf
Write an application containing three parallel arrays that hold 10 e.pdfizabellejaeden956
 
Which type of project risk is the most relevantStand-alone risk.pdf
Which type of project risk is the most relevantStand-alone risk.pdfWhich type of project risk is the most relevantStand-alone risk.pdf
Which type of project risk is the most relevantStand-alone risk.pdfizabellejaeden956
 
Which of the following is an advantage businesses have over citizens.pdf
Which of the following is an advantage businesses have over citizens.pdfWhich of the following is an advantage businesses have over citizens.pdf
Which of the following is an advantage businesses have over citizens.pdfizabellejaeden956
 
what is the pseudoautosomal regionA. the region on the Y chromose.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdfwhat is the pseudoautosomal regionA. the region on the Y chromose.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdfizabellejaeden956
 
What is a flat file database How can it be used for forecasting.pdf
What is a flat file database How can it be used for forecasting.pdfWhat is a flat file database How can it be used for forecasting.pdf
What is a flat file database How can it be used for forecasting.pdfizabellejaeden956
 
What is, in your opinion, the minimum firewall placement for a SCADA.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdfWhat is, in your opinion, the minimum firewall placement for a SCADA.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdfizabellejaeden956
 
What factor(s) do not contribute to the development of mutations tha.pdf
What factor(s) do not contribute to the development of mutations tha.pdfWhat factor(s) do not contribute to the development of mutations tha.pdf
What factor(s) do not contribute to the development of mutations tha.pdfizabellejaeden956
 
Urinary Tract infections commonly caused by E. Coli is a common illn.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdfUrinary Tract infections commonly caused by E. Coli is a common illn.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdfizabellejaeden956
 
Two samples of sizes 15 and 20 are randomly and independently select.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdfTwo samples of sizes 15 and 20 are randomly and independently select.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdfizabellejaeden956
 
True or False The Coefficient of Determination shows the direction .pdf
True or False The Coefficient of Determination shows the direction .pdfTrue or False The Coefficient of Determination shows the direction .pdf
True or False The Coefficient of Determination shows the direction .pdfizabellejaeden956
 
Mechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdfMechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdfizabellejaeden956
 
The following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdfThe following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdfizabellejaeden956
 
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdfRegulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdfizabellejaeden956
 
Q4. We used remote port forwarding in this scenario. How does local .pdf
Q4. We used remote port forwarding in this scenario. How does local .pdfQ4. We used remote port forwarding in this scenario. How does local .pdf
Q4. We used remote port forwarding in this scenario. How does local .pdfizabellejaeden956
 
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdfPYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdfizabellejaeden956
 

More from izabellejaeden956 (20)

Explain the advantages and disadvantages of misuse-based and anomaly.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdfExplain the advantages and disadvantages of misuse-based and anomaly.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdf
 
E. coli takes up plasmid DNA by which of the following methodsple.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdfE. coli takes up plasmid DNA by which of the following methodsple.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdf
 
Consider the two genes described in Question 7. What is the probabili.pdf
Consider the two genes described in Question 7. What is the probabili.pdfConsider the two genes described in Question 7. What is the probabili.pdf
Consider the two genes described in Question 7. What is the probabili.pdf
 
A wireless technology that may someday replace barcodes through the u.pdf
A wireless technology that may someday replace barcodes through the u.pdfA wireless technology that may someday replace barcodes through the u.pdf
A wireless technology that may someday replace barcodes through the u.pdf
 
The director of special events for Sun City believed that he amount o.pdf
The director of special events for Sun City believed that he amount o.pdfThe director of special events for Sun City believed that he amount o.pdf
The director of special events for Sun City believed that he amount o.pdf
 
Write an application containing three parallel arrays that hold 10 e.pdf
Write an application containing three parallel arrays that hold 10 e.pdfWrite an application containing three parallel arrays that hold 10 e.pdf
Write an application containing three parallel arrays that hold 10 e.pdf
 
Which type of project risk is the most relevantStand-alone risk.pdf
Which type of project risk is the most relevantStand-alone risk.pdfWhich type of project risk is the most relevantStand-alone risk.pdf
Which type of project risk is the most relevantStand-alone risk.pdf
 
Which of the following is an advantage businesses have over citizens.pdf
Which of the following is an advantage businesses have over citizens.pdfWhich of the following is an advantage businesses have over citizens.pdf
Which of the following is an advantage businesses have over citizens.pdf
 
what is the pseudoautosomal regionA. the region on the Y chromose.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdfwhat is the pseudoautosomal regionA. the region on the Y chromose.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdf
 
What is a flat file database How can it be used for forecasting.pdf
What is a flat file database How can it be used for forecasting.pdfWhat is a flat file database How can it be used for forecasting.pdf
What is a flat file database How can it be used for forecasting.pdf
 
What is, in your opinion, the minimum firewall placement for a SCADA.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdfWhat is, in your opinion, the minimum firewall placement for a SCADA.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdf
 
What factor(s) do not contribute to the development of mutations tha.pdf
What factor(s) do not contribute to the development of mutations tha.pdfWhat factor(s) do not contribute to the development of mutations tha.pdf
What factor(s) do not contribute to the development of mutations tha.pdf
 
Urinary Tract infections commonly caused by E. Coli is a common illn.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdfUrinary Tract infections commonly caused by E. Coli is a common illn.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdf
 
Two samples of sizes 15 and 20 are randomly and independently select.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdfTwo samples of sizes 15 and 20 are randomly and independently select.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdf
 
True or False The Coefficient of Determination shows the direction .pdf
True or False The Coefficient of Determination shows the direction .pdfTrue or False The Coefficient of Determination shows the direction .pdf
True or False The Coefficient of Determination shows the direction .pdf
 
Mechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdfMechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdf
 
The following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdfThe following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdf
 
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdfRegulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
 
Q4. We used remote port forwarding in this scenario. How does local .pdf
Q4. We used remote port forwarding in this scenario. How does local .pdfQ4. We used remote port forwarding in this scenario. How does local .pdf
Q4. We used remote port forwarding in this scenario. How does local .pdf
 
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdfPYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 

Topics .Understanding and accessing instance variables Object constr.pdf

  • 1. Topics: .Understanding and accessing instance variables Object construction Encapsulation Your programming assignments require individual work and effort to be of any benefit. Every student must wo independently on his or her assignments. This means that every student must ensure that neither a soft copy nor hard copy of their work gets into the hands of another student. Sharing your assignments with others in any way is NOT permitted. Violations of the University Academic Integrity policy will not be ignored. policy is found at http://www.asu.edu/studentlife/judicial/integrity, html The university academic integrity Use the following Coding Guidelines: .Give identifiers Give identifers semantic meaning and make them easy to read (examples num Students. gross Pay, etc) semantic meaning and make them easy to read (examples numStudents, grossPay, etc). Keep identifiers to a reasonably short length. .User upper case for constants. Use title cuse (first letter is upper case) for classes. Use lower case with uppercase word separators fa all other identifiers (variables, methods, objects). .Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated w ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent Use white space to make your program more readablec .Use comments after the ending brace of classes, methods, and blocks to identity to which block it belongs Assignments Documentation: At the beginning of each programming assignment you must have a comment block with the following information /AUTHOR: your name / FILENAME: title of the source file / SPECIFICATION: description of the program YOUR Lab Letter and Name of the IA for your Closed lab // FOR. CSE I 10-homework #-days and time ofyour class Solution solution package com.prt.test; public class Customer { private String firstName; private String lastName; private int idNumber; private int noOfMatineeTickets; private int noOfNormalTickets; private double totalCost; /** * @param totalCost * the totalCost to set */
  • 2. public void setTotalCost(double totalCost) { this.totalCost = totalCost; } /** * @param firstName * the firstName to set */ public void setFirstName(String firstName) { this.firstName = firstName; } /** * @param lastName * the lastName to set */ public void setLastName(String lastName) { this.lastName = lastName; } /** * @param idNumber * the idNumber to set */ public void setIdNumber(int idNumber) { this.idNumber = idNumber; } /** * @param noOfMatineeTickets * the noOfMatineeTickets to set */ public void setNoOfMatineeTickets(int noOfMatineeTickets) { this.noOfMatineeTickets = noOfMatineeTickets; } /** * @param noOfNormalTickets * the noOfNormalTickets to set */ public void setNoOfNormalTickets(int noOfNormalTickets) {
  • 3. this.noOfNormalTickets = noOfNormalTickets; } public Customer() { this.firstName = firstName; this.lastName = lastName; this.idNumber = idNumber; this.noOfMatineeTickets = noOfMatineeTickets; this.noOfNormalTickets = noOfNormalTickets; this.totalCost = totalCost; } public Customer(String firstName, String lastName, int idNumber) { this.firstName = firstName; this.lastName = lastName; this.idNumber = idNumber; } public Customer(String firstName, String lastName, int idNumber, int noOfMatineeTickets, int noOfNormalTickets) { this.firstName = firstName; this.lastName = lastName; this.idNumber = idNumber; this.noOfMatineeTickets = noOfMatineeTickets; this.noOfNormalTickets = noOfNormalTickets; } /** * @return the firstName */ public String getFirstName() { return firstName; } /** * @return the lastName */ public String getLastName() { return lastName; } /**
  • 4. * @return the idNumber */ public int getIdNumber() { return idNumber; } /** * @return the noOfMatineeTickets */ public int getNoOfMatineeTickets() { return noOfMatineeTickets; } /** * @return the noOfNormalTickets */ public int getNoOfNormalTickets() { return noOfNormalTickets; } /** * @return the totalCost */ public double getTotalCost() { return totalCost; } private static int getTickets() { return 0; } private static int getNumCustomers() { return 0; } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() {
  • 5. final int prime = 31; int result = 1; result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); result = prime * result + idNumber; result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); result = prime * result + noOfMatineeTickets; result = prime * result + noOfNormalTickets; return result; } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Customer other = (Customer) obj; if (firstName == null) { if (other.firstName != null) return false; } else if (!firstName.equals(other.firstName)) return false; if (idNumber != other.idNumber) return false; if (lastName == null) { if (other.lastName != null) return false; } else if (!lastName.equals(other.lastName))
  • 6. return false; return true; } public void computeTotalCost() { int matineetickets = this.getNoOfMatineeTickets(); int normaltickets = this.getNoOfNormalTickets(); double totalcost = 5 * matineetickets + 7.5 * normaltickets; System.out.println("totalcost $" + totalcost); } public Customer hasMore(Customer other) { if (this.getNoOfMatineeTickets() == other.getNoOfMatineeTickets() && this.getNoOfNormalTickets() == other.getNoOfNormalTickets()) return this; if ((this.getNoOfMatineeTickets() + this.getNoOfNormalTickets()) > (other .getNoOfNormalTickets() + other.getNoOfMatineeTickets())) { return this; } else return other; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return "firstName=" + firstName + " " + "lastName=" + lastName + " " + "idNumber=" + idNumber + " " + "noOfMatineeTickets=" + noOfMatineeTickets + " " + "noOfNormalTickets=" + noOfNormalTickets; } } package com.prt.test; import java.util.Scanner; public class Assignment6 { public static void main(String[] args) {
  • 7. Scanner scanner = new Scanner(System.in); Customer customer1 = new Customer(); System.out.println(".......customer's info....."); System.out.println(customer1.toString()); // call the mutator methods customer1.setFirstName("Grace"); customer1.setLastName("Hopper"); customer1.setNoOfNormalTickets(30); customer1.setIdNumber(12345); System.out.println(".......customer's info....."); System.out.println(customer1); // instantiate another customer using overloaded constructor Customer customer2 = new Customer("Morgan", "smith", 555666777); // print custmer's info System.out.println(".......customer's info....."); System.out.println(customer2); customer2.setNoOfMatineeTickets(25); // cusotmers information using keyboard System.out.println("enter fname"); String fname = scanner.next(); System.out.println("enter lname"); String lname = scanner.next(); System.out.println("enter id"); int id = scanner.nextInt(); System.out.println("enter noofmatineetickets"); int matineeTickets = scanner.nextInt(); System.out.println("enter noofmatineetickets"); int normalTickets = scanner.nextInt(); // overloaded constructor Customer customer3 = new Customer(fname, lname, id, matineeTickets, normalTickets); // customers info using get methods System.out.println(".....customers info using get methods........"); System.out.println("firstname" + customer3.getFirstName()); System.out.println("lastname" + customer3.getLastName()); System.out.println("matinee tickets"
  • 8. + customer3.getNoOfMatineeTickets()); System.out.println("normaltickets" + customer3.getNoOfNormalTickets()); customer3.computeTotalCost(); // who has more tickets System.out.println("who has more tickets"); System.out.println(customer1.hasMore(customer3)); System.out.println("first comparison"); if (customer2.equals(customer3)) System.out.println("customer2 and customer3 are same"); else System.out.println("customer2 and customer3 are not same"); System.out.println("second comparison"); customer2 = customer3; if (customer2.equals(customer3)) System.out.println("customer2 and customer3 are same"); else System.out.println("customer2 and customer3 are not same"); } } output .......customer's info..... firstName=null lastName=null idNumber=0 noOfMatineeTickets=0 noOfNormalTickets=0 .......customer's info..... firstName=Grace lastName=Hopper idNumber=12345 noOfMatineeTickets=0 noOfNormalTickets=30 .......customer's info..... firstName=Morgan lastName=smith idNumber=555666777
  • 9. noOfMatineeTickets=0 noOfNormalTickets=0 enter fname john enter lname helen enter id 12345 enter noofmatineetickets 25 enter noofmatineetickets 36 .....customers info using get methods........ firstnamejohn lastnamehelen matinee tickets25 normaltickets36 totalcost $395.0 who has more tickets firstName=john lastName=helen idNumber=12345 noOfMatineeTickets=25 noOfNormalTickets=36 first comparison customer2 and customer3 are not same second comparison customer2 and customer3 are same