SlideShare a Scribd company logo
1 of 31
codeComprehension/orders.txt
womens sandals 1011 6 78.00 red 12
womens runners 2231 7 128.00 white 5
mens boat 7124 8 35.00 leather 3
mens dress 6122 11 165.00 black 0
childs sandals 3331 1 25.00 silver 6
childs school 2121 4 69.00 black 7
womens dress 4321 7 99.99 blue 2
womens sandals 2223 6 67.95 brown 5
childs school 2123 6 59.95 black 9
mens runners 53423 8 189.00 blue 5
childs runner 44453 3 59.95 orange 2
codeComprehension/Shoe.javacodeComprehension/Shoe.javapac
kage sampleAssignment2;
publicclassShoe{
privateString style;
privateint size;
privateint code;
privateString category;
privateString color;
privatedouble price;
publicShoe(){
style="";
size=0;
code=0;
category="";
color="";
price=0.0;
}
publicShoe(String aCategory,String aStyle,int aCode,int aSize,d
ouble aPrice,String aColor){
category = aCategory;
style=aStyle;
size=aSize;
code=aCode;
price=aPrice;
color=aColor;
}
publicString getColor(){
return color;
}
publicvoid setColor(String color){
this.color = color;
}
publicString getStyle(){
return style;
}
publicvoid setStyle(String style){
this.style = style;
}
publicint getSize(){
return size;
}
publicvoid setSize(int size){
this.size = size;
}
publicint getCode(){
return code;
}
publicvoid setCode(int code){
this.code = code;
}
publicString getCategory(){
return category;
}
publicvoid setCategory(String aCategory){
this.category = aCategory;
}
publicdouble getPrice(){
return price;
}
publicvoid setPrice(double price){
this.price = price;
}
publicint compareTo(Shoe anotherShoe){
if(this.getCode()> anotherShoe.getCode())
return1;
elseif(this.getCode()< anotherShoe.getCode())
return-1;
else
return0;
}
publicString toString(){
return code +"t"+ category +"t"+ style +"t"+ size +"t"+ price
+"t"+ color;
}
}
codeComprehension/ShoeShop.javacodeComprehension/ShoeSh
op.javapackage codeComprehension;
import java.util.Scanner;
import java.io.*;
publicclassShoeShop{
publicstaticvoid main(String[] args){
boolean done=false;
int menuSelection;
int numberOfLines=0;
Store myStore =newStore("Value Shoes","Melbourne");
while(!done){
menuSelection = obtainMenuSelection();
switch(menuSelection){
case1:System.out.println("Menu 1 - Read from file");
numberOfLines =readFromFile(myStore);
System.out.println("Read "+ numberOfLines +" lines");
break;
case2:System.out.println("Menu 2 - Display inventory");
myStore.displayInventory();
break;
case3:System.out.println("Menu 3 - Sort inventory");
myStore.sortInventory();
myStore.displayInventory();
break;
case4:System.out.println("Menu 4 - Save file");
numberOfLines = exportToFile(myStore);
System.out.println(numberOfLines +" saved to file.");
break;
case5:System.out.println("Menu 5 - Search inventory");
searchInventory(myStore);
break;
case6:System.out.println("Menu 6 - Exiting");
done=true;
break;
}
}
}
publicstaticint obtainMenuSelection(){
Scanner in =newScanner(System.in);
System.out.println("Menu");
System.out.println("1 - Read inventory from file");
System.out.println("2 - Display inventory");
System.out.println("3 - Sort inventory");
System.out.println("4 - Save inventory");
System.out.println("5 - Search inventory");
System.out.println("6 - Exit");
System.out.println("Choice: ");
return in.nextInt();
}
publicstaticint readFromFile(Store myStore){
int numAdded=0;
try{
Scanner inputFile =newScanner(newFile("c:orders.txt"));
while(inputFile.hasNext()){
//Read the details from the file
String style = inputFile.next();
String type = inputFile.next();
int code = inputFile.nextInt();
int size = inputFile.nextInt();
double price = inputFile.nextDouble();
String color = inputFile.next();
int onhand = inputFile.nextInt();
//Create a new Shoe instance using the details from the file
Shoe aShoe =newShoe(style,type,code,size,price,color);
//Add the new Shoe to the inventory
myStore.addShoes(aShoe);
numAdded++;
}
inputFile.close();
}catch(IOException e){
System.out.println("Error occured reading from file");
e.printStackTrace();
}
//Return a value representing the number of shoes read from the
file
return numAdded++;
}
publicstaticint exportToFile(Store myStore)throwsIOException{
int numOutput=0;
BufferedWriter output;
try{
File file =newFile("export.txt");
System.out.println(file.getAbsolutePath());
output =newBufferedWriter(newFileWriter(file));
while(numOutput < myStore.inventorySize()){
Shoe nextShoe = myStore.getShoes(numOutput);
output.flush();
output.write(nextShoe.toString()+"rn");
numOutput++;
}
output.close();
}catch(IOException e){
System.out.println("Error occured reading from file");
e.printStackTrace();
}
return numOutput++;
}
publicstaticvoid searchInventory(Store myStore){
System.out.println("Searching Inventory");
Scanner in =newScanner(System.in);
int searchCode;
Shoe foundShoe;
System.out.println("Enter the code to search for: ");
searchCode = in.nextInt();
foundShoe = myStore.searchInventory(searchCode);
if(foundShoe!=null)
System.out.println(foundShoe +" current in stock");
else
System.out.println("Not current in stock");
}
}
codeComprehension/Store.javacodeComprehension/Store.javapa
ckage sampleAssignment2;
publicclassStore{
privateString storeName;
privateString location;
privateShoe[] inventory;
privatefinalint MAX_SHOES =100;
privateint numShoes;
publicStore(){
storeName="";
location="";
inventory =newShoe[MAX_SHOES];
numShoes=0;
}
publicStore(String aName,String aLocation){
storeName="";
location="";
inventory =newShoe[MAX_SHOES];
numShoes=0;
}
publicString getStoreName(){
return storeName;
}
publicvoid setStoreName(String storeName){
this.storeName = storeName;
}
publicString getLocation(){
return location;
}
publicvoid setLocation(String location){
this.location = location;
}
publicvoid addShoes(Shoe aPair){
this.inventory[numShoes++]= aPair;
}
publicint inventorySize(){
return numShoes;
}
publicShoe getShoes(int anIndex){
return inventory[anIndex];
}
publicvoid sortInventory(){
for(int i=(this.inventorySize())-1; i>=1; i--){
//Set the maximum shoe (ie highest code) to be position 0
Shoe curMaxShoe=inventory[0];
int curMaxIndex=0;
for(int j=1;j<=i;j++){
//check to see if the next Shoe code is > than curMax
if(curMaxShoe.compareTo(inventory[j])==-1){
curMaxShoe=(inventory[j]);
curMaxIndex=j;
}
}
if(curMaxIndex !=i){
inventory[curMaxIndex]= inventory[i];
inventory[i]= curMaxShoe;
}
}
}
publicvoid displayInventory(){
for(int i=0;i<this.inventorySize(); i++){
System.out.println(inventory[i]);
}
}
publicShoe searchInventory(int searchCode){
Shoe target=null;
for(int i=0;i<this.inventorySize(); i++){
if(inventory[i].getCode()== searchCode){
target=inventory[i];
break;
}
}
return target;
}
publicString toString(){
return storeName +" "+ location +" has "+ inventory.length +" s
hoes in store.";
}
}
starterCode/Apartment.javastarterCode/Apartment.javapackage
starterCode;
publicclassApartment{
privateint numberOfBedrooms;
privateint numberOfBathrooms;
privatedouble squareMetres;
privateint numberOfLiving;
privateboolean available;
privatePerson owner;
privatedouble rentPerWeek;
privateint apartmentNumber;
privateint floor;
//empty constructor
publicApartment(){
}
//constructor with initialisation values
publicApartment(int numBeds,int numBath,double sq,boolean a
vail,Person owner2,double rent){
}
publicint getNumberOfBedrooms(){
return1;//change this to appropriate value
}
publicvoid setNumberOfBedrooms(int numberOfBedrooms){
}
publicint getNumberOfBathrooms(){
return1;//change this to appropriate value
}
publicvoid setNumberOfBathrooms(int numberOfBathrooms){
}
publicdouble getSquareMetres(){
return1;//change this to appropriate value
}
publicvoid setSquareMetres(double squareMetres){
}
publicint getNumberOfLiving(){
return1;//change this to appropriate value
}
publicvoid setNumberOfLiving(int numberOfLiving){
}
publicboolean isAvailable(){
returntrue;//change this to appropriate value
}
publicvoid setAvailable(boolean available){
}
publicPerson getOwner(){
returnnull;//change this to appropriate value
}
publicvoid setOwner(Person owner){
}
publicString toString(){
return"";
}
}
starterCode/Building.javastarterCode/Building.javapackage start
erCode;
import java.util.Arrays;
publicclassBuilding{
privateApartment apartments[];
privateString name;
privateint numberOfApartments;
privateint capacity=100;
publicBuilding(){
apartments =newApartment[capacity];
numberOfApartments=0;
}
publicBuilding(int _capacity){
capacity=_capacity;
apartments =newApartment[capacity];
numberOfApartments=0;
}
// TODO: add get and set methods
// TODO: add toString() method
// TODO: add other methods including addApartment
}
starterCode/TestClass.javastarterCode/TestClass.javapackage st
arterCode;
publicclassTestClass{
publicTestClass(){// constructor for TestClass
}
publicvoid runtest1(){
// first test case
Apartment myApartment =newApartment();
System.out.println(myApartment.toString());
}
publicvoid runtest2(){
// second test case
}
publicvoid runtest3(){
// third test case
}
publicstaticvoid main(String[] args){
// TODO write code here
TestClass mytest =newTestClass();
System.out.println("Running test1... ");
mytest.runtest1();
System.out.println("Running test2... ");
mytest.runtest2();
System.out.println("Running test3... ");
mytest.runtest3();
}
}
ITECH1000 Programming 1 Assignment 2 Specification 2015
Sem 2.pdf
Programming 1 Assignment 2, 2015 Sem 2 Page 1 of 7
ITECH1000 Programming 1, Semester 2 2015
Assignment 2 – Development of a Simple Program Involving
Multiple
Classes
Due Date: Week 11 - see Course Description for full details
Please see the Course Description for further information
related to extensions for assignments and Special
Consideration.
Important Notes
1. Code that does not successfully compile will not be marked.
In such cases, only the specification, design and
question sections of the assignment will be awarded marks. If
you are unable to get sections of your code to
compile prior to handing it in, please state this clearly in your
submission and comment out the offending code.
Marks will also be deducted if your code compiles but contains
warnings. Please see your tutor for help if you are
unable to successfully compile your code.
2. If you use any resources apart from the course material to
complete your assignment you MUST provide an in-text
citation within your documentation and/or code, as well as
providing a list of references in APA formatting. This
includes the use of any websites, online forums, books or text
books. If you are unsure of how to do this please
either see the online guide or ask your tutor for help.
3. You are strongly urged to keep backup files as you work on
the project so that you can revert to an earlier version if
you break an aspect of the program while attempting to
implement one of the later requirements.
4. If you encounter any problems in uploading files to Moodle
please report this to your lecturer or other staff
member as soon as possible. It is your responsibility to check
that you are submitting the correct version of your
files and the correct assignment.
5. You may be required to demonstrate and explain your
working code to your tutor in your lab class.
Project Specification
Please read through the entire specification PRIOR to beginning
work. The assignment should be
completed in the stages mentioned below. The objectives of
this assignment are for you to:
• Write your own classes from a specification
• Instantiate objects of these classes
• Perform required tasks by creating and manipulating objects in
the code of one class through the public
interfaces (methods) of the classes of the objects being
manipulated.
The context for this assignment will be creating a software
system to support the management of a Building,
which a number of Apartments that are for rent.
ITECH 1000/5000 Programming 1 Assignment 2 Specification
Semester 2, 2015 Page 2 of 7
Resources:
The following files/links are available on Moodle:
• An electronic copy of this assignment specification sheet
• A sample program with similar features to the assignment
requirements involving multiple classes
• Starter code for some of the classes which you will need to
create
Design Constraints
Your program should conform to the following constraints.
• Use a while-loop when the number of iterations is not known
before loop execution.
• Use a for-loop when the number of iterations is known before
loop execution.
• Indent your code correctly to aid readability and use a
consistent curly bracket placement scheme.
• Use white space to make your code as readable as possible.
• Validation of input should be limited to ensuring that the user
has entered values that are within correct
bounds. You do not have to check that they have entered the
correct data type.
• Comment your code appropriately.
Part A – Code Comprehension
A Sample program is provided. Make sure you understand this
code as it will help you with your own
programming for this assignment. Using the uncommented
sample code for classes provided, answer the
following questions:
1. Draw a UML diagram of the Shoe class using the code that
has been provided. Complete this using the
examples that have been provide in the lecture slides.
2. Draw a UML diagram of the Store class using the code that
has been provided. Complete this using the
examples that have been provide in the lecture slides.
3. Copy the code from Store.java into your report and
appropriately comment the code. At a minimum, explain the
purpose of each method. For the more complex methods reading
input from a file, sorting the data and
exporting data to the file, insert comments to explain the code.
4. Briefly explain the code in sortInventory. What is the
inventory being sorted by? What is the sort algorithm
that is being used. Explain in words how it works. Why do you
need to use two for loops?
5. Briefly explain what other sorting algorithms could have
been used.
6. What method of searching for shoes has been used in the
program? What other algorithm could have been
used.
7. Examine the lines to open the output file and write the
outputString in the ShoeStore class:
File file = new File(“export.txt”);
System.out.println(file.getAbsolutePath());
output = new BufferedWriter(new FileWriter(file));
output.write(outputString);
Where is the output file located? Find BufferedWriter in the
Java API documentation and describe the use of
this object.
8. Examine the code in the exportToFile method in the
ShoeShop.java file. What is the purpose of the ‘rn’ in the
toString() method that is used to produce the output string?
ITECH 1000/5000 Programming 1 Assignment 2 Specification
Semester 2, 2015 Page 3 of 7
9. Explain the use of the return value (result) of the compareTo
method in the Shoe class.
10. Briefly explain why the line to open the input file:
Scanner inputFile = new Scanner(new File("C:orders.txt"));
has two  in the filename specification. Where is the file
located? What happens if only one  is used? Is there
another option that would not require these?
11. Examine the code in the saveToFile method. How could
this be improved for readability of the output file?
What is the purpose of the ‘rn’?
12. Briefly explain why a try and catch clause has been included
in the code to read from the file. Remove this from
the code and remove the input file and take note of the error.
Re-add the line and investigate what happens if
the input file is not present. Record your observations in your
report.
Part B – Development of a Basic Class – Person
Your first coding task is to implement and test a class that
represents an Apartment. An Apartment object
has the following attributes: number of bedrooms, number of
bathrooms, the size of the apartment, the
number of living areas, an indication of whether the apartment
is available for rent, the owner of the
apartment and the amount of rent per week. To complete this
task, you are required to:
1. Create a new package in eclipse named
assignTwoStudentNNNNN where NNNNN is your student
number. You will author a number of classes for this assignment
and they will all be in this package.
2. Use the UML diagram provided to implement the class
Person in a file called Person.java. Starter code
has been provided with this assignment, copy this starter code
into your Apartment.java file. Complete
the constructors that will create a Person object.
a. Author all mutator and accessor (set and get) methods and the
toString() as indicated in the UML
diagram.
Person
- String name;
- String address;
~ Person(name:String, address:String)
+ getName():String
+ setName (_aName:String):boolean
+ getAddress():String
+ setAddress (_anAddress:String):boolean
+ toString():String
Figure 1: Person class UML
3. Update the class TestClass.java adding in code to:
a. Create an instance of the Person class
b. Set the name and address of the instance
c. Display the details of the Person that you have created using
the toString() method in the Person class.
ITECH 1000/5000 Programming 1 Assignment 2 Specification
Semester 2, 2015 Page 4 of 7
Part C – Development of a Basic Class - Apartment
1. Use the UML diagram provided to implement the class
Apartment in a file called Apartment.java adding
the class to your package assignTwoStudentNNNNN. Starter
code has been provided with this
assignment, copy this starter code into your Apartment.java file.
Complete the constructors that will
create an Apartment object.
a. Author all mutator and accessor (set and get) methods and the
toString() as indicated in the UML
diagram.
b. Ensure that your Apartment class includes the following
validation within the mutator (set) methods:
i. The owner of the Apartment cannot be null.
ii. The rent per week of the Apartment must be greater than
zero. If an attempt is made to set the
value of the rent to an invalid value the method should return
false and not change the value of
the attributes.
Apartment
- int numberOfBedrooms;
- int numberOfBathrooms;
- int numberOfLiving;
- int floorNumber;
- char apartmentLetter;
- Person owner;
- boolean available;
- double rent;
~ Apartment(numberofBedrooms:int,, numberOfBathrooms:int,
numberOfLiving:int,, owner:Person, available:boolean,
rent:double)
+ getOwner():Person
+ setOwner (_aPerson:Person):boolean
+ getNumberOfBedrooms():int
+ setNumberOfBedrooms(_numBedrooms:int)
+ getNumberOfBathrooms():int
+ setNumberOfBathrooms(_numBathrooms:int)
+ getNumberOfLiving():int
+ setNumberOffLivings(_numfLiving:int)
+ getAvailable():boolean
+ setAvailable(_available:boolean)
+ getRent():float
+ setRent(_rent:double):boolean
+ toString():String
ITECH 1000/5000 Programming 1 Assignment 2 Specification
Semester 2, 2015 Page 5 of 7
Figure 2: Apartment class UML Diagram
4. Update the class TestClass.java adding in code to:
a. Create an instance of the Apartment class
b. Create an instance of the Person class
c. Set all of the instance variables of the instance of the
Apartment class that you have created including
the owner (using the Person created in b. above)
d. Display the details of the Apartment that you have created
using the toString() method in the
Apartment class.
Part D – Development of the Building class
Using the UML diagrams provided and the information below
you are required to implement and test classes
that represent a Building object. For this assignment a Building
contains multiple Apartments up to a
specified capacity. (This may be modeled on the classes in the
sample code. Your Building will in a similar
way contain multiple Apartments in an array.)
Building.java
Building
- name: String
- apartments: Apartment[]
- numberOfApartments: int
- capacity: int
~ Building (initName: String, capacity: int) <<create>>
+ getName():String
+ getNumberOfApartments():int
+ setName(newName: String): boolean
+ addApartment(newApartment: Apartment): boolean
+ sortApartments()
+ numberEmpty(): int
+ exportToFile() //itech5000 students only
+ readFromFile() //itech5000 students only
+ toString():String
Figure 3: UML Diagram for the class Garage
1. You have been provided with starting point in Building.java -
add the provided class to your package
assignTwoStudentNNNNN.. Write get and set methods as well
as an addApartment method. addApartment
should return false if an attempt is made to add an apartment
after the Building has already reached its maximum
capacity.
2. Create a method for sorting the addApartment in the Building
ITECH 1000/5000 Programming 1 Assignment 2 Specification
Semester 2, 2015 Page 6 of 7
3. Update the class TestClass.java adding in code to:
a. Create an instance of the Building class
b. Add at least two Apartments created to the Building class
using the addApartment () method
c. Add at least two other Apartments to the Building class
d. Display the details of the Building that you have created
using the toString() method in the Building class
– these should be accessed via the instance of the Building class
that you have created
Part E – Using the Classes
Create a new class called Driver.java . This class is to be used
to implement a basic menu system. You may
find some of the code you have already written in the
TestClass.java can be copied and used with some
modification here. You may also find the menu code from
assignment one helpful as an example of a menu,
although in this case you should use a switch statement to
process the menu options. Each menu item
should be enacted by choosing the appropriate method on the
Building object. The menu should include the
following options:
1. Populate the Building
2. Display Apartments in the Building
3. Sort Apartment data
4. Reports
5. Import data (ITECH5000 students only)
6. Export data (ITECH5000 students only
7. Exit
Further information:
• Populate the Building – this option will either allow the user
to enter data for each apartment OR you
may write a populate method that will insert data hardcoded in
your method directly into each
Apartment.
• Display Data – display the data of all Apartments in the
Building, using your toString() method on the
Building object.
• Sort data should utilise some form of sorting algorithm to sort
the Apartments into order based on
apartment number.
• Reports – design a report that would be useful for the manager
of the building. As a minimum you
should display about the Apartments in the Building including:
o The number and percentage of empty apartments
o Current total rent per week (calculated for apartments that are
currently being rented)
You will need to include 2 further reports in your code.
For students enrolled in ITECH5000 ONLY:
• Import data – this menu should read in data from the file
called sampleData.txt. You are required to
add the additional data described above to this file.
• Export data – save the data to a new file exportData.txt
ITECH 1000/5000 Programming 1 Assignment 2 Specification
Semester 2, 2015 Page 7 of 7
Assignment Submission
The following criteria will be used when marking your
assignment:
• successful completion of the required tasks
• quality of code that adheres to the programming standards for
the course; including:
• comments and documentation
• code layout
• meaningful variable names
You are required to provide documentation, contained in an
appropriate file, which includes:
• a front page - indicating your name, a statement of what has
been completed and acknowledgement of the
names of all people (including other students and people outside
of the university) who have assisted you and
details on what parts of the assignment that they have assisted
you with
• a table of contents and page numbers
• answers to the questions from Part A
• UML diagrams and design of your report for part Part E
• A copy of the javadocs created from your assignment code
• list of references used (APA style); please specify if none
have been used
• An appendix containing copies of your code and evidence of
your testing
Using the link provided in Moodle, please upload the following:
1. All of the classes created in a single zip file –
SurnameStudentIdAssign2.zip
2. A copy of your report – surnameStudentIDAssign2.pdf
Marking Guide
PART A – Code Comprehension
/20
PART B – Person class + Testing
/20
PART C - Apartment class + Testing
/20
PART D - Building Class + Testing
/40
PART E – Implementation of Menu
/20
Quality of code created
/15
Presentation of documentation / report
/5
Total /20 /140
ITECH1000 Programming 1, Semester 2 2015Assignment 2 –
Development of a Simple Program Involving Multiple
ClassesDue Date: Week 11 - see Course Description for full
detailsProject SpecificationResources:Design ConstraintsPart A
– Code ComprehensionPart B – Development of a Basic Class –
PersonPart C – Development of a Basic Class - ApartmentPart D
– Development of the Building classBuilding.javaPart E – Using
the ClassesFor students enrolled in ITECH5000
ONLY:Assignment SubmissionMarking Guide

More Related Content

Similar to codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx

Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
Giordano Scalzo
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
rozakashif85
 
CIS355A_StudentName_CourseProjectCIS355A Week 7 Course Project..docx
CIS355A_StudentName_CourseProjectCIS355A Week 7 Course Project..docxCIS355A_StudentName_CourseProjectCIS355A Week 7 Course Project..docx
CIS355A_StudentName_CourseProjectCIS355A Week 7 Course Project..docx
clarebernice
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
whitneyleman54422
 
重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1
Chris Huang
 

Similar to codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx (20)

Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
 
Productaccess m
Productaccess mProductaccess m
Productaccess m
 
Google guava
Google guavaGoogle guava
Google guava
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
Creating an Uber Clone - Part XXXIV.pdf
Creating an Uber Clone - Part XXXIV.pdfCreating an Uber Clone - Part XXXIV.pdf
Creating an Uber Clone - Part XXXIV.pdf
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
 
CIS355A_StudentName_CourseProjectCIS355A Week 7 Course Project..docx
CIS355A_StudentName_CourseProjectCIS355A Week 7 Course Project..docxCIS355A_StudentName_CourseProjectCIS355A Week 7 Course Project..docx
CIS355A_StudentName_CourseProjectCIS355A Week 7 Course Project..docx
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
 
Backbone js
Backbone jsBackbone js
Backbone js
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)
 
重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1
 
Serial(ize) killers, czyli jak popsuliśmy API
Serial(ize) killers, czyli jak popsuliśmy APISerial(ize) killers, czyli jak popsuliśmy API
Serial(ize) killers, czyli jak popsuliśmy API
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 

More from monicafrancis71118

1. Despite our rational nature, our ability to reason well is ofte.docx
1. Despite our rational nature, our ability to reason well is ofte.docx1. Despite our rational nature, our ability to reason well is ofte.docx
1. Despite our rational nature, our ability to reason well is ofte.docx
monicafrancis71118
 
1. Describe in your own words the anatomy of a muscle.  This sho.docx
1. Describe in your own words the anatomy of a muscle.  This sho.docx1. Describe in your own words the anatomy of a muscle.  This sho.docx
1. Describe in your own words the anatomy of a muscle.  This sho.docx
monicafrancis71118
 
1. Case 3-4 Franklin Industries’ Whistleblowing (a GVV Case)Natali.docx
1. Case 3-4 Franklin Industries’ Whistleblowing (a GVV Case)Natali.docx1. Case 3-4 Franklin Industries’ Whistleblowing (a GVV Case)Natali.docx
1. Case 3-4 Franklin Industries’ Whistleblowing (a GVV Case)Natali.docx
monicafrancis71118
 
1. Date September 13, 2017 – September 15, 2017 2. Curr.docx
1. Date September 13, 2017 – September 15, 2017 2. Curr.docx1. Date September 13, 2017 – September 15, 2017 2. Curr.docx
1. Date September 13, 2017 – September 15, 2017 2. Curr.docx
monicafrancis71118
 
1. Compare and contrast Strategic and Tactical Analysis and its .docx
1. Compare and contrast Strategic and Tactical Analysis and its .docx1. Compare and contrast Strategic and Tactical Analysis and its .docx
1. Compare and contrast Strategic and Tactical Analysis and its .docx
monicafrancis71118
 
1. Coalition ProposalVaccination Policy for Infectious Disease P.docx
1. Coalition ProposalVaccination Policy for Infectious Disease P.docx1. Coalition ProposalVaccination Policy for Infectious Disease P.docx
1. Coalition ProposalVaccination Policy for Infectious Disease P.docx
monicafrancis71118
 
1. Company Description and Backgrounda. Weight Watchers was cr.docx
1. Company Description and Backgrounda. Weight Watchers was cr.docx1. Company Description and Backgrounda. Weight Watchers was cr.docx
1. Company Description and Backgrounda. Weight Watchers was cr.docx
monicafrancis71118
 
1. Come up with TWO movie ideas -- as in for TWO screenplays that .docx
1. Come up with TWO movie ideas -- as in for TWO screenplays that .docx1. Come up with TWO movie ideas -- as in for TWO screenplays that .docx
1. Come up with TWO movie ideas -- as in for TWO screenplays that .docx
monicafrancis71118
 
1. Choose a case for the paper that interests you. Most choose a .docx
1. Choose a case for the paper that interests you.  Most choose a .docx1. Choose a case for the paper that interests you.  Most choose a .docx
1. Choose a case for the paper that interests you. Most choose a .docx
monicafrancis71118
 

More from monicafrancis71118 (20)

1. Discuss Blockchains potential application in compensation system.docx
1. Discuss Blockchains potential application in compensation system.docx1. Discuss Blockchains potential application in compensation system.docx
1. Discuss Blockchains potential application in compensation system.docx
 
1. Describe the characteristics of the aging process. Explain how so.docx
1. Describe the characteristics of the aging process. Explain how so.docx1. Describe the characteristics of the aging process. Explain how so.docx
1. Describe the characteristics of the aging process. Explain how so.docx
 
1. Dis. 7Should we continue to collect data on race and .docx
1. Dis. 7Should we continue to collect data on race and .docx1. Dis. 7Should we continue to collect data on race and .docx
1. Dis. 7Should we continue to collect data on race and .docx
 
1. Differentiate crisis intervention from other counseling therapeut.docx
1. Differentiate crisis intervention from other counseling therapeut.docx1. Differentiate crisis intervention from other counseling therapeut.docx
1. Differentiate crisis intervention from other counseling therapeut.docx
 
1. Despite our rational nature, our ability to reason well is ofte.docx
1. Despite our rational nature, our ability to reason well is ofte.docx1. Despite our rational nature, our ability to reason well is ofte.docx
1. Despite our rational nature, our ability to reason well is ofte.docx
 
1. Describe the ethical challenges faced by organizations operating .docx
1. Describe the ethical challenges faced by organizations operating .docx1. Describe the ethical challenges faced by organizations operating .docx
1. Describe the ethical challenges faced by organizations operating .docx
 
1. Describe in your own words the anatomy of a muscle.  This sho.docx
1. Describe in your own words the anatomy of a muscle.  This sho.docx1. Describe in your own words the anatomy of a muscle.  This sho.docx
1. Describe in your own words the anatomy of a muscle.  This sho.docx
 
1. Describe how your attitude of including aspects of health literac.docx
1. Describe how your attitude of including aspects of health literac.docx1. Describe how your attitude of including aspects of health literac.docx
1. Describe how your attitude of including aspects of health literac.docx
 
1. Choose a behavior (such as overeating, shopping, Internet use.docx
1. Choose a behavior (such as overeating, shopping, Internet use.docx1. Choose a behavior (such as overeating, shopping, Internet use.docx
1. Choose a behavior (such as overeating, shopping, Internet use.docx
 
1. Case 3-4 Franklin Industries’ Whistleblowing (a GVV Case)Natali.docx
1. Case 3-4 Franklin Industries’ Whistleblowing (a GVV Case)Natali.docx1. Case 3-4 Franklin Industries’ Whistleblowing (a GVV Case)Natali.docx
1. Case 3-4 Franklin Industries’ Whistleblowing (a GVV Case)Natali.docx
 
1. Cryptography is used to protect confidential data in many areas. .docx
1. Cryptography is used to protect confidential data in many areas. .docx1. Cryptography is used to protect confidential data in many areas. .docx
1. Cryptography is used to protect confidential data in many areas. .docx
 
1. Compare and contrast steganography and cryptography.2. Why st.docx
1. Compare and contrast steganography and cryptography.2. Why st.docx1. Compare and contrast steganography and cryptography.2. Why st.docx
1. Compare and contrast steganography and cryptography.2. Why st.docx
 
1. Date September 13, 2017 – September 15, 2017 2. Curr.docx
1. Date September 13, 2017 – September 15, 2017 2. Curr.docx1. Date September 13, 2017 – September 15, 2017 2. Curr.docx
1. Date September 13, 2017 – September 15, 2017 2. Curr.docx
 
1. compare and contrast predictive analytics with prescriptive and d.docx
1. compare and contrast predictive analytics with prescriptive and d.docx1. compare and contrast predictive analytics with prescriptive and d.docx
1. compare and contrast predictive analytics with prescriptive and d.docx
 
1. Creating and maintaining relationships between home and schoo.docx
1. Creating and maintaining relationships between home and schoo.docx1. Creating and maintaining relationships between home and schoo.docx
1. Creating and maintaining relationships between home and schoo.docx
 
1. Compare and contrast Strategic and Tactical Analysis and its .docx
1. Compare and contrast Strategic and Tactical Analysis and its .docx1. Compare and contrast Strategic and Tactical Analysis and its .docx
1. Compare and contrast Strategic and Tactical Analysis and its .docx
 
1. Coalition ProposalVaccination Policy for Infectious Disease P.docx
1. Coalition ProposalVaccination Policy for Infectious Disease P.docx1. Coalition ProposalVaccination Policy for Infectious Disease P.docx
1. Coalition ProposalVaccination Policy for Infectious Disease P.docx
 
1. Company Description and Backgrounda. Weight Watchers was cr.docx
1. Company Description and Backgrounda. Weight Watchers was cr.docx1. Company Description and Backgrounda. Weight Watchers was cr.docx
1. Company Description and Backgrounda. Weight Watchers was cr.docx
 
1. Come up with TWO movie ideas -- as in for TWO screenplays that .docx
1. Come up with TWO movie ideas -- as in for TWO screenplays that .docx1. Come up with TWO movie ideas -- as in for TWO screenplays that .docx
1. Come up with TWO movie ideas -- as in for TWO screenplays that .docx
 
1. Choose a case for the paper that interests you. Most choose a .docx
1. Choose a case for the paper that interests you.  Most choose a .docx1. Choose a case for the paper that interests you.  Most choose a .docx
1. Choose a case for the paper that interests you. Most choose a .docx
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx

  • 1. codeComprehension/orders.txt womens sandals 1011 6 78.00 red 12 womens runners 2231 7 128.00 white 5 mens boat 7124 8 35.00 leather 3 mens dress 6122 11 165.00 black 0 childs sandals 3331 1 25.00 silver 6 childs school 2121 4 69.00 black 7 womens dress 4321 7 99.99 blue 2 womens sandals 2223 6 67.95 brown 5 childs school 2123 6 59.95 black 9 mens runners 53423 8 189.00 blue 5 childs runner 44453 3 59.95 orange 2 codeComprehension/Shoe.javacodeComprehension/Shoe.javapac kage sampleAssignment2; publicclassShoe{ privateString style; privateint size; privateint code; privateString category; privateString color;
  • 2. privatedouble price; publicShoe(){ style=""; size=0; code=0; category=""; color=""; price=0.0; } publicShoe(String aCategory,String aStyle,int aCode,int aSize,d ouble aPrice,String aColor){ category = aCategory; style=aStyle; size=aSize; code=aCode; price=aPrice; color=aColor; } publicString getColor(){ return color; } publicvoid setColor(String color){ this.color = color; } publicString getStyle(){ return style; } publicvoid setStyle(String style){ this.style = style; }
  • 3. publicint getSize(){ return size; } publicvoid setSize(int size){ this.size = size; } publicint getCode(){ return code; } publicvoid setCode(int code){ this.code = code; } publicString getCategory(){ return category; } publicvoid setCategory(String aCategory){ this.category = aCategory; } publicdouble getPrice(){ return price; } publicvoid setPrice(double price){ this.price = price; } publicint compareTo(Shoe anotherShoe){ if(this.getCode()> anotherShoe.getCode()) return1;
  • 4. elseif(this.getCode()< anotherShoe.getCode()) return-1; else return0; } publicString toString(){ return code +"t"+ category +"t"+ style +"t"+ size +"t"+ price +"t"+ color; } } codeComprehension/ShoeShop.javacodeComprehension/ShoeSh op.javapackage codeComprehension; import java.util.Scanner; import java.io.*; publicclassShoeShop{ publicstaticvoid main(String[] args){ boolean done=false; int menuSelection; int numberOfLines=0; Store myStore =newStore("Value Shoes","Melbourne"); while(!done){ menuSelection = obtainMenuSelection(); switch(menuSelection){ case1:System.out.println("Menu 1 - Read from file"); numberOfLines =readFromFile(myStore); System.out.println("Read "+ numberOfLines +" lines"); break; case2:System.out.println("Menu 2 - Display inventory");
  • 5. myStore.displayInventory(); break; case3:System.out.println("Menu 3 - Sort inventory"); myStore.sortInventory(); myStore.displayInventory(); break; case4:System.out.println("Menu 4 - Save file"); numberOfLines = exportToFile(myStore); System.out.println(numberOfLines +" saved to file."); break; case5:System.out.println("Menu 5 - Search inventory"); searchInventory(myStore); break; case6:System.out.println("Menu 6 - Exiting"); done=true; break; } } } publicstaticint obtainMenuSelection(){ Scanner in =newScanner(System.in); System.out.println("Menu"); System.out.println("1 - Read inventory from file"); System.out.println("2 - Display inventory"); System.out.println("3 - Sort inventory"); System.out.println("4 - Save inventory"); System.out.println("5 - Search inventory"); System.out.println("6 - Exit"); System.out.println("Choice: "); return in.nextInt(); }
  • 6. publicstaticint readFromFile(Store myStore){ int numAdded=0; try{ Scanner inputFile =newScanner(newFile("c:orders.txt")); while(inputFile.hasNext()){ //Read the details from the file String style = inputFile.next(); String type = inputFile.next(); int code = inputFile.nextInt(); int size = inputFile.nextInt(); double price = inputFile.nextDouble(); String color = inputFile.next(); int onhand = inputFile.nextInt(); //Create a new Shoe instance using the details from the file Shoe aShoe =newShoe(style,type,code,size,price,color); //Add the new Shoe to the inventory myStore.addShoes(aShoe); numAdded++; } inputFile.close(); }catch(IOException e){ System.out.println("Error occured reading from file"); e.printStackTrace(); } //Return a value representing the number of shoes read from the file return numAdded++; }
  • 7. publicstaticint exportToFile(Store myStore)throwsIOException{ int numOutput=0; BufferedWriter output; try{ File file =newFile("export.txt"); System.out.println(file.getAbsolutePath()); output =newBufferedWriter(newFileWriter(file)); while(numOutput < myStore.inventorySize()){ Shoe nextShoe = myStore.getShoes(numOutput); output.flush(); output.write(nextShoe.toString()+"rn"); numOutput++; } output.close(); }catch(IOException e){ System.out.println("Error occured reading from file"); e.printStackTrace(); } return numOutput++; } publicstaticvoid searchInventory(Store myStore){ System.out.println("Searching Inventory"); Scanner in =newScanner(System.in); int searchCode; Shoe foundShoe; System.out.println("Enter the code to search for: "); searchCode = in.nextInt();
  • 8. foundShoe = myStore.searchInventory(searchCode); if(foundShoe!=null) System.out.println(foundShoe +" current in stock"); else System.out.println("Not current in stock"); } } codeComprehension/Store.javacodeComprehension/Store.javapa ckage sampleAssignment2; publicclassStore{ privateString storeName; privateString location; privateShoe[] inventory; privatefinalint MAX_SHOES =100; privateint numShoes; publicStore(){ storeName=""; location=""; inventory =newShoe[MAX_SHOES]; numShoes=0; } publicStore(String aName,String aLocation){
  • 9. storeName=""; location=""; inventory =newShoe[MAX_SHOES]; numShoes=0; } publicString getStoreName(){ return storeName; } publicvoid setStoreName(String storeName){ this.storeName = storeName; } publicString getLocation(){ return location; } publicvoid setLocation(String location){ this.location = location; } publicvoid addShoes(Shoe aPair){ this.inventory[numShoes++]= aPair; } publicint inventorySize(){ return numShoes; } publicShoe getShoes(int anIndex){ return inventory[anIndex]; } publicvoid sortInventory(){ for(int i=(this.inventorySize())-1; i>=1; i--){
  • 10. //Set the maximum shoe (ie highest code) to be position 0 Shoe curMaxShoe=inventory[0]; int curMaxIndex=0; for(int j=1;j<=i;j++){ //check to see if the next Shoe code is > than curMax if(curMaxShoe.compareTo(inventory[j])==-1){ curMaxShoe=(inventory[j]); curMaxIndex=j; } } if(curMaxIndex !=i){ inventory[curMaxIndex]= inventory[i]; inventory[i]= curMaxShoe; } } } publicvoid displayInventory(){ for(int i=0;i<this.inventorySize(); i++){ System.out.println(inventory[i]); } } publicShoe searchInventory(int searchCode){ Shoe target=null; for(int i=0;i<this.inventorySize(); i++){ if(inventory[i].getCode()== searchCode){ target=inventory[i]; break; } } return target;
  • 11. } publicString toString(){ return storeName +" "+ location +" has "+ inventory.length +" s hoes in store."; } } starterCode/Apartment.javastarterCode/Apartment.javapackage starterCode; publicclassApartment{ privateint numberOfBedrooms; privateint numberOfBathrooms; privatedouble squareMetres; privateint numberOfLiving; privateboolean available; privatePerson owner; privatedouble rentPerWeek; privateint apartmentNumber; privateint floor; //empty constructor publicApartment(){ } //constructor with initialisation values publicApartment(int numBeds,int numBath,double sq,boolean a vail,Person owner2,double rent){
  • 12. } publicint getNumberOfBedrooms(){ return1;//change this to appropriate value } publicvoid setNumberOfBedrooms(int numberOfBedrooms){ } publicint getNumberOfBathrooms(){ return1;//change this to appropriate value } publicvoid setNumberOfBathrooms(int numberOfBathrooms){ } publicdouble getSquareMetres(){ return1;//change this to appropriate value } publicvoid setSquareMetres(double squareMetres){ } publicint getNumberOfLiving(){ return1;//change this to appropriate value } publicvoid setNumberOfLiving(int numberOfLiving){
  • 13. } publicboolean isAvailable(){ returntrue;//change this to appropriate value } publicvoid setAvailable(boolean available){ } publicPerson getOwner(){ returnnull;//change this to appropriate value } publicvoid setOwner(Person owner){ } publicString toString(){ return""; } } starterCode/Building.javastarterCode/Building.javapackage start erCode; import java.util.Arrays;
  • 14. publicclassBuilding{ privateApartment apartments[]; privateString name; privateint numberOfApartments; privateint capacity=100; publicBuilding(){ apartments =newApartment[capacity]; numberOfApartments=0; } publicBuilding(int _capacity){ capacity=_capacity; apartments =newApartment[capacity]; numberOfApartments=0; } // TODO: add get and set methods // TODO: add toString() method // TODO: add other methods including addApartment } starterCode/TestClass.javastarterCode/TestClass.javapackage st arterCode;
  • 15. publicclassTestClass{ publicTestClass(){// constructor for TestClass } publicvoid runtest1(){ // first test case Apartment myApartment =newApartment(); System.out.println(myApartment.toString()); } publicvoid runtest2(){ // second test case } publicvoid runtest3(){ // third test case } publicstaticvoid main(String[] args){ // TODO write code here TestClass mytest =newTestClass(); System.out.println("Running test1... "); mytest.runtest1(); System.out.println("Running test2... "); mytest.runtest2(); System.out.println("Running test3... "); mytest.runtest3();
  • 16. } } ITECH1000 Programming 1 Assignment 2 Specification 2015 Sem 2.pdf Programming 1 Assignment 2, 2015 Sem 2 Page 1 of 7 ITECH1000 Programming 1, Semester 2 2015 Assignment 2 – Development of a Simple Program Involving Multiple Classes Due Date: Week 11 - see Course Description for full details Please see the Course Description for further information related to extensions for assignments and Special Consideration. Important Notes 1. Code that does not successfully compile will not be marked. In such cases, only the specification, design and question sections of the assignment will be awarded marks. If you are unable to get sections of your code to compile prior to handing it in, please state this clearly in your submission and comment out the offending code. Marks will also be deducted if your code compiles but contains warnings. Please see your tutor for help if you are unable to successfully compile your code.
  • 17. 2. If you use any resources apart from the course material to complete your assignment you MUST provide an in-text citation within your documentation and/or code, as well as providing a list of references in APA formatting. This includes the use of any websites, online forums, books or text books. If you are unsure of how to do this please either see the online guide or ask your tutor for help. 3. You are strongly urged to keep backup files as you work on the project so that you can revert to an earlier version if you break an aspect of the program while attempting to implement one of the later requirements. 4. If you encounter any problems in uploading files to Moodle please report this to your lecturer or other staff member as soon as possible. It is your responsibility to check that you are submitting the correct version of your files and the correct assignment. 5. You may be required to demonstrate and explain your working code to your tutor in your lab class. Project Specification Please read through the entire specification PRIOR to beginning work. The assignment should be completed in the stages mentioned below. The objectives of this assignment are for you to: • Write your own classes from a specification • Instantiate objects of these classes • Perform required tasks by creating and manipulating objects in the code of one class through the public interfaces (methods) of the classes of the objects being manipulated.
  • 18. The context for this assignment will be creating a software system to support the management of a Building, which a number of Apartments that are for rent. ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 2 of 7 Resources: The following files/links are available on Moodle: • An electronic copy of this assignment specification sheet • A sample program with similar features to the assignment requirements involving multiple classes • Starter code for some of the classes which you will need to create Design Constraints Your program should conform to the following constraints. • Use a while-loop when the number of iterations is not known before loop execution. • Use a for-loop when the number of iterations is known before loop execution. • Indent your code correctly to aid readability and use a consistent curly bracket placement scheme. • Use white space to make your code as readable as possible. • Validation of input should be limited to ensuring that the user has entered values that are within correct
  • 19. bounds. You do not have to check that they have entered the correct data type. • Comment your code appropriately. Part A – Code Comprehension A Sample program is provided. Make sure you understand this code as it will help you with your own programming for this assignment. Using the uncommented sample code for classes provided, answer the following questions: 1. Draw a UML diagram of the Shoe class using the code that has been provided. Complete this using the examples that have been provide in the lecture slides. 2. Draw a UML diagram of the Store class using the code that has been provided. Complete this using the examples that have been provide in the lecture slides. 3. Copy the code from Store.java into your report and appropriately comment the code. At a minimum, explain the purpose of each method. For the more complex methods reading input from a file, sorting the data and exporting data to the file, insert comments to explain the code. 4. Briefly explain the code in sortInventory. What is the inventory being sorted by? What is the sort algorithm that is being used. Explain in words how it works. Why do you need to use two for loops? 5. Briefly explain what other sorting algorithms could have been used. 6. What method of searching for shoes has been used in the program? What other algorithm could have been used.
  • 20. 7. Examine the lines to open the output file and write the outputString in the ShoeStore class: File file = new File(“export.txt”); System.out.println(file.getAbsolutePath()); output = new BufferedWriter(new FileWriter(file)); output.write(outputString); Where is the output file located? Find BufferedWriter in the Java API documentation and describe the use of this object. 8. Examine the code in the exportToFile method in the ShoeShop.java file. What is the purpose of the ‘rn’ in the toString() method that is used to produce the output string? ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 3 of 7 9. Explain the use of the return value (result) of the compareTo method in the Shoe class. 10. Briefly explain why the line to open the input file: Scanner inputFile = new Scanner(new File("C:orders.txt")); has two in the filename specification. Where is the file located? What happens if only one is used? Is there another option that would not require these? 11. Examine the code in the saveToFile method. How could this be improved for readability of the output file? What is the purpose of the ‘rn’?
  • 21. 12. Briefly explain why a try and catch clause has been included in the code to read from the file. Remove this from the code and remove the input file and take note of the error. Re-add the line and investigate what happens if the input file is not present. Record your observations in your report. Part B – Development of a Basic Class – Person Your first coding task is to implement and test a class that represents an Apartment. An Apartment object has the following attributes: number of bedrooms, number of bathrooms, the size of the apartment, the number of living areas, an indication of whether the apartment is available for rent, the owner of the apartment and the amount of rent per week. To complete this task, you are required to: 1. Create a new package in eclipse named assignTwoStudentNNNNN where NNNNN is your student number. You will author a number of classes for this assignment and they will all be in this package. 2. Use the UML diagram provided to implement the class Person in a file called Person.java. Starter code has been provided with this assignment, copy this starter code into your Apartment.java file. Complete the constructors that will create a Person object. a. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML diagram. Person - String name;
  • 22. - String address; ~ Person(name:String, address:String) + getName():String + setName (_aName:String):boolean + getAddress():String + setAddress (_anAddress:String):boolean + toString():String Figure 1: Person class UML 3. Update the class TestClass.java adding in code to: a. Create an instance of the Person class b. Set the name and address of the instance c. Display the details of the Person that you have created using the toString() method in the Person class. ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 4 of 7 Part C – Development of a Basic Class - Apartment 1. Use the UML diagram provided to implement the class Apartment in a file called Apartment.java adding the class to your package assignTwoStudentNNNNN. Starter code has been provided with this
  • 23. assignment, copy this starter code into your Apartment.java file. Complete the constructors that will create an Apartment object. a. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML diagram. b. Ensure that your Apartment class includes the following validation within the mutator (set) methods: i. The owner of the Apartment cannot be null. ii. The rent per week of the Apartment must be greater than zero. If an attempt is made to set the value of the rent to an invalid value the method should return false and not change the value of the attributes. Apartment - int numberOfBedrooms; - int numberOfBathrooms; - int numberOfLiving; - int floorNumber; - char apartmentLetter; - Person owner; - boolean available; - double rent;
  • 24. ~ Apartment(numberofBedrooms:int,, numberOfBathrooms:int, numberOfLiving:int,, owner:Person, available:boolean, rent:double) + getOwner():Person + setOwner (_aPerson:Person):boolean + getNumberOfBedrooms():int + setNumberOfBedrooms(_numBedrooms:int) + getNumberOfBathrooms():int + setNumberOfBathrooms(_numBathrooms:int) + getNumberOfLiving():int + setNumberOffLivings(_numfLiving:int) + getAvailable():boolean + setAvailable(_available:boolean) + getRent():float + setRent(_rent:double):boolean + toString():String ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 5 of 7
  • 25. Figure 2: Apartment class UML Diagram 4. Update the class TestClass.java adding in code to: a. Create an instance of the Apartment class b. Create an instance of the Person class c. Set all of the instance variables of the instance of the Apartment class that you have created including the owner (using the Person created in b. above) d. Display the details of the Apartment that you have created using the toString() method in the Apartment class. Part D – Development of the Building class Using the UML diagrams provided and the information below you are required to implement and test classes that represent a Building object. For this assignment a Building contains multiple Apartments up to a specified capacity. (This may be modeled on the classes in the sample code. Your Building will in a similar way contain multiple Apartments in an array.) Building.java Building - name: String - apartments: Apartment[] - numberOfApartments: int - capacity: int ~ Building (initName: String, capacity: int) <<create>>
  • 26. + getName():String + getNumberOfApartments():int + setName(newName: String): boolean + addApartment(newApartment: Apartment): boolean + sortApartments() + numberEmpty(): int + exportToFile() //itech5000 students only + readFromFile() //itech5000 students only + toString():String Figure 3: UML Diagram for the class Garage 1. You have been provided with starting point in Building.java - add the provided class to your package assignTwoStudentNNNNN.. Write get and set methods as well as an addApartment method. addApartment should return false if an attempt is made to add an apartment after the Building has already reached its maximum capacity. 2. Create a method for sorting the addApartment in the Building ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 6 of 7
  • 27. 3. Update the class TestClass.java adding in code to: a. Create an instance of the Building class b. Add at least two Apartments created to the Building class using the addApartment () method c. Add at least two other Apartments to the Building class d. Display the details of the Building that you have created using the toString() method in the Building class – these should be accessed via the instance of the Building class that you have created Part E – Using the Classes Create a new class called Driver.java . This class is to be used to implement a basic menu system. You may find some of the code you have already written in the TestClass.java can be copied and used with some modification here. You may also find the menu code from assignment one helpful as an example of a menu, although in this case you should use a switch statement to process the menu options. Each menu item should be enacted by choosing the appropriate method on the Building object. The menu should include the following options: 1. Populate the Building 2. Display Apartments in the Building 3. Sort Apartment data 4. Reports 5. Import data (ITECH5000 students only) 6. Export data (ITECH5000 students only
  • 28. 7. Exit Further information: • Populate the Building – this option will either allow the user to enter data for each apartment OR you may write a populate method that will insert data hardcoded in your method directly into each Apartment. • Display Data – display the data of all Apartments in the Building, using your toString() method on the Building object. • Sort data should utilise some form of sorting algorithm to sort the Apartments into order based on apartment number. • Reports – design a report that would be useful for the manager of the building. As a minimum you should display about the Apartments in the Building including: o The number and percentage of empty apartments o Current total rent per week (calculated for apartments that are currently being rented) You will need to include 2 further reports in your code. For students enrolled in ITECH5000 ONLY: • Import data – this menu should read in data from the file called sampleData.txt. You are required to add the additional data described above to this file.
  • 29. • Export data – save the data to a new file exportData.txt ITECH 1000/5000 Programming 1 Assignment 2 Specification Semester 2, 2015 Page 7 of 7 Assignment Submission The following criteria will be used when marking your assignment: • successful completion of the required tasks • quality of code that adheres to the programming standards for the course; including: • comments and documentation • code layout • meaningful variable names You are required to provide documentation, contained in an appropriate file, which includes: • a front page - indicating your name, a statement of what has been completed and acknowledgement of the names of all people (including other students and people outside of the university) who have assisted you and details on what parts of the assignment that they have assisted you with • a table of contents and page numbers • answers to the questions from Part A • UML diagrams and design of your report for part Part E • A copy of the javadocs created from your assignment code
  • 30. • list of references used (APA style); please specify if none have been used • An appendix containing copies of your code and evidence of your testing Using the link provided in Moodle, please upload the following: 1. All of the classes created in a single zip file – SurnameStudentIdAssign2.zip 2. A copy of your report – surnameStudentIDAssign2.pdf Marking Guide PART A – Code Comprehension /20 PART B – Person class + Testing /20 PART C - Apartment class + Testing /20 PART D - Building Class + Testing /40 PART E – Implementation of Menu /20 Quality of code created /15 Presentation of documentation / report /5 Total /20 /140 ITECH1000 Programming 1, Semester 2 2015Assignment 2 – Development of a Simple Program Involving Multiple ClassesDue Date: Week 11 - see Course Description for full detailsProject SpecificationResources:Design ConstraintsPart A – Code ComprehensionPart B – Development of a Basic Class –
  • 31. PersonPart C – Development of a Basic Class - ApartmentPart D – Development of the Building classBuilding.javaPart E – Using the ClassesFor students enrolled in ITECH5000 ONLY:Assignment SubmissionMarking Guide