Thursday, August 11, 2011

Assignment 10


Exercise 4
a)
import java.util.Scanner;
public class Division2{
   public static void main(String[] args){

      Scanner stdIn = new Scanner (System.in);
      boolean zero = true;
      double n;
      int d = 0;
       
      System.out.print("\nEnter numerator: ");
      n = stdIn.nextDouble();
       
      System.out.print("Enter divisor: ");
      d = stdIn.nextInt();      
       
      if (d ==0){
         do{
            System.out.print("Enter divisor: ");
            d = stdIn.nextInt();
            zero = false;
            }
         while(d == 0);
        }  
       
        System.out.println(n / d);
    }
}

b)
import java.util.Scanner;
import java.util.*;
public class Division2b{
    public static void main(String[] args){
        Scanner stdIn = new Scanner (System.in);

        boolean ok = true;
        int n;
        int d = 0;
        int result;  
       
        System.out.print("Enter numerator: ");
        n = stdIn.nextInt();
        System.out.print("Enter divisor: ");
        d = stdIn.nextInt();  
       
        do{
            try{
                result = n/d;
                System.out.println(result);
                ok = true;
            }
            catch (ArithmeticException mistake){  
                System.out.print("Invalid Entry. Enter divisor: ");
                d = stdIn.nextInt();
                ok = false;
            }
        }
       while(ok == false);
    }
}



Exercise 5)
import java.util.*;
import java.io.*;

public class WordsInFile{
   public static void main(String[] args){

   Scanner stdIn = new Scanner(System.in);
   Scanner fileIn;
   int numWords = 0;

   try{
      //Added Code
      System.out.print("Enter full pathname of file: ");
      fileIn = new Scanner(new FileReader(stdIn.nextLine()));


      while (fileIn.hasNextLine()){
         String file = fileIn.next();
         numWords++;
         }


      System.out.println("Number of words = " + numWords);
      }

   catch(FileNotFoundException e){
      System.out.println("Invalid Filename");
      }
   catch(Exception e){
      System.out.println("Error reading from the file.");
      }
   }
}

Sunday, August 7, 2011

Assignment 9

Problem 11
i = 5
factorial = 5

Problem 12
import java.util.Scanner;

public class Test{
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        String entry;

        for (entry = ""; !(entry.equals("q"));){
            System.out.println("Enter 'q' to quit: ");
            entry = stdIn.nextLine();
        }
    }
}

Problem 8
1. creates an infinite loop
2. change doIt(); to super.doIt();

Problem 12
structural and member beam, I
building and floor,C
company and fixed assets, C
employee and salesperson, I
forest and tree, C
bird and robin, I
class and method, C
neurosis and paranoia, I

Problem 3
sparky = bark, bark  
lassie = Animal@62f72617

Animals extends to the Dog class.
Bark is pulled from the dog class.
Lassie is pulled straight from Animal, which returns the memory location.

Problem 8
Dog lassie = new Dog("lassie");
Cat fluffy = new Cat("fluffy");

Monday, August 1, 2011

Assignment 8

 #6

System.arraycopy(allSalaries, 2, workerSalaries, 0, 5);



 #7

list = temp; should be changed to
System.arraycopy(temp, 0, list, 0, 3);

Wednesday, July 27, 2011

Assignment 7 # 10

PennyJar.getAllPennies() is needed in PennyJarDriver.java
PennyJar may be omitted in the PennyJar Class

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();

}
}

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;
}
}

Friday, July 15, 2011

Assignment 4 - #7

songIndex = songs.indexOf(songNum);
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;
  }
}

Tuesday, July 12, 2011

Answer to #3

if (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);

Saturday, April 23, 2011

IT461 Reflection

Reflection

I learned an enormous amount of information in this class. I've been making small websites for a number of years now, and I've always wondered how websites could do all the things it does today. I remember the days when “frames” were the new deal, and if your website had them, you're at the top. I've always loved programming websites. But with all the programming languages today, I've been overwhelmed so much to the point where programming websites didn't look so appealing to me – until this semester. Although IT461 was only an elective class that I took because it was the only one available, I don't regret it at all. Now that I've taken the time to learn php and ASP.net, I do think this is something that I would want to do in the future. The best thing is I learned it at my own pace, since its an online course. I learned HTML 10 years ago at my own pace as well, so its only fitting, and maybe that’s the reason why I enjoyed this class.

I learned that programming websites today isn't as hard as I thought. But I also do know that not everyone can do program websites. You may be a good programmer and debugger, but today's websites come with a lot of ingenuity and design. The artistry and inventiveness of today's websites are apparent through websites like WeChooseTheMoon.org. Websites are putting so much information onto one page that you must be imaginative to design and mesh everything on one page, in a way that isn't clashing or rude to the eyes. ESPN.COM has evolved into a website that is always always changing. Because it covers tons of different sports from around the world, it is always getting updated – every minute of the day. I can't even begin to imagine the coding process it takes to develop something of that magnitude.

I feel like I know where to begin if I wanted to design web applications – but I don't even consider myself remotely competent. I do wish to gain more experience in this field but with this only being a secondary thing to me, I plan to do it slow. It has been a good class, and I will recommend it to others who are interested in becoming web application developers.