Wednesday, August 10, 2011

Assignment 10 Ch 15 number 5

5.
fileIn = new Scanner( new FileReader(stdIn.nextLine()));
while(filein.hastNext()
{
numwords++;
}

Assignment 10.Problem 4

Part A.
import java.util.Scanner;
public class JavaAp5 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner stdIn= new Scanner(System.in);
double n;
int d;
System.out.print("Enter Numerator:");
n=stdIn.nextDouble();
System.out.print("Enter divsor:");
d=stdIn.nextInt();
if (d==0)
{
System.out.print("please enter a value that is not zero");
d=stdIn.nextInt();
}
System.out.println(n/d);

Part B.
public static void main(String[] args) {
Scanner stdIn= new Scanner(System.in);
double n;
int d;
System.out.print("Enter Numerator:");
n=stdIn.nextDouble();
System.out.print("Enter divsor:");
d=stdIn.nextInt();
while(n!=0 && d!=0)
{
try
{
System.out.print("Please enter a numerator");
n=stdIn.nextDouble();
System.out.print("Please enter a denominator");
d=stdIn.nextInt();
}
catch (NumberFormatException e)
{
System.out.print("That was not a correct number");
}
}
System.out.println(n/d);
}

Friday, August 5, 2011

Chapter 13: Assignment 9

3.
Sparky= bark, bark lassie=animal

Sparky is generating a bark bark because you extended out the Animal class to Dog. and it returns a string of bark bark.

lassie is generating animal because thats what her class is calling.

8.
New Dog Lassie= animals[0]
New Cat fluffy= animals[1]

Assignment 9 Chapter 12

#8.
A. The problem will be that this method will not inherit the correct variables when another method calls it.
B. You should fix the problem by overriding that method with a .super extension.

#12.
1. Composition.
2.Composition.
3.inheritance
4. composition
5.composition.
6. inheritance
7.composition.
8.inheritance.

Chapter 11 #11-12

11. int w, x, y =z;
12. The expression Evaluates out to 'M'.

Friday, July 29, 2011

Assignment 8 #1,

Problem 6:
System.arraycopy(allSalaries,1,workerSalaries,0,7);

Problem 7:
a. It prints homer,Flanders,apu
b. change the method type to String [] and add return list;

Wednesday, July 27, 2011