PRG421 Java Programming II

Need Help in PRG/421 Java Assignments?
We can help you if you are having difficulty with your PRG421 Assignment. Just email your assignments at support@assignmentcache.com.
We provide help for students all over the world.

Items 1 to 10 of 25 total

per page
Page:
  1. 1
  2. 2
  3. 3

Grid  List 

Set Ascending Direction
  1. PRG 421 Week 1 Individual Analyze Assignment Analyzing a Java Program Containing Abstract and Derived Classes

    PRG 421 Week 1 Individual Analyze Assignment Analyzing a Java Program Containing Abstract and Derived Classes

    Regular Price: $6.00

    Special Price: $4.00

    PRG 421 Week 1 Individual Analyze Assignment Analyzing a Java Program Containing Abstract and Derived Classes


    "Analyzing a Java™ Program Containing Abstract and Derived Classes"
    The purpose of creating an abstract class is to model an abstract situation.
    Example:
    You work for a company that has different types of customers: domestic, international, business partners, individuals, and so on. It well may be useful for you to "abstract out" all the information that is common to all of your customers, such as name, customer number, order history, etc., but also keep track of the information that is specific to different classes of customer. For example, you may want to keep track of additional information for international customers so that you can handle exchange rates and customs-related activities, or you may want to keep track of additional tax-, company-, and department-related information for business customers.
    Modeling all these customers as one abstract class ("Customer") from which many specialized customer classes derive or inherit ("International Customer," "Business Customer," etc.) will allow you to define all of that information your customers have in common and put it in the "Customer" class, and when you derive your specialized customer classes from the abstract Customer class you will be able to reuse all of those abstract data/methods.This approach reduces the coding you have to do which, in turn, reduces the probability of errors you will make. It also allows you, as a programmer, to reduce the cost of producing and maintaining the program.
    In this assignment, you will analyze Java™ code that declares one abstract class and derives three concrete classes from that one abstract class. You will read through the code and predict the output of the program.
    Read through the linked Java™ code carefully.
    Predict the result of running the Java™ code. Write your prediction into a Microsoft® Word document, focusing specifically on what text you think will appear on the console after running the Java™ code.
    In the same Word document, answer the following question:
    Why would a programmer choose to define a method in an abstract class, such as the Animal constructor method or the getName() method in the linked code example, as opposed to defining a method as abstract, such as the makeSound() method in the linked example?


    Supporting Material: Week One Analyze Assignment Text File
    /**********************************************************************
    * Program: PRG/421 Week 1 Analyze Assignment
    * Purpose: Analyze the coding for an abstract class
    * and two derived classes, including overriding methods
    * Programmer: Iam A. Student
    * Class: PRG/421r13, Java Programming II
    * Instructor:
    * Creation Date: December 13, 2017
    *
    * Comments:
    * Notice that in the abstract Animal class shown here, one method is
    * concrete (the one that returns an animal's name) because all animals can
    * be presumed to have a name. But one method, makeSound(), is declared as
    * abstract, because each concrete animal must define/override the makeSound() method
    * for itself--there is no generic sound that all animals make.
    **********************************************************************/


    package mytest;


    // Animal is an abstract class because "animal" is conceptual
    // for our purposes. We can't declare an instance of the Animal class,
    // but we will be able to declare an instance of any concrete class
    // that derives from the Animal class.
    abstract class Animal {
    // All animals have a name, so store that info here in the superclass.
    // And make it private so that other programmers have to use the
    // getter method to access the name of an animal.


    private final String animalName;
    // One-argument constructor requires a name.
    public Animal(String aName) {
    animalName = aName;
    }


    // Return the name of the animal when requested to do so via this
    // getter method, getName().
    public String getName() {
    return animalName;
    }


    // Declare the makeSound() method abstract, as we have no way of knowing
    // what sound a generic animal would make (in other words, this
    // method MUST be defined differently for each type of animal,
    // so we will not define it here--we will just declare a placeholder
    // method in the animal superclass so that every class that derives from
    // this superclass will need to provide an override method
    // for makeSound()).
    public abstract String makeSound();
    };


    // Create a concrete subclass named "Dog" that inherits from Animal.
    // Because Dog is a concrete class, we can instantiate it.
    class Dog extends Animal {
    // This constructor passes the name of the dog to
    // the Animal superclass to deal with.
    public Dog(String nameOfDog) {
    super(nameOfDog);
    }


    // This method is Dog-specific.
    @Override
    public String makeSound() {
    return ("Woof");
    }
    }


    // Create a concrete subclass named "Cat" that inherits from Animal.
    // Because Cat is a concrete class, we can instantiate it.
    class Cat extends Animal {
    // This constructor passes the name of the cat on to the Animal
    // superclass to deal with.
    public Cat(String nameOfCat) {
    super(nameOfCat);
    }


    // This method is Cat-specific.
    @Override
    public String makeSound() {
    return ("Meow");
    }
    }


    class Bird extends Animal {
    // This constructor passes the name of the bird on to the Animal
    // superclass to deal with.
    public Bird (String nameOfBird) {
    super(nameOfBird);
    }


    // This method is Bird-specific.
    @Override
    public String makeSound() {
    return ("Squawk");
    }
    }


    public class MyTest {
    public static void main(String[] args) {
    // Create an instance of the Dog class, passing it the name "Spot."
    // The variable aDog that we create is of type Animal.
    Animal aDog = new Dog("Spot");
    // Create an instance of the Cat class, passing it the name "Fluffy."
    // The variable aCat that we create is of type Animal.
    Animal aCat = new Cat("Fluffy");
    // Create an instance of (instantiate) the Bird class.
    Animal aBird = new Bird("Tweety");
    //Exercise two different methods of the aDog instance:
    // 1) getName() (which was defined in the abstract Animal class)
    // 2) makeSound() (which was defined in the concrete Dog class)
    System.out.println("The dog named " + aDog.getName() + " will make this sound: " + aDog.makeSound());
    //Exercise two different methods of the aCat instance:
    // 1) getName() (which was defined in the abstract Animal class)
    // 2) makeSound() (which was defined in the concrete Cat class)
    System.out.println("The cat named " + aCat.getName() + " will make this sound: " + aCat.makeSound());
    System.out.println("The bird named " + aBird.getName() + " will make this sound: " + aBird.makeSound());
    }
    }

    Learn More
  2. PRG421 Week 1 Individual Coding Assignment Object-Oriented Programming Concepts

    PRG421 Week 1 Individual Coding Assignment Object-Oriented Programming Concepts

    Regular Price: $10.00

    Special Price: $7.00

    PRG421 Week 1 Individual Coding Assignment Object-Oriented Programming Concepts


    For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following:


    An abstract Bicycle class that contains private data relevant to all types of bicycles (cadence, speed, and gear) in addition to one new static variable: bicycleCount. The private data must be made visible via public getter and setter methods; the static variable must be set/manipulated in the Bicycle constructor and made visible via a public getter method.
    Two concrete classes named MountainBike and RoadBike, both of which derive from the abstract Bicycle class and both of which add their own class-specific data and getter/setter methods.


    Read through the "Lesson: Object-Oriented Programming Concepts" on The Java™ Tutorials website.
    Download the linked Bicycle class, or cut-and-paste it at the top of a new Java™ project named BicycleDemo.
    Download the linked BicycleDemo class, or cut-and-paste it beneath the Bicycle class in the BicycleDemo.java file.
    Optionally, review this week's Individual "Week One Analyze Assignment," to refresh your understanding of how to code derived classes.


    Adapt the Bicycle class by cutting and pasting the class into the NetBeans editor and completing the following:
    Change the Bicycle class to be an abstract class.
    Add a private variable of type integer named bicycleCount, and initialize this variable to 0.
    Change the Bicycle constructor to add 1 to the bicycleCount each time a new object of type Bicycle is created.
    Add a public getter method to return the current value of bicycleCount.
    Derive two classes from Bicycle: MountainBike and RoadBike. To the MountainBike class, add the private variables tireTread (String) and mountainRating (int). To the RoadBike class, add the private variable maximumMPH (int).
    Using the NetBeans editor, adapt the BicycleDemo class as follows:
    Create two instances each of MountainBike and RoadBike.
    Display the value of bicycleCount on the console.
    Comment each line of code you add to explain what you added and why. Be sure to include a header comment that includes the name of the program, your name, PRG/421, and the date.
    Rename your JAVA file to have a .txt file extension.
    Submit your TXT file to the Assignment Files tab.


    package bicycledemo;


    class Bicycle {
    int cadence = 0;
    int speed = 0;
    int gear = 1;


    void changeCadence(int newValue) {
    cadence = newValue;
    }


    void changeGear(int newValue) {
    gear = newValue;
    }


    void speedUp(int increment) {
    speed = speed + increment;  
    }


    void applyBrakes(int decrement) {
    speed = speed - decrement;
    }


    void printStates() {
    System.out.println("cadence:" +
    cadence + " speed:" +
    speed + " gear:" + gear);
    }
    }
    class BicycleDemo {
    public static void main(String[] args) {


    // Create two different
    // Bicycle objects
    Bicycle bike1 = new Bicycle();
    Bicycle bike2 = new Bicycle();


    // Invoke methods on
    // those objects
    bike1.changeCadence(50);
    bike1.speedUp(10);
    bike1.changeGear(2);
    bike1.printStates();


    bike2.changeCadence(50);
    bike2.speedUp(10);
    bike2.changeGear(2);
    bike2.changeCadence(40);
    bike2.speedUp(10);
    bike2.changeGear(3);
    bike2.printStates();
    }
    }

    Learn More
  3. PRG 421 Week 2 Individual Analyze Assignment Demonstrate the Coding to Produce Output to a File

    PRG 421 Week 2 Individual Analyze Assignment Demonstrate the Coding to Produce Output to a File

    Regular Price: $6.00

    Special Price: $4.00

    PRG 421 Week 2 Individual Analyze Assignment Demonstrate the Coding to Produce Output to a File


    "Demonstrate the Coding to Produce Output to a File" text file
    For this assignment, you will analyze Java™ that presents instructional text on the console, accepts user input, and then creates a file based on that user input.
    Read the linked Java™ code carefully.
    Then, answer the following questions in a Microsoft® Word file:
    As you run the program in NetBeans the first time, at the prompt (the program will pause for input) type abc Return def Return ghi Ctrl+Shift+Del. What is the result?
    As you run the program in NetBeans the second time, at the prompt (the program will pause for input) type 123 Ctrl+Shift +Del. What is the result?
    What happens if the file Data.txt already exists when you run the program?
    What happens if the file Data.txt does not already exist when you run the program?


    Submit your Word file to the Assignment Files tab.


    /**********************************************************************
    *   Program:   FileOut 
    *    Purpose:    Demonstrate the coding to produce output to a file.  
    *   Programmer:   I am student         
    *   Class:       PRG/421r13, Java Programming II         
    *   Instructor:             
    *   Creation Date:   01/03/2018 
    *
    ***********************************************************************/
    package fileout;
    import java.io.*;


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


    InputStream istream;
    OutputStream ostream=null;
       // FileOutputStream creates an OutputStream that you can use to write bytes to a file.
    int c;                     // character stream 
    final int EOF = -1;                 // EOF indicator
    istream = System.in;


     
    // If the Data.txt file already exists, present its contents on the console.
    String fileName = "Data.txt";         // name of the file to open.
    String line = null;               // will reference one line at a time


    try {
    FileReader fileReader =        // FileReader reads text file
    new FileReader(fileName);         // reads in data from the file


    // always wrap FileReader in BufferedReader (to verify)
    BufferedReader bufferedReader =
    new BufferedReader(fileReader);


    System.out.println("Here are the contents of the current file named " + fileName + ":\n");
    while((line = bufferedReader.readLine()) != null) {
    System.out.println(line);        // verify / display what is read in by the program
    }  
    bufferedReader.close();         // close file


    }
    catch(FileNotFoundException ex) {       // coding to verify file can be opened
    System.out.println(           // if not open, error message to display
    "Unable to open file '" +
    fileName + "'");
    }
    catch(IOException ex) {           // exception, when there is an error in reading
    System.out.println(
    "Error reading file '"
    + fileName + "'");
    }


    // Now, let's construct a new file containing user input.
    System.out.println("\nType characters to write to file. After you finish, press Ctrl+Shift+Del to end.");
    File outFile = new File("Data.txt");    // create a new file


    try {                     // try block for EOF indicator
    ostream = new FileOutputStream(outFile);
    while ((c = istream.read()) != EOF)     // look for end of file in istream
    ostream.write(c);
    } catch (IOException e) {
    System.out.println("Error: " + e.getMessage());
    } finally {
    try {                     // try block for file error ñ file did not close


    istream.close();             // close input and output
    ostream.close();
    } catch (IOException e) {
    System.out.println("File did not close");
    }
    }
    }
    }

    Learn More
  4. PRG 421 Week 3 Individual Analyze Assignment Java Code That Sorts Extracts Data and Saves It To a Collection

    PRG 421 Week 3 Individual Analyze Assignment Java Code That Sorts Extracts Data and Saves It To a Collection

    Regular Price: $6.00

    Special Price: $4.00

    PRG 421 Week 3 Individual Analyze Assignment Java Code That Sorts Extracts Data and Saves It To a Collection


    "Java Code That Sorts, Extracts Data and Saves It To a Collection" text file
    For this assignment, you will analyze code that uses a file input stream and a file output stream.
    Read through the linked Java™ code.
    In a Microsoft® Word document, answer the following questions:
    Could this program be run as is? If not, what is it lacking?
    Does this program modify the contents of an input stream? In what way?
    What are the results of running this code?
    Submit your completed Word document to the Assignment Files tab.
    Here is the code to answer the questions with:


    // import the needed classes
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;



    public class Datasort {


    public static void main (String [] args) throws IOException {


    File fin = new File("e:\\input.txt");   // input file on e: drive (with data)  
    File fout = new File("e:\\sorted.txt");   // create an out file on e: drive


    // Java FileInputStream class obtains input bytes from a file
    FileInputStream fis = new FileInputStream(fin); 
    FileOutputStream fos = new FileOutputStream(fout);


    // buffering characters so as to provide for the efficient reading of characters, arrays, and lines
    BufferedReader in = new BufferedReader(new InputStreamReader(fis));
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos));


    // declare an array in-line, ready for the sort


    String aLine;
    ArrayList<String> al = new ArrayList<String> ();


    int i = 0;
    while ((aLine = in.readLine()) != null) {
    // set the sort for values is greater than 0
       if (!aLine.trim().startsWith("-") && aLine.trim().length() > 0) {
           al.add(aLine);
           i++;
               }
           }


    Collections.sort(al);   // sorted content to the output file
    for (String s : al) {
    System.out.println(s);
       out.write(s);
       out.newLine();
       out.newLine();
       }
    // close the 2 files
           in.close();
           out.close();
       }
    }

    Learn More
  5. PRG421 Week 3 Individual Coding Assignment

    PRG 421 Week 3 Individual Coding Assignment

    Regular Price: $10.00

    Special Price: $7.00

    PRG 421 Week 3 Individual Coding Assignment


    For this assignment, you will develop "starter" code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text file, sort and store the contents of the text file into an ArrayList, then write the sorted contents via an output stream to a separate output text file.
    Copy and paste the following Java™ code into a JAVA source file in NetBeans:
     
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
     
    public class Datasort {
     
    public static void main (String [] args)  {
     
    File fin =      // input  file
    File fout =    // create an out file
     
    // Java FileInputStream class obtains input bytes from a file
    FileInputStream fis = new FileInputStream(fin);    
     
    // buffering characters so as to provide for the efficient reading of characters, arrays, and lines
    BufferedReader in = new BufferedReader(new InputStreamReader(fis));
     
    // declare an array in-line, ready for the sort
    String aLine;
    ArrayList al = new ArrayList ();
     
    int i = 0;
    while ((aLine = in.readLine()) != null) {
    // set the sort  for values is greater than 0
     
    Collections.sort(al);    // sorted content to the output  file
    {
    System.out.println(s);
                  
    }
     // close the 2 files
                          
    }
    }
     
    Add code as indicated in the comments.
    Note: Refer to this week's Individual assignment, "Week Three Analyze Assignment," and to Ch. 8, "IO," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide.
    Run and debug your modified program in NetBeans until it satisfies the requirements described above.
    Save your finalized JAVA file with a .txt extension.
    Submit your TXT file to the Assignment Files tab.

    Learn More
  6. PRG 421 Week 4 Individual Analyze Assignment Analyzing a Multithreaded Program

    PRG 421 Week 4 Individual Analyze Assignment Analyzing a Multithreaded Program

    Regular Price: $7.00

    Special Price: $5.00

    PRG 421 Week 4 Individual Analyze Assignment Analyzing a Multithreaded Program


    Deadlock occurs when no processing can occur because two processes that are waiting for each other to finish. For example, imagine that two processes need access to a file or database table row in order to complete, but both processes are attempting to access that resource at the same time. Neither process can complete without the other releasing access to the required resource, so the result is deadlock.
    Read and analyze code in the linked document that spawns two different threads at the same time.
    In a Microsoft® Word file, predict the results of executing the program, and identify whether a deadlock or starvation event will occur and, if so, at what point in the code.
    Submit your Word file to the Assignment Files tab.
    1. Predict the results of executing the program.
    2. Identify whether a deadlock or starvation event will occur and, if so, at what point in the code.


    /**********************************************************************
    * Program: Week 4 Analyze a Multithreaded Program
    * Purpose: Review the code and predict the results for the program execution.
    * Programmer: Iam A. student
    * Instructor: xxx
    ***********************************************************************/
    Package example deadlk;


    public class Deadlock {
    public static Object Lock1 = new Object(); // aacquires lock on the Lock1 object
    public static Object Lock2 = new Object(); // aacquires lock on the Lock2 object
    public static void main(String args[]) {
    ThreadDemo1 T1 = new ThreadDemo1(); // define the new threads
    ThreadDemo2 T2 = new ThreadDemo2(); // and set name for the threads
    T1.start();
    T2.start();
    }


    private static class ThreadDemo1 extends Thread {
    public void run() {
    synchronized (Lock1) {
    // synchronized Lock1 and Lock 2 will hold the thread until release
    System.out.println("Thread 1: Holding lock 1...");
    try { Thread.sleep(10); } // pause for 10 secs, then access thread
    catch (InterruptedException e) {} // if exception happens, “catch it”
    System.out.println("Thread 1: Waiting for lock 2..."); // display wait condition
    synchronized (Lock2) {
    System.out.println("Thread 1: Holding lock 1 & 2...");
    }
    }
    }
    }


    private static class ThreadDemo2 extends Thread {
    public void run() {
    synchronized (Lock2) {
    System.out.println("Thread 2: Holding lock 2...");
    try { Thread.sleep(10); } // pause for 10 secs, then access thread
    catch (InterruptedException e) {} // if exception happens, “catch it”
    System.out.println("Thread 2: Waiting for lock 1..."); // display wait condition
    synchronized (Lock1) {
    System.out.println("Thread 2: Holding lock 1 & 2...");
    }
    }
    }
    }
    }

    Learn More
  7. PRG421 Week 5 Java 5.21 LAB Sorting user IDs

    PRG/421 Week 5 Java 5.21 LAB: Sorting user IDs

    Regular Price: $7.00

    Special Price: $3.00

    PRG/421 Week 5 Java 5.21 LAB: Sorting user IDs


    Given a main() that reads user IDs (until -1), complete the quicksort() and partition() methods to sort the IDs in ascending order using the Quicksort algorithm, and output the sorted IDs one per line.


    Ex. If the input is:
    kaylasimms
    julia
    myron1994
    kaylajones
    -1


    the output is:
    julia
    kaylajones
    kaylasimms
    myron1994

    Learn More
  8. PRG/421 Week 5 Java 5.20 LAB: Descending selection sort with output during execution

    PRG/421 Week 5 Java 5.20 LAB: Descending selection sort with output during execution

    Regular Price: $7.00

    Special Price: $3.00

    PRG/421 Week 5 Java 5.20 LAB: Descending selection sort with output during execution


    Write a void method selectionSortDescendTrace() that takes an integer array, and sorts the array into descending order. The method should use nested loops and output the array after each iteration of the outer loop, thus outputting the array N-1 times (where N is the size). Complete the main() to read in a list of up to 10 positive integers (ending in -1) and then call the selectionSortDescendTrace() method.


    If the input is:
    20 10 30 40 -1


    then the output is:
    40 10 30 20
    40 30 10 20
    40 30 20 10

    Learn More
  9. PRG421 Week 5 Java 5.10 LAB Number pattern

    PRG/421 Week 5 Java 5.10 LAB: Number pattern

    Regular Price: $7.00

    Special Price: $3.00

    PRG/421 Week 5 Java 5.10 LAB: Number pattern


    Write a recursive method called printNumPattern() to output the following number pattern.


    Given a positive integer as input (Ex: 12), subtract another positive integer (Ex: 3) continually until 0 or a negative value is reached, and then continually add the second integer until the first integer is again reached


    Ex. If the input is:
    12
    3


    the output is:
    12 9 6 3 0 3 6 9 12

    Learn More
  10. PRG/421 Week 5 Java 5.9 LAB: All permutations of names

    PRG/421 Week 5 Java 5.9 LAB: All permutations of names

    Regular Price: $7.00

    Special Price: $3.00

    PRG/421 Week 5 Java 5.9 LAB: All permutations of names


    Write a program that lists all ways people can line up for a photo (all permutations of a list of Strings). The program will read a list of one-word names (until -1), and use a recursive method to create and output all possible orderings of those names, one ordering per line.


    When the input is:
    Julia Lucas Mia -1


    then the output is (must match the below ordering):
    Julia Lucas Mia
    Julia Mia Lucas
    Lucas Julia Mia
    Lucas Mia Julia
    Mia Julia Lucas
    Mia Lucas Julia

    Learn More

Items 1 to 10 of 25 total

per page
Page:
  1. 1
  2. 2
  3. 3

Grid  List 

Set Ascending Direction