Sunday, July 31, 2011

Assignment 8 Exercise 6 & 7

/************************************
*T'Nora Green
*Assignment 8, Exercise 6
*************************************/
System.arraycopy(allSalaries, 2, workerSalaries, 0, 5);


/************************************
*T'Nora Green
*Assignment 
8, Exercise 7
*************************************/
a: Homer Flanders Apu
b: System.arraycopy(temp,0,list,0,list.length);

Tuesday, July 26, 2011

Assignment 7 Exercise 6 & 10

/************************************
*T'Nora Green
*Assignment 7, Exercise 6

*************************************/

public class Test
{
  private int x;
  private static int y;
  public void doIt()
  {
    x = 1;
    y = 2;
  }
  public static void tryIt()
  {
    x = 3;                               
    y = 4;
  }
  public static void main(String[] args)
  {
    doIt();                             
    tryIt();
    Test t = new Test();
    t.doIt();
    Test.doIt();                         
    Test.tryIt();
  }
} // end Test class

Reasons for errors from the debugger:
non-static variable x cannot be referenced from the static tryIt method
non-static method doIt() cannot be referenced from the static main method
 non-static method doIt cannot be referenced  instance method using a dot prefix.


/************************************
*T'Nora Green
*Assignment 7, Exercise 10
*************************************/
Yes, its legal to omit the PennyJar dot prefixes in the PennyJar class. In the PennyJarDriver class PennyJar.getAllPennies() is needed and cannot be omitted.

Saturday, July 23, 2011

Assignment 6 Exercise 4, 12 & 5

/************************************
*T'Nora Green
*Assignment 6, Exercise 4
*************************************/


public void swapHardDrive(Computer otherComputer)

{

  String temp; //temporary storage location

temp = otherComputer.hardDrive;
otherComputer.hardDrive = this.hardDrive;
this.hardDrive = temp;

}//end swapHardDrive.





/************************************
*T'Nora Green
*Assignment 6, Exercise 12
*************************************/


The two classes gave the output of:


10
20
30
60
50





/************************************
*T'Nora Green
*Assignment 6, Exercise 5
*************************************/


 public boolean copyTo(Car5 newCar)
 {
 
   String truth;

  if (newCar.make == this.make && newCar.year == this.year && newCar.color == this.color)
     {
      return false;
      }//end if statement
 
else{

      newCar = this;
      return true;
  

     }//end else statement


     }//end of boolean

Tuesday, July 12, 2011

Assignment 4 Exercise 7

/************************************
*T'Nora Green
*Assignment 4, Exercise 7
*************************************/

import java.util.Scanner;

public class ExtractLine
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
String songs =
"1. Bow Wow - Fresh Azimiz\n" +
"2. Weezer - Beverly Hills\n" +
"3. Dave Matthews Band - Crash Into me\n" +
"4. Sheryl Crow - Leaving Las Vegas\n";

String songNum; //song number that is searched for
int songIndex; //position of where song number is found
int eolIndex; //position of end of line character
String song; //the specified line

System.out.print("Enter song number: ");
songNum = stdIn.nextLine();

songIndex = songs.indexOf(songNum);
eolIndex = songs.indexOf("\n", songIndex);
song = songs.substring(songIndex, eolIndex);

System.out.println(song);
}//end main
}//end class ExtractLine

Assignment 4 Exercise 6

/************************************
*T'Nora Green
*Assignment 4, Exercise 6
*************************************/
import java.util.Scanner;

public class CountSubstringOccurrences
{
public static void main(String[] args)
{
Scanner stdIn= new Scanner(System.in);
String songs =
" 1. Green Day - American Idiot\n" +
" 2. Jesus Jones - Right Here, Right Now\n" +
" 3. Indigo Girls - Closer to Fine\n" +
" 4. Peter Tosh - Equal Rights\n";

String searchText;  // text that is searched for
int foundIndex=0; // position of where text is found
int count = 0; // number of occurences of search text

System.out.print("Enter search text: ");
searchText= stdIn.nextLine();

while(foundIndex <= songs.length())
{
foundIndex += songs.indexOf(searchText, foundIndex);
count++;
} //end loop

System.out.println("Number of occurences of \"" + searchText + "\": " + count);

} //end main
} //end class CountSubstringOccurrences

Monday, July 11, 2011

Assignment 3 Exercise 5

/************************************
*T'Nora Green
*Assignment 3, Exercise 5
*************************************/
import java.util.Scanner;

public class ProductEvenInts
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
int i, num, product;

System.out.print("Enter a positive even number: ");
num = stdIn.nextInt();

product=1;
i=2;


do
{
product *= i;
i+=2;
}


while (i <= num);


System.out.println("Product = " + product);
}//end main
}//end class ProductEvenInts

Sunday, July 10, 2011

Assignment 3 Excercise 3

/************************************
*T'Nora Green
*Assignment 3, Exercise 3
*************************************/
public class Numbers

{
public static void main (String[] args)
{
int count = 0;
int sum = 0;
int product = 1;
do
{
count++;
sum += count;
product *= count;
if (count == 5)
{
System.out.println("Sum = " + sum);
System.out.println("Product = " + product);
}
}
while (count < 5);

} //end main
} //end class Numbers

// solutions:
//must add a class heading
//change the placement of the opening and closing braces to inclose class and main method appropriately.
// change int product to 1
//add opening an closing braces around the if statement
//add semicolon to the end of the while statement

Wednesday, July 6, 2011

A{KA}cademics First

Please excuse my blog while it is reconstructed and edited for the collegiate arena.

Thanks! : )

Buckle up

Welcome to my blog! From here we will be flying first class, and at the highest altitude to ensure a smooth ride. Buckle up and enjoy the fun, especially the view during landing, from your window seat of course!