PennyJar.getAllPennies() is needed in PennyJarDriver.java
PennyJar may be omitted in the PennyJar Class
Wednesday, July 27, 2011
Assignment 7 # 6
public class Test
{
private int x;
private static int y;
public void doIt()
{
x = 1;
y = 2;
}
public void tryIt() //cannot be static
{
x = 3; //x is in a static method - cannot be referenced
y = 4;
}
public static void main(String[] args)
{
doIt(); //object instance must be created
tryIt() //object instance must be created
Test t = new Test();
t.doIt();
Test.tryIt(); //must use t.tryIt();
}
}
{
private int x;
private static int y;
public void doIt()
{
x = 1;
y = 2;
}
public void tryIt() //cannot be static
{
x = 3; //x is in a static method - cannot be referenced
y = 4;
}
public static void main(String[] args)
{
doIt(); //object instance must be created
tryIt() //object instance must be created
Test t = new Test();
t.doIt();
Test.tryIt(); //must use t.tryIt();
}
}
Assignment 6
Ch7, #4:
public void swapHardDrive (Computer otherComputer)
{
String temp;
temp = otherComputer.hardDrive;
otherComputer.hardDrive = this.hardDrive;
this.hardDrive = temp;
}
Ch7, #12
10
20
30
60
50
Ch8, #5:
public boolean copyTo(Car5 newCar)
{
if(this.make.isEmpty()||this.year.isEmpty()||this.color.isEmpty())
{
return false;
}
else
{
newCar.make = this.make;
newCar.year = this.year;
newCar.color = this.color;
return true;
}
}
public void swapHardDrive (Computer otherComputer)
{
String temp;
temp = otherComputer.hardDrive;
otherComputer.hardDrive = this.hardDrive;
this.hardDrive = temp;
}
Ch7, #12
10
20
30
60
50
Ch8, #5:
public boolean copyTo(Car5 newCar)
{
if(this.make.isEmpty()||this.year.isEmpty()||this.color.isEmpty())
{
return false;
}
else
{
newCar.make = this.make;
newCar.year = this.year;
newCar.color = this.color;
return true;
}
}
Friday, July 15, 2011
Assignment 4 - #7
songIndex = songs.indexOf(songNum);
eolIndex = songs.indexOf('\n', songIndex);
song = songs.substring(songIndex, eolIndex);
eolIndex = songs.indexOf('\n', songIndex);
song = songs.substring(songIndex, eolIndex);
Assignment 4 - #6
for( int i=0; i < songs.length(); i++){
foundIndex = songs.indexOf(searchText, i);
if(foundIndex > 0)
{
count = count + 1;
i = foundIndex + 1;
foundIndex = 0;
}
}
foundIndex = songs.indexOf(searchText, i);
if(foundIndex > 0)
{
count = count + 1;
i = foundIndex + 1;
foundIndex = 0;
}
}
Tuesday, July 12, 2011
Answer to #3
if (count == 5){
System.out.println("Sum = " + sum);
System.out.println("Product = " + product);}
} while (count < 5);
System.out.println("Sum = " + sum);
System.out.println("Product = " + product);}
} while (count < 5);
Answer to #5
product = 1;
For (i = 2; i <=num; i+=2;){
product = product * i;}
System.out.println ("Product is " + product);
For (i = 2; i <=num; i+=2;){
product = product * i;}
System.out.println ("Product is " + product);
Subscribe to:
Posts (Atom)