SlideShare a Scribd company logo
1 of 15
week4_src/ArrayMethods.javaweek4_src/ArrayMethods.javapac
kage edu.drexel.ct290;
publicclassArrayMethods{
/**
* Pass and array to a method that will search through it for a
given value.
*
* @param elementToFind: This is the item we want to find i
n the array.
* @param stringArray: This is the array to search through.
* @return Returns: The index of the element, or -
1 if not found.
*/
publicint findElement(String elementToFind,String[] stringArra
y ){
int index =-1;
for(int i=0; i<stringArray.length; i++){
if( elementToFind.equals(stringArray[i])){
// If the element is found, set index
index = i;
}
}
return index;
}
/**
* Replace a value in an array.
*
* @param indexToReplace: The index where the new value s
hould be written.
* @param newValue: The new value.
* @param stringArray: Change a value in this array.
* @return True if the given index is valid
*/
publicboolean replace(int indexToReplace,String newValue,Stri
ng[] stringArray ){
boolean replaced =false;
// Use the if condition to make sure the given index is valid
if( indexToReplace >0&& indexToReplace < stringArray.length
){
stringArray[indexToReplace]= newValue;
replaced =true;
}
return replaced;
}
/**
* Insert a value into the array. From the insertion point on, t
he
* data needs to be copied down one space to make room for t
he new
* element indices .
*
* @param index: The index where the new element should b
e inserted
* @param element: The element to insert in the array
* @param array: The array to insert into
* @param indicesUsed: the number of elements in the array
already used
* @return the array with the new value inserted
*/
publicString[] insert(int index,String element,String[] array,int i
ndicesUsed){
// First, check that there is enough room in the array for
// another element. The parameter indicesUsed indicates how
// many elements of the array are already filled.
String[] newArray = array;
if( indicesUsed == array.length ){
newArray = makeBiggerArray(array);
}
// Now that we know there is enough room, move the
// elements down one spot in the array until we get to the
// insertion point. Make sure the element at the insertion
// point gets moved too.
int indexToMove = indicesUsed;
while( indexToMove >= index ){
newArray[indexToMove+1]= newArray[indexToMove];
indexToMove--;
}
// Set the given index to the new element
newArray[index]= element;
// Return the new array
return newArray;
}
/**
* Since arrays are fixed size, if you run out of room, the
* only options is to create a new bigger array, then copy
* the old data over.
* @param oldArray: The old data to copy into the new array
* @return The new bigger array
*/
publicString[] makeBiggerArray(String[] oldArray){
// Make the new array twice the size of the old one.
int newArraySize = oldArray.length *2;
String[] newArray =newString[newArraySize];
// Copy the old data over to the new array
for(int i=0; i<oldArray.length; i++){
newArray[i]= oldArray[i];
}
return newArray;
}
publicvoid printArray(String[] array ){
for(int i=0; i<array.length; i++){
System.out.println("Element "+ i +": "+ array[i]);
}
}
publicstaticvoid main(String[] args){
String[] groceries =newString[5];
groceries[0]="bread";
groceries[1]="milk";
groceries[2]="cheese";
groceries[3]="steak";
groceries[4]="portobello mushrooms";
ArrayMethods arrayMethods =newArrayMethods();
arrayMethods.printArray(groceries);
int cheese = arrayMethods.findElement("cheese", groceries);
// You could use an if condition to make sure the result is not -1
System.out.println("nCheese is at index: "+ cheese +"n");
arrayMethods.replace(4,"lobster", groceries);
arrayMethods.printArray(groceries);
System.out.println("nInsert onion into the list.n");
String[] withOnion = arrayMethods.insert(3,"onion",groceries,5
);
arrayMethods.printArray( withOnion );
// make a blank line so the output is easier to read
System.out.println("");
String[] moreGroceries = arrayMethods.makeBiggerArray(groce
ries);
arrayMethods.printArray(moreGroceries);
}
}
__MACOSX/week4_src/._ArrayMethods.java
week4_src/Contacts.javaweek4_src/Contacts.javapackage edu.dr
exel.ct290;
import java.util.ArrayList;
publicclassContacts{
// Collects can hold any type of object, but its best to tell
// Java what type of object it will be. To do that put the
// class name in angle brackets right after the collection type.
// In this case we will have an ArrayList that holds objects of ty
pe
// Person (same as the Person class used in week 3).
privateArrayList<Person> contacts =newArrayList<Person>();
publicvoid addContact(Person newPerson ){
// To add an element to an ArrayList simply call the add method
.
// With array list, you don't have to worry about the size.
contacts.add(newPerson);
}
publicint find(Person person ){
// Find the index of a given object.
// indexOf returns -1 if not found
return contacts.indexOf(person);
}
publicvoid delete(Person person ){
// simply use remove to delete an element from the list
// There is also a remove method that removes based on index
contacts.remove(person);
}
publicvoid deleteAll(){
// ArrayList's clear method removes all elements from the list.
contacts.clear();
}
publicvoid printAll(){
// Use size() to get the number of elements in the list.
for(int i=0; i<contacts.size(); i++){
Person contact = contacts.get(i);
System.out.println("n"+ contact.toString());
}
}
}
week4_src/FirstArray.javaweek4_src/FirstArray.javapackage ed
u.drexel.ct290;
publicclassFirstArray{
publicstaticvoid main(String[] args){
// Create an array of five strings
String[] groceries =newString[5];
// After creation, the array is empty, so lets fill it up:
// Recall that array index go from 0 to size-1. In this case 0-4
// Using brackets with an index references a specific element.
groceries[0]="bread";
groceries[1]="milk";
groceries[2]="cheese";
groceries[3]="steak";
groceries[4]="portobello mushrooms";
// Now print out each value in the array. For loops are ideal
// for arrays since we know the exact number of iterations.
// Here we start with element, 0, and keep incrementing i
// as long as i is less than 5
for(int i=0; i<5; i++){
System.out.println("Element "+ i +": "+ groceries[i]);
}
// Array also have properties you can access with the . operator
// Most notably the lenght of the array:
System.out.println("Array size: "+ groceries.length);
// Trying using groceries.length in the for loop above instead of
// using the hard coded size.
// Most array errors occur due to using an invalid index:
// Uncomment the line below, then see what happens when you r
un it:
//System.out.println("More groceries: " + groceries[6]);
}
}
__MACOSX/week4_src/._FirstArray.java
week4_src/GradeBook.javaweek4_src/GradeBook.javapackage e
du.drexel.ct290;
import java.util.ArrayList;
import java.util.Scanner;
publicclassGradeBook{
privateString course;
privateArrayList<Person> students =newArrayList<Person>();
privateArrayList<GradeBookEntry> entries =newArrayList<Gra
deBookEntry>();
publicString getCourse(){
return course;
}
publicvoid setCourse(String course){
this.course = course;
}
publicvoid addStudent(Person student ){
students.add(student);
}
publicvoid addEntry(){
// Print out each students name and choose one
System.out.println("Grade which student: ");
for(int i=0; i<students.size(); i++){
System.out.println(i +" "+ students.get(i).getName());
}
Scanner reader =newScanner(System.in);
reader.nextInt();
reader.nextLine();
// TODO: get the assessment name and numeric grade
GradeBookEntry entry =newGradeBookEntry();
// TODO: set the data in the new entry
entries.add(entry);
}
publicvoid listGrades(){
// TODO: Print out all the grade entries in this gradbook
}
publicvoid displaySummary(){
// TODO: show a distribution of letter grades in this class.
// See the barchart example in Java HTP 7.4
}
publicstaticvoid main(String[] args){
Person person1 =newPerson();
person1.setName("John");
Person person2 =newPerson();
person1.setName("Lisa");
Person person3 =newPerson();
person1.setName("Bill");
Person person4 =newPerson();
person1.setName("Sarah");
GradeBook book =newGradeBook();
book.setCourse("CT-290");
// TODO: add some gradbook entries
// TODO: list the entries and disply the bar chart
}
}
week4_src/GradeBookEntry.javaweek4_src/GradeBookEntry.jav
apackage edu.drexel.ct290;
import java.util.Scanner;
publicclassGradeBookEntry{
privatePerson student;
privateint numericGrade;
privateString assessmentName;
// The next six methods are just getters and setters
// for the member variables of this class.
publicPerson getStudent(){
return student;
}
publicvoid setStudent(Person student){
this.student = student;
}
publicint getNumericGrade(){
return numericGrade;
}
publicvoid setNumericGrade(int numericGrade){
this.numericGrade = numericGrade;
}
publicString getAssessmentName(){
return assessmentName;
}
publicvoid setAssessmentName(String assessmentName){
this.assessmentName = assessmentName;
}
publicString getLetterGrade(){
GradeConverter converter =newGradeConverter();
return converter.convertGrade(numericGrade);
}
publicvoid printEntry(){
System.out.println(student.toString());
// instantiate a GradeConverter to get the letter grade.
GradeConverter converter =newGradeConverter();
System.out.println("Scored "+ numericGrade );
System.out.println("Which is a: "+ converter.convertGrade(num
ericGrade));
System.out.println("For assessment: "+ assessmentName);
}
publicstaticvoid main(String[] args){
// instantiate the GradeBookEntry, just like we have
// done with the Scanner class.
GradeBookEntry gradeBookEntry =newGradeBookEntry();
Scanner reader =newScanner(System.in);
// instantiate a new person object
Person student =newPerson();
student.getPersonData();
gradeBookEntry.setStudent(student);
System.out.print("Enter this students numeric grade: ");
int grade = reader.nextInt();
gradeBookEntry.setNumericGrade(grade);
gradeBookEntry.setAssessmentName("test1");
gradeBookEntry.printEntry();
}
}
__MACOSX/week4_src/._GradeBookEntry.java
week4_src/GradeConverter.javaweek4_src/GradeConverter.java
package edu.drexel.ct290;
import java.util.Scanner;
publicclassGradeConverter{
publicString convertGrade(int numberGrade ){
if( numberGrade >=90){
return"A";
}
elseif( numberGrade >=80){
return"B";
}
elseif( numberGrade >=70){
return"C";
}
elseif( numberGrade >=60){
return"D";
}
else{
return"F";
}
}
/**
* This method gets input from the user
* @return a grade in number format from 0-100
*/
publicint getNumberGrade(){
// declare and intialize variables
int userInput=0;
Scanner reader =newScanner(System.in);
// get the user input
System.out.print("Enter the number grade: ");
userInput = reader.nextInt();
// return the input to the caller of this method
return userInput;
}
/**
* @param args
*/
publicstaticvoid main(String[] args){
GradeConverter converter =newGradeConverter();
int input = converter.getNumberGrade();
String letterGrade = converter.convertGrade(input);
System.out.println("The letter grade for "+ input +" is "+ letter
Grade);
}
}
__MACOSX/week4_src/._GradeConverter.java
week4_src/Person.javaweek4_src/Person.javapackage edu.drexe
l.ct290;
import java.util.Scanner;
publicclassPerson{
privateString name;
privateint age;
privateString email;
publicString getName(){
return name;
}
publicvoid setName(String name){
this.name = name;
}
publicint getAge(){
return age;
}
publicvoid setAge(int age){
this.age = age;
}
publicString getEmail(){
return email;
}
publicvoid setEmail(String email){
this.email = email;
}
publicvoid getPersonData(){
Scanner reader =newScanner(System.in);
System.out.print("Enter the person's name: ");
name = reader.nextLine();
System.out.print("Enter the person's age: ");
age = reader.nextInt();
reader.nextLine();
System.out.print("Enter the person's email: ");
email = reader.nextLine();
}
publicString toString(){
return"Name: "+ name +"nAge: "+ age +"nemail: "+ email;
}
}
__MACOSX/week4_src/._Person.java
__MACOSX/._week4_src

More Related Content

Similar to week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx

Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfxlynettalampleyxc
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxVictorzH8Bondx
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdfadinathassociates
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
This file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfThis file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfdeepaksatrker
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfNicholasflqStewartl
 
this file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfthis file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfflashfashioncasualwe
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfaucmistry
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdffantoosh1
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdffantasiatheoutofthef
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfseoagam1
 
public class DoubleArraySeq implements Cloneable {    Priva.pdf
public class DoubleArraySeq implements Cloneable {     Priva.pdfpublic class DoubleArraySeq implements Cloneable {     Priva.pdf
public class DoubleArraySeq implements Cloneable {    Priva.pdfannaimobiles
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docxKomlin1
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfarpaqindia
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxSHIVA101531
 
lec6.ppt
lec6.pptlec6.ppt
lec6.pptcawarir
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfAugstore
 

Similar to week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx (20)

Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
This file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfThis file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdf
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdf
 
this file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfthis file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdf
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdf
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
22.ppt
22.ppt22.ppt
22.ppt
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdf
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
public class DoubleArraySeq implements Cloneable {    Priva.pdf
public class DoubleArraySeq implements Cloneable {     Priva.pdfpublic class DoubleArraySeq implements Cloneable {     Priva.pdf
public class DoubleArraySeq implements Cloneable {    Priva.pdf
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docx
 
lec6.ppt
lec6.pptlec6.ppt
lec6.ppt
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
 

More from alanfhall8953

With regards to this article, I agree and disagree on certain leve.docx
With regards to this article, I agree and disagree on certain leve.docxWith regards to this article, I agree and disagree on certain leve.docx
With regards to this article, I agree and disagree on certain leve.docxalanfhall8953
 
WIT Financial Accounting Test Ch.docx
WIT                   Financial Accounting Test                 Ch.docxWIT                   Financial Accounting Test                 Ch.docx
WIT Financial Accounting Test Ch.docxalanfhall8953
 
Windows Server Deployment ProposalOverviewEach student will .docx
Windows Server Deployment ProposalOverviewEach student will .docxWindows Server Deployment ProposalOverviewEach student will .docx
Windows Server Deployment ProposalOverviewEach student will .docxalanfhall8953
 
Wireshark Lab TCP v6.0 Supplement to Computer Networking.docx
Wireshark Lab TCP v6.0  Supplement to Computer Networking.docxWireshark Lab TCP v6.0  Supplement to Computer Networking.docx
Wireshark Lab TCP v6.0 Supplement to Computer Networking.docxalanfhall8953
 
Wireshark Lab IP v6.0Supplement to Computer Networking A Top-D.docx
Wireshark Lab IP v6.0Supplement to Computer Networking A Top-D.docxWireshark Lab IP v6.0Supplement to Computer Networking A Top-D.docx
Wireshark Lab IP v6.0Supplement to Computer Networking A Top-D.docxalanfhall8953
 
Wireshark Lab IP v6.0 Supplement to Computer Networking.docx
Wireshark Lab IP v6.0  Supplement to Computer Networking.docxWireshark Lab IP v6.0  Supplement to Computer Networking.docx
Wireshark Lab IP v6.0 Supplement to Computer Networking.docxalanfhall8953
 
Willowbrook SchoolBackgroundWillowbrook School is a small, pri.docx
Willowbrook SchoolBackgroundWillowbrook School is a small, pri.docxWillowbrook SchoolBackgroundWillowbrook School is a small, pri.docx
Willowbrook SchoolBackgroundWillowbrook School is a small, pri.docxalanfhall8953
 
Wind PowerUsed For Millennia Variations in alb.docx
Wind PowerUsed For Millennia Variations in alb.docxWind PowerUsed For Millennia Variations in alb.docx
Wind PowerUsed For Millennia Variations in alb.docxalanfhall8953
 
winter 2013 235 CREATE A CONTRACTInstructionsI will giv.docx
winter 2013 235 CREATE A CONTRACTInstructionsI will giv.docxwinter 2013 235 CREATE A CONTRACTInstructionsI will giv.docx
winter 2013 235 CREATE A CONTRACTInstructionsI will giv.docxalanfhall8953
 
WinEst As 1. Es2. Tassignment stInfo (Esti.docx
WinEst As 1. Es2. Tassignment stInfo (Esti.docxWinEst As 1. Es2. Tassignment stInfo (Esti.docx
WinEst As 1. Es2. Tassignment stInfo (Esti.docxalanfhall8953
 
Wiley Plus Brief Exercise 6 –Accounting 100Brief Exercise 6-1B.docx
Wiley Plus Brief Exercise 6 –Accounting 100Brief Exercise 6-1B.docxWiley Plus Brief Exercise 6 –Accounting 100Brief Exercise 6-1B.docx
Wiley Plus Brief Exercise 6 –Accounting 100Brief Exercise 6-1B.docxalanfhall8953
 
Winter 2011 • Morality in Education 35Workplace Bullying .docx
Winter 2011 • Morality in Education 35Workplace Bullying .docxWinter 2011 • Morality in Education 35Workplace Bullying .docx
Winter 2011 • Morality in Education 35Workplace Bullying .docxalanfhall8953
 
With the competitive advantage that Crocs’ supply chain holds, the.docx
With the competitive advantage that Crocs’ supply chain holds, the.docxWith the competitive advantage that Crocs’ supply chain holds, the.docx
With the competitive advantage that Crocs’ supply chain holds, the.docxalanfhall8953
 
Windows Server 2012 R2 Essentials Windows Server 2012.docx
Windows Server 2012 R2 Essentials  Windows Server 2012.docxWindows Server 2012 R2 Essentials  Windows Server 2012.docx
Windows Server 2012 R2 Essentials Windows Server 2012.docxalanfhall8953
 
Wind power resources on the eastern U.S. continental shelf are est.docx
Wind power resources on the eastern U.S. continental shelf are est.docxWind power resources on the eastern U.S. continental shelf are est.docx
Wind power resources on the eastern U.S. continental shelf are est.docxalanfhall8953
 
WilliamStearman_Java301build.xml Builds, tests, and ru.docx
WilliamStearman_Java301build.xml      Builds, tests, and ru.docxWilliamStearman_Java301build.xml      Builds, tests, and ru.docx
WilliamStearman_Java301build.xml Builds, tests, and ru.docxalanfhall8953
 
Wilco Corporation has the following account balances at December 3.docx
Wilco Corporation has the following account balances at December 3.docxWilco Corporation has the following account balances at December 3.docx
Wilco Corporation has the following account balances at December 3.docxalanfhall8953
 
Wilson Majee Technology Diffusion, S-Curve, and Innovation.docx
Wilson Majee Technology Diffusion, S-Curve, and Innovation.docxWilson Majee Technology Diffusion, S-Curve, and Innovation.docx
Wilson Majee Technology Diffusion, S-Curve, and Innovation.docxalanfhall8953
 
WinARM - Simulating Advanced RISC Machine Architecture .docx
WinARM - Simulating Advanced RISC Machine Architecture   .docxWinARM - Simulating Advanced RISC Machine Architecture   .docx
WinARM - Simulating Advanced RISC Machine Architecture .docxalanfhall8953
 
William PennWhat religion was William PennWilliam Pen was fr.docx
William PennWhat religion was William PennWilliam Pen was fr.docxWilliam PennWhat religion was William PennWilliam Pen was fr.docx
William PennWhat religion was William PennWilliam Pen was fr.docxalanfhall8953
 

More from alanfhall8953 (20)

With regards to this article, I agree and disagree on certain leve.docx
With regards to this article, I agree and disagree on certain leve.docxWith regards to this article, I agree and disagree on certain leve.docx
With regards to this article, I agree and disagree on certain leve.docx
 
WIT Financial Accounting Test Ch.docx
WIT                   Financial Accounting Test                 Ch.docxWIT                   Financial Accounting Test                 Ch.docx
WIT Financial Accounting Test Ch.docx
 
Windows Server Deployment ProposalOverviewEach student will .docx
Windows Server Deployment ProposalOverviewEach student will .docxWindows Server Deployment ProposalOverviewEach student will .docx
Windows Server Deployment ProposalOverviewEach student will .docx
 
Wireshark Lab TCP v6.0 Supplement to Computer Networking.docx
Wireshark Lab TCP v6.0  Supplement to Computer Networking.docxWireshark Lab TCP v6.0  Supplement to Computer Networking.docx
Wireshark Lab TCP v6.0 Supplement to Computer Networking.docx
 
Wireshark Lab IP v6.0Supplement to Computer Networking A Top-D.docx
Wireshark Lab IP v6.0Supplement to Computer Networking A Top-D.docxWireshark Lab IP v6.0Supplement to Computer Networking A Top-D.docx
Wireshark Lab IP v6.0Supplement to Computer Networking A Top-D.docx
 
Wireshark Lab IP v6.0 Supplement to Computer Networking.docx
Wireshark Lab IP v6.0  Supplement to Computer Networking.docxWireshark Lab IP v6.0  Supplement to Computer Networking.docx
Wireshark Lab IP v6.0 Supplement to Computer Networking.docx
 
Willowbrook SchoolBackgroundWillowbrook School is a small, pri.docx
Willowbrook SchoolBackgroundWillowbrook School is a small, pri.docxWillowbrook SchoolBackgroundWillowbrook School is a small, pri.docx
Willowbrook SchoolBackgroundWillowbrook School is a small, pri.docx
 
Wind PowerUsed For Millennia Variations in alb.docx
Wind PowerUsed For Millennia Variations in alb.docxWind PowerUsed For Millennia Variations in alb.docx
Wind PowerUsed For Millennia Variations in alb.docx
 
winter 2013 235 CREATE A CONTRACTInstructionsI will giv.docx
winter 2013 235 CREATE A CONTRACTInstructionsI will giv.docxwinter 2013 235 CREATE A CONTRACTInstructionsI will giv.docx
winter 2013 235 CREATE A CONTRACTInstructionsI will giv.docx
 
WinEst As 1. Es2. Tassignment stInfo (Esti.docx
WinEst As 1. Es2. Tassignment stInfo (Esti.docxWinEst As 1. Es2. Tassignment stInfo (Esti.docx
WinEst As 1. Es2. Tassignment stInfo (Esti.docx
 
Wiley Plus Brief Exercise 6 –Accounting 100Brief Exercise 6-1B.docx
Wiley Plus Brief Exercise 6 –Accounting 100Brief Exercise 6-1B.docxWiley Plus Brief Exercise 6 –Accounting 100Brief Exercise 6-1B.docx
Wiley Plus Brief Exercise 6 –Accounting 100Brief Exercise 6-1B.docx
 
Winter 2011 • Morality in Education 35Workplace Bullying .docx
Winter 2011 • Morality in Education 35Workplace Bullying .docxWinter 2011 • Morality in Education 35Workplace Bullying .docx
Winter 2011 • Morality in Education 35Workplace Bullying .docx
 
With the competitive advantage that Crocs’ supply chain holds, the.docx
With the competitive advantage that Crocs’ supply chain holds, the.docxWith the competitive advantage that Crocs’ supply chain holds, the.docx
With the competitive advantage that Crocs’ supply chain holds, the.docx
 
Windows Server 2012 R2 Essentials Windows Server 2012.docx
Windows Server 2012 R2 Essentials  Windows Server 2012.docxWindows Server 2012 R2 Essentials  Windows Server 2012.docx
Windows Server 2012 R2 Essentials Windows Server 2012.docx
 
Wind power resources on the eastern U.S. continental shelf are est.docx
Wind power resources on the eastern U.S. continental shelf are est.docxWind power resources on the eastern U.S. continental shelf are est.docx
Wind power resources on the eastern U.S. continental shelf are est.docx
 
WilliamStearman_Java301build.xml Builds, tests, and ru.docx
WilliamStearman_Java301build.xml      Builds, tests, and ru.docxWilliamStearman_Java301build.xml      Builds, tests, and ru.docx
WilliamStearman_Java301build.xml Builds, tests, and ru.docx
 
Wilco Corporation has the following account balances at December 3.docx
Wilco Corporation has the following account balances at December 3.docxWilco Corporation has the following account balances at December 3.docx
Wilco Corporation has the following account balances at December 3.docx
 
Wilson Majee Technology Diffusion, S-Curve, and Innovation.docx
Wilson Majee Technology Diffusion, S-Curve, and Innovation.docxWilson Majee Technology Diffusion, S-Curve, and Innovation.docx
Wilson Majee Technology Diffusion, S-Curve, and Innovation.docx
 
WinARM - Simulating Advanced RISC Machine Architecture .docx
WinARM - Simulating Advanced RISC Machine Architecture   .docxWinARM - Simulating Advanced RISC Machine Architecture   .docx
WinARM - Simulating Advanced RISC Machine Architecture .docx
 
William PennWhat religion was William PennWilliam Pen was fr.docx
William PennWhat religion was William PennWilliam Pen was fr.docxWilliam PennWhat religion was William PennWilliam Pen was fr.docx
William PennWhat religion was William PennWilliam Pen was fr.docx
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
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
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
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 🔝✔️✔️
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx

  • 1. week4_src/ArrayMethods.javaweek4_src/ArrayMethods.javapac kage edu.drexel.ct290; publicclassArrayMethods{ /** * Pass and array to a method that will search through it for a given value. * * @param elementToFind: This is the item we want to find i n the array. * @param stringArray: This is the array to search through. * @return Returns: The index of the element, or - 1 if not found. */ publicint findElement(String elementToFind,String[] stringArra y ){ int index =-1; for(int i=0; i<stringArray.length; i++){ if( elementToFind.equals(stringArray[i])){ // If the element is found, set index index = i; } } return index; } /** * Replace a value in an array. * * @param indexToReplace: The index where the new value s hould be written.
  • 2. * @param newValue: The new value. * @param stringArray: Change a value in this array. * @return True if the given index is valid */ publicboolean replace(int indexToReplace,String newValue,Stri ng[] stringArray ){ boolean replaced =false; // Use the if condition to make sure the given index is valid if( indexToReplace >0&& indexToReplace < stringArray.length ){ stringArray[indexToReplace]= newValue; replaced =true; } return replaced; } /** * Insert a value into the array. From the insertion point on, t he * data needs to be copied down one space to make room for t he new * element indices . * * @param index: The index where the new element should b e inserted * @param element: The element to insert in the array * @param array: The array to insert into * @param indicesUsed: the number of elements in the array already used * @return the array with the new value inserted */ publicString[] insert(int index,String element,String[] array,int i ndicesUsed){ // First, check that there is enough room in the array for
  • 3. // another element. The parameter indicesUsed indicates how // many elements of the array are already filled. String[] newArray = array; if( indicesUsed == array.length ){ newArray = makeBiggerArray(array); } // Now that we know there is enough room, move the // elements down one spot in the array until we get to the // insertion point. Make sure the element at the insertion // point gets moved too. int indexToMove = indicesUsed; while( indexToMove >= index ){ newArray[indexToMove+1]= newArray[indexToMove]; indexToMove--; } // Set the given index to the new element newArray[index]= element; // Return the new array return newArray; } /** * Since arrays are fixed size, if you run out of room, the * only options is to create a new bigger array, then copy * the old data over. * @param oldArray: The old data to copy into the new array * @return The new bigger array */ publicString[] makeBiggerArray(String[] oldArray){ // Make the new array twice the size of the old one. int newArraySize = oldArray.length *2; String[] newArray =newString[newArraySize];
  • 4. // Copy the old data over to the new array for(int i=0; i<oldArray.length; i++){ newArray[i]= oldArray[i]; } return newArray; } publicvoid printArray(String[] array ){ for(int i=0; i<array.length; i++){ System.out.println("Element "+ i +": "+ array[i]); } } publicstaticvoid main(String[] args){ String[] groceries =newString[5]; groceries[0]="bread"; groceries[1]="milk"; groceries[2]="cheese"; groceries[3]="steak"; groceries[4]="portobello mushrooms"; ArrayMethods arrayMethods =newArrayMethods(); arrayMethods.printArray(groceries); int cheese = arrayMethods.findElement("cheese", groceries); // You could use an if condition to make sure the result is not -1 System.out.println("nCheese is at index: "+ cheese +"n"); arrayMethods.replace(4,"lobster", groceries); arrayMethods.printArray(groceries); System.out.println("nInsert onion into the list.n");
  • 5. String[] withOnion = arrayMethods.insert(3,"onion",groceries,5 ); arrayMethods.printArray( withOnion ); // make a blank line so the output is easier to read System.out.println(""); String[] moreGroceries = arrayMethods.makeBiggerArray(groce ries); arrayMethods.printArray(moreGroceries); } } __MACOSX/week4_src/._ArrayMethods.java week4_src/Contacts.javaweek4_src/Contacts.javapackage edu.dr exel.ct290; import java.util.ArrayList; publicclassContacts{ // Collects can hold any type of object, but its best to tell // Java what type of object it will be. To do that put the // class name in angle brackets right after the collection type. // In this case we will have an ArrayList that holds objects of ty pe // Person (same as the Person class used in week 3). privateArrayList<Person> contacts =newArrayList<Person>(); publicvoid addContact(Person newPerson ){ // To add an element to an ArrayList simply call the add method .
  • 6. // With array list, you don't have to worry about the size. contacts.add(newPerson); } publicint find(Person person ){ // Find the index of a given object. // indexOf returns -1 if not found return contacts.indexOf(person); } publicvoid delete(Person person ){ // simply use remove to delete an element from the list // There is also a remove method that removes based on index contacts.remove(person); } publicvoid deleteAll(){ // ArrayList's clear method removes all elements from the list. contacts.clear(); } publicvoid printAll(){ // Use size() to get the number of elements in the list. for(int i=0; i<contacts.size(); i++){ Person contact = contacts.get(i); System.out.println("n"+ contact.toString()); } } } week4_src/FirstArray.javaweek4_src/FirstArray.javapackage ed u.drexel.ct290; publicclassFirstArray{
  • 7. publicstaticvoid main(String[] args){ // Create an array of five strings String[] groceries =newString[5]; // After creation, the array is empty, so lets fill it up: // Recall that array index go from 0 to size-1. In this case 0-4 // Using brackets with an index references a specific element. groceries[0]="bread"; groceries[1]="milk"; groceries[2]="cheese"; groceries[3]="steak"; groceries[4]="portobello mushrooms"; // Now print out each value in the array. For loops are ideal // for arrays since we know the exact number of iterations. // Here we start with element, 0, and keep incrementing i // as long as i is less than 5 for(int i=0; i<5; i++){ System.out.println("Element "+ i +": "+ groceries[i]); } // Array also have properties you can access with the . operator // Most notably the lenght of the array: System.out.println("Array size: "+ groceries.length); // Trying using groceries.length in the for loop above instead of // using the hard coded size. // Most array errors occur due to using an invalid index: // Uncomment the line below, then see what happens when you r un it: //System.out.println("More groceries: " + groceries[6]); } }
  • 8. __MACOSX/week4_src/._FirstArray.java week4_src/GradeBook.javaweek4_src/GradeBook.javapackage e du.drexel.ct290; import java.util.ArrayList; import java.util.Scanner; publicclassGradeBook{ privateString course; privateArrayList<Person> students =newArrayList<Person>(); privateArrayList<GradeBookEntry> entries =newArrayList<Gra deBookEntry>(); publicString getCourse(){ return course; } publicvoid setCourse(String course){ this.course = course; } publicvoid addStudent(Person student ){ students.add(student); } publicvoid addEntry(){ // Print out each students name and choose one System.out.println("Grade which student: "); for(int i=0; i<students.size(); i++){ System.out.println(i +" "+ students.get(i).getName()); }
  • 9. Scanner reader =newScanner(System.in); reader.nextInt(); reader.nextLine(); // TODO: get the assessment name and numeric grade GradeBookEntry entry =newGradeBookEntry(); // TODO: set the data in the new entry entries.add(entry); } publicvoid listGrades(){ // TODO: Print out all the grade entries in this gradbook } publicvoid displaySummary(){ // TODO: show a distribution of letter grades in this class. // See the barchart example in Java HTP 7.4 } publicstaticvoid main(String[] args){ Person person1 =newPerson(); person1.setName("John"); Person person2 =newPerson(); person1.setName("Lisa"); Person person3 =newPerson(); person1.setName("Bill"); Person person4 =newPerson(); person1.setName("Sarah"); GradeBook book =newGradeBook();
  • 10. book.setCourse("CT-290"); // TODO: add some gradbook entries // TODO: list the entries and disply the bar chart } } week4_src/GradeBookEntry.javaweek4_src/GradeBookEntry.jav apackage edu.drexel.ct290; import java.util.Scanner; publicclassGradeBookEntry{ privatePerson student; privateint numericGrade; privateString assessmentName; // The next six methods are just getters and setters // for the member variables of this class. publicPerson getStudent(){ return student; } publicvoid setStudent(Person student){ this.student = student; } publicint getNumericGrade(){ return numericGrade; } publicvoid setNumericGrade(int numericGrade){
  • 11. this.numericGrade = numericGrade; } publicString getAssessmentName(){ return assessmentName; } publicvoid setAssessmentName(String assessmentName){ this.assessmentName = assessmentName; } publicString getLetterGrade(){ GradeConverter converter =newGradeConverter(); return converter.convertGrade(numericGrade); } publicvoid printEntry(){ System.out.println(student.toString()); // instantiate a GradeConverter to get the letter grade. GradeConverter converter =newGradeConverter(); System.out.println("Scored "+ numericGrade ); System.out.println("Which is a: "+ converter.convertGrade(num ericGrade)); System.out.println("For assessment: "+ assessmentName); } publicstaticvoid main(String[] args){ // instantiate the GradeBookEntry, just like we have // done with the Scanner class. GradeBookEntry gradeBookEntry =newGradeBookEntry(); Scanner reader =newScanner(System.in); // instantiate a new person object Person student =newPerson(); student.getPersonData();
  • 12. gradeBookEntry.setStudent(student); System.out.print("Enter this students numeric grade: "); int grade = reader.nextInt(); gradeBookEntry.setNumericGrade(grade); gradeBookEntry.setAssessmentName("test1"); gradeBookEntry.printEntry(); } } __MACOSX/week4_src/._GradeBookEntry.java week4_src/GradeConverter.javaweek4_src/GradeConverter.java package edu.drexel.ct290; import java.util.Scanner; publicclassGradeConverter{ publicString convertGrade(int numberGrade ){ if( numberGrade >=90){ return"A"; } elseif( numberGrade >=80){ return"B"; } elseif( numberGrade >=70){ return"C"; } elseif( numberGrade >=60){
  • 13. return"D"; } else{ return"F"; } } /** * This method gets input from the user * @return a grade in number format from 0-100 */ publicint getNumberGrade(){ // declare and intialize variables int userInput=0; Scanner reader =newScanner(System.in); // get the user input System.out.print("Enter the number grade: "); userInput = reader.nextInt(); // return the input to the caller of this method return userInput; } /** * @param args */ publicstaticvoid main(String[] args){ GradeConverter converter =newGradeConverter(); int input = converter.getNumberGrade(); String letterGrade = converter.convertGrade(input); System.out.println("The letter grade for "+ input +" is "+ letter Grade); } }
  • 14. __MACOSX/week4_src/._GradeConverter.java week4_src/Person.javaweek4_src/Person.javapackage edu.drexe l.ct290; import java.util.Scanner; publicclassPerson{ privateString name; privateint age; privateString email; publicString getName(){ return name; } publicvoid setName(String name){ this.name = name; } publicint getAge(){ return age; } publicvoid setAge(int age){ this.age = age; } publicString getEmail(){ return email; } publicvoid setEmail(String email){
  • 15. this.email = email; } publicvoid getPersonData(){ Scanner reader =newScanner(System.in); System.out.print("Enter the person's name: "); name = reader.nextLine(); System.out.print("Enter the person's age: "); age = reader.nextInt(); reader.nextLine(); System.out.print("Enter the person's email: "); email = reader.nextLine(); } publicString toString(){ return"Name: "+ name +"nAge: "+ age +"nemail: "+ email; } } __MACOSX/week4_src/._Person.java __MACOSX/._week4_src