Java

Need Help in Java Assignment?
We can help you if you are having difficulty with your Java Assignment. Just email your Java Assignment at admin@assignmentcache.com.
We provide help for students all over the world in Java Assignment.

Items 1 to 10 of 22 total

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

Grid  List 

Set Ascending Direction
  1. Big Java Chapter 8 Programming Exercise P8.3

    Big Java Chapter 8 Programming Exercise P8.3

    Regular Price: $5.00

    Special Price: $4.00

    Big Java Chapter 8 Programming Exercise P8.3


    Real cash registers can handle both bills and coins. Design a single class that expresses the commonality of these concepts. Redesign the CashRegister class and provide a method for entering payments that are described by your class. Your primary challenge is to come up with a good name for the class.

    Learn More
  2. 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
  3. Stack to print the Prime Factors Java Program

    Stack to print the Prime Factors Java Program

    $5.00

    Stack to print the Prime Factors Java Program


    For a given integer n > 1, the smallest integer d > 1 that divides n is a prime factor. We can find the prime factorization of n if we find d and then replace n by the quotient of n divided by d, repeating this until n becomes 1.


    Write a Java program that uses a stack (in Arrays) to print the prime factors of a positive integer in descending order.


    For example, for n = 3960, the program should produce:
    11*5*3*3*2*2*2

    Learn More
  4. PRG420 Week 2 Individual Assignment Coding a Program Containing if-then and switch Java Source

    PRG420 Week 2 Individual Assignment Coding a Program Containing if-then and switch

    Regular Price: $10.00

    Special Price: $7.00

    PRG420 Week 2 Individual Assignment Coding a Program Containing if-then and switch


    Individual: Coding a Program Containing if-then and switch


    Includes Working Java Build and Program File and Explanation of Code
    Resources:  Week Two Coding Assignment Zip File (starter code for this assignment that includes placeholders), and Week Two Recommended Activity Zip File (examples of how to code a switch statement, an if-then-else statement, and how to construct a string to display text onscreen).
    For this assignment, you will apply what you learned in analyzing Java™ code so far in this course by writing your own Java™ program.
    The Java™ program you write should do the following:
    • Accept user input that represents the number of sides in a polygon. Note: The code to do this is already written for you.
    • If input value is not between 3 and 5, display an informative error message
    • If input value is between 3 and 5, use a switch statement to display a message that identifies the correct polygon based on the number of sides matching the input number (e.g., triangle, rectangle, or polygon)
    Complete this assignment by doing the following:
    1. Download and unzip the linked Week Two Coding Assignment Zip File.
    2. Read the file carefully, especially the explanatory comments of what the existing code does.
    3. Add your name and the date in the multi-line comment header.
    4. Refer to the following linked Week Two Recommended Activity Zip File to see examples of how to code all of the Java™ statements (i.e., switch, println(), and if-then-else) you will need to write to complete this assignment.
    5. Replace the following lines with Java code as directed in the file:
    • LINE 1
    • LINE 2
    6. Comment each line of code you add to explain what you intend the code to do.
    7. Test and modify your Java™ program until it runs without errors and produces the results as described above.
    Note: Refer to this week's analyzing code assignment if you need help.
    Submit your Java source (.java) code file using the Assignment Files tab.


    /**********************************************************************
    * Program: PRG/420 Week 2
    * Purpose: Week 2 Coding Assignment
    * Programmer: Iam A. Student
    * Class: PRG/420 PRG420 PRG 420
    * Creation Date: 10/18/17
    *********************************************************************
    *
    **********************************************************************
    * Program Summary: This program demonstrates these basic Java concepts:
    * - defining variables of different types
    * - if-then and if-then-else logic
    * - constructing a string to display onscreen
    * - switch logic
    *
    * To finish assignment, you will add code where indicated. The
    * behavior of your completed assignment should be to accept an input
    * value for the number of sides of a two-dimensional figure. Based on that value,
    * your code should display the type of figure that corresponds to the number of polygon angles
    * indicated (3=triangle, 4=rectangle, etc.)
    *
    * Here are the specific requirements:
    *
    * After the user types in a value from 3 to 5 inclusive (i.e., 3, 4, or 5):
    *
    * 1. Your code determines whether the input value is out of range (less than 3 or more than 5)
    * and, if so, displays a meaningful error message on the screen and ends the program.
    *
    * 2. Because you will be comparing a single expression (the input value) to multiple constants (3, 4, and 5),
    * your code should use a switch statement to display the following message onscreen:
    *
    * If user inputs 3, onscreen message should say "A triangle has 3 sides."
    * If user inputs 4, onscreen message should say "A rectangle has 4 sides."
    * If user inputs 5, onscreen message should see "A pentagon has 5 sides."
    *
    * 3. Be sure to test your program. This means running your program multiple
    * times with test values 3, 4, 5, as well as at least two values that fall outside that range
    * (one lower than the lowest and one higher than the highest) and making sure
    * that the correct message displays for each value you input. Also be sure
    * that running your program does not cause any compiler errors.
    ***********************************************************************/


    package week2codingassignment;


    import java.util.Scanner;


    public class PRG420Week2_CodingAssignment {
    public static void main(String[] args) {
    String userInputStringOfAngles; // Declare a variable of type String to capture user input
    int numberOfAngles; // Declare a variable of type int to hold the converted user input
    Scanner myInputScannerInstance = new Scanner(System.in); // Recognize the keyboard
    System.out.print("Please type the integer 3, 4, or 5 and then press Enter: "); // Prompt the user
    userInputStringOfAngles= myInputScannerInstance.next(); // Capture user input as string
    numberOfAngles = Integer.parseInt(userInputStringOfAngles); // Convert the string to a number in case this will be useful later
    // LINE 1. CODE TO DETERMINE WHETHER USER INPUT IS OUT OF BOUNDS GOES HERE
    // LINE 2. SWITCH CODE TO PRINT CORRECT "SHAPE" MESSAGE BASED ON USER INPUT GOES HERE
    }
    }

    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 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
  7. Remove hyphens from a word java program

    Remove hyphens from a word Java program

    $5.00

    Remove hyphens from a word Java program


    This program will remove the hyphens from a word. a string (delimited by whitespaces) with hyphens is divided into substrings delimited by hyphen.
    Program outputs shall go to the console display.
    input: WORD-word
    expected output: WORD word

    Learn More
  8. PRG420 Week 1 Individual Assignment Coding a Simple Hello world Java Program

    PRG420 Week 1 Individual Assignment Coding a Simple "Hello, world!" Java Program

    Regular Price: $7.00

    Special Price: $5.00

    PRG420 Week 1 Individual Assignment Coding a Simple "Hello, world!" Java Program


    Individual: Coding a Simple "Hello, world!" Java™ Program


    Includes Working Java Build and Program File and Explanation of Code
    Resource: Week One Coding Assignment Zip File (starter code for this assignment that includes placeholders)
    For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program. The Java™ program you write should do the following:
    • Display a prompt on the console asking the user to type in his or her first name
    • Construct the greeting string "Hello, nameEntered!"
    • Display the constructed greeting on the console
    Complete this assignment by doing the following:
    1. Download and unzip the linked zip file.
    2. Add comments to the code by typing your name and the date in the multi-line comment header.
    3. Replace the following lines with Java™ code as directed in the file:
    • LINE 1
    • LINE 2
    • LINE 3
    • LINE 4
    4. Comment each line of code you add to explain what you intend the code to do.
    5. Test and modify your Java™ program until it runs without errors and produces the results as described above.
    Note: Refer to this week's analyzing code assignment if you need help.
    Submit your Java source (.java) code file using the Assignment Files tab.


    /**********************************************************************
    * Program: PRG420Week1_CodingAssignment
    *  Purpose: Week 1 Individual Assignment #2
    * Programmer: YOUR FULL NAME GOES HERE
    * Class: PRG/420 PRG420 PRG 420
    * Creation Date: TODAY'S DATE GOES HERE
    *********************************************************************
    *
    **********************************************************************
    * Program Summary: This program asks the user for a one-word name
    *            and then displays a constructed greeting
    *            that looks like this:
    *
    *            Hello, NAME!
    **********************************************************************/
    package prg420week1_codingassignment;


    /**
     *
     * @author NETBEANS PLACES YOUR INITIALS HERE
     */


    import java.util.Scanner;


    public class PRG420Week1_CodingAssignment {


      public static void main(String[] args) {


        // Create a usable instance of an input device 
        LINE 1. INSTANTIATE AN INSTANCE OF SCANNER AND ASSIGN IT TO A VARIABLE OF TYPE SCANNER.


        // Prompt user for input
        LINE 2. USE THE PRINT() METHOD TO PROMPT THE USER FOR HIS OR HER FIRST NAME.


        // Capture first word and assign it to A VARIABLE
        LINE 3. USE THE NEXT() METHOD OF YOUR SCANNER INSTANCE TO ASSIGN A VALUE TO A STRING VARIABLE.


        // Construct the greeting
        LINE 4. USE THE PRINTLN() METHOD TO CONSTRUCT A CORRECTLY PUNCTUATED GREETING.


    }
    }

    Learn More
  9. PRG420 Week 5 Individual Assignment Coding a Program Containing Exception Handling Output and coding

    PRG420 Week 5 Individual Assignment Coding a Program Containing Exception Handling

    Regular Price: $10.00

    Special Price: $7.00

    PRG420 Week 5 Individual Assignment Coding a Program Containing Exception Handling


    Individual: Coding a Program Containing Exception Handling


    Includes Working Java Build and Program File and Explanation of Code
    Resource:  Week Five Coding Assignment Zip File (starter code for this assignment that includes placeholders)
    For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program. The Java™ program you write should do the following:
    • Organize the code capable of throwing an exception of type ParseException as a try block.
    • Include a catch block to handle a ParseException error thrown by the try block.
    • Include a hard-coded error that results in a ParseException to prove that the code can catch and handle this type of exception.
    Complete this assignment by doing the following:
    1. Download and unzip the linked Week Five Coding Assignment Zip File.
    2. Add comments to the code by typing your name and the date in the multi-line comment header.
    3. Replace the following lines with Java™ code as directed in the file:
    • LINE 1
    • LINE 2
    4. Replace the value assigned with one of the variables so that the program throws an exception.
    5. Comment each line of code you add to explain what you intend the code to do. Be sure to include a comment for the replacement value you added in Step 4 that causes the program to throw an exception.
    6. Test and modify your Java™ program until it runs without errors and produces the results described above.
    Note: Refer to this week's analyzing code assignment if you need help.
    Submit your Java application file using the Assignment Files tab.


    /********************************************************************
    * Program:    PRG420Week5_CodingAssignment
    * Purpose:       Week 5 Individual Assignment #2
    * Programmer:    Iam A. Student
    * Class:         PRG/420  PRG420 PRG 420
    * Creation Date:   TODAY'S DATE GOES HERE
    *********************************************************************
    *
    *********************************************************************
    * Program Summary:
    * This program converts a given date to a string.  
    * The code includes exception handling for a ParseException.
    ************************************************************************************/
    package prg420week5_codingassignment;
    import java.util.*;
    import java.text.*;
    public class PRG420Week5_CodingAssignment {
     public static void main(String[] args){
      // The getInstance() method returns a Calendar object whose calendar fields have been initialized with the current date and time.
      Calendar calendar = Calendar.getInstance(); {
      LINE 1. BEGIN THE TRY BLOCK.
      String str_date="01-Nov-17"; // Declare a string that we will use later to format a date like this: ##-XXX-##
      DateFormat formatter; // Declare an object of type DateFormat so that we can call its parse() method later
      Date myFormattedDate; // Declare a variable of type Date to hold the formatted date
      formatter = new SimpleDateFormat("dd-MMM-yy"); // Assign a specific date format to the formatter variable
      // The given date is taken as a string that is converted into a date type by using
      // the parse() method
      myFormattedDate = (Date)formatter.parse(str_date); // setting up the format
      System.out.println("The formatted date is " + myFormattedDate);
      System.out.println("Today is " +calendar.getTime() );
      LINE 2. WRITE THE CATCH BLOCK TO CATCH EXCEPTIONS OF TYPE ParseException (TO HANDLE EXCEPTION, SIMPLY PRINT THE EXCEPTION)
      }
     }
    }

    Learn More
  10. Big Java Chapter 8 Programming Exercise P8.4 BankAccount

    Big Java Chapter 8 Programming Exercise P8.4 BankAccount Solution

    Regular Price: $5.00

    Special Price: $4.00

    Big Java Chapter 8 Programming Exercise P8.4 BankAccount


    Enhance the BankAccount class by adding preconditions for the constructor and the deposit method that require the amount parameter to be at least zero, and a precondition for the withdraw method that requires amount to be a value between 0 and the current balance. Use assertions to test the preconditions.

    Learn More

Items 1 to 10 of 22 total

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

Grid  List 

Set Ascending Direction