Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is one problem with multiple parts i need them all answered, please. Thank you! Part 1 Create a class called Reverse.java. Write a method

image text in transcribedimage text in transcribed

this is one problem with multiple parts i need them all answered, please. Thank you!

Part 1 Create a class called Reverse.java. Write 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.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 UW 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: UW love 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 Write a class Array2D. It should contain the following: Private instance variables to store a 2D array, number of rows, number of columns, minimum and maximum value of the numbers stored in the array. A constructor that set the number of rows and columns for the array, and minimum and maximum value. Public methods to 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: o a method called addMatrices that 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. o a method called substract Matrices that 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 Write classes Card and Deck (Card.java D). The instances of the Card class represent a single card. It should contain the following: Private instance variables name 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 constructor that sets the name and suit variables in the Card instance. Values to be assigned should be passed in via an argument list. Public methods to 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: o a method called value that returns 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 as Int = Integer.parseInt(string); o a method called toString that will return the name and suit as a single 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". The Deck class holds Card objects in a line and has methods to initialize, shuffle, and deal cards. Private instance variables: o a string array of values of cards called names. o a string array of suits of cards called suits. o an array of Card objects. o an int called dealtIndex, representing the number of the cards that have been dealt. Constructors: o no-argument constructor which initializes the array called cards. The order of the Card doesn't matter. Public methods: o a method called shuffle, which shuffles each card by swapping itself with a random card in the unshuffled part . Consider using a Random object. . Consider creating a helper method swap(), which swaps two cards o a method called deal, 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 update dealtIndex along the way The driver file Main.java D is a basic test file. It creates 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

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_2

Step: 3

blur-text-image_3

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

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago