Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a class called Reverse.java. Make a method reverse that accepts two parameters: a Scanner representing an input file, and a PrintStream representing an output


Make a class called Reverse.java. Make a method reverse that accepts two parameters: a Scanner representing an input file, and a PrintStream representing an output file. Your method should read the input file,input.txtDownload input.txt, convert the input file's text to the reverse. Output the reversed version of the text to the given output file. Preserve the original line breaks from the input and perform the following replacements: For example, if the input file input.txt contains the following text:

I love School

Programming is fun

And your method is called in the following way:

Scanner input = new Scanner(new File(pathname)); PrintStream output = new PrintStream(new File(pathname)); reverse(input, output);

Then after the call, the output file reverse.txt should contain the following text:

School love I

fun is Programming

You may assume

  1. Each token from the input file is separated by exactly one space.
  2. There are no leading or trailing spaces.

Part 2

Make a class2DArray. It should contain the following:

  • Private instance variablesto store a 2D array, number of rows, number of columns, minimum and maximum value of the numbers stored in the array.
  • A constructorthat set the number of rows and columns for the array, and minimum and maximum value.
  • Public methodsto get and set the instance variables of the class. For the set2DArray method, create a matrix of random integers ranging from the minimum and maximum value.

  • Public methods:
    • a method calledaddMatricesthat takes another object of the class 2DArray as the argument and returns the sum of the matrix of the object that the method is called upon and the matrix of the object passed.
    • a method calledsubstractMatricesthat takes another object of the class 2DArray as the argument and returns the difference of the matrix of the object that the method is called upon and the matrix of the object passed.

Part 3

Make classesCard and Deck(Card.javaDownload Card.java). The instances of the Card class represent a single card.It should contain the following:

  • Private instance variablesname and suit. Both are String type.The name instance variable is either a number (as a String) or the String "A", "J", "Q", or "K".The suit instance variable is either "Club", "Diamond", "Heart", or "Spade".
  • A constructorthat sets thename and suit variables in the Card instance.Values to be assigned should be passed in via anargument list.
  • Public methodsto get and set the instance variables of the class.The getName and getSuit methods each return a String which correspond to the values of the instance variables name and suit, respectively.

  • Public methods:
    • a method calledvaluethatreturns an integer that gives the numerical value of the Card. For the non-numbered cards, the Ace should return 1 while Jack, Queen, and King should return 11, 12, and 13, respectively. Hint: To convert a String variable aString (that represents an Arabic numeral) into an int named asInt, you would type:int asInt = Integer.parseInt(aString);
    • a method calledtoStringthat will return the name and suit as asingle String. Thus, if myCard is an instance of Card that is set to the Queen of Hearts, the call myCard.toString() should return "Q Heart".

TheDeckDownload Deckclass holds Card objects in a line and has methods to initialize, shuffle, and deal cards.

  • Private instance variables:
    • a string array of values of cards callednames.
    • a string array of suits of cards calledsuits.
    • an array of Card objects.
    • an int calleddealtIndex, representing the number of the cards that have been dealt.
  • Constructors:
    • no-argument constructor which initializes the array called cards. The order of the Card doesn't matter.
  • Public methods:
    • a method calledshuffle,which shuffles each card by swapping itself with a random card in the unshuffled part
      • Consider using a Random object.
      • Consider making a helper method swap(), which swaps two cards
    • a method calleddeal,which takes an int, meaning the number the player should get. The method returns an array of Cards that the player gets.
      • check whether there are enough cards left, if not, return null.
      • Don't forget to updatedealtIndexalong the way

The driver fileMain.javaDownload Main.javais a basic test file. It make a new deck, shuffles the cards, and deals 13 (if we assume there are 4 players, but it can be any number ) cards for a player.




Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres the implementation for the requested classes java import javautilScanner import javaioFile import javaioPrintStream public class Reverse public static void reverseScanner input PrintStream outpu... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Java Programs A Back To Basics Approach

Authors: Stuart Reges, Marty Stepp

5th Edition

013547194X, 978-0135471944

More Books

Students also viewed these Programming questions

Question

For what is the phrase "number of failures" an abbreviation?

Answered: 1 week ago

Question

What are the applications of AI in agriculture?

Answered: 1 week ago