Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this Lab: Modify the code for LineNumberer so that the input file comes from a different project, using a relative path

I need help with this Lab:

Modify the code for LineNumberer so that the input file comes from a different project, using a relative path to identify it. For example, run LineNumberer on the source file Deck.java

This is LineNumberer:

package lab8; import java.util.Scanner; public class LineNumberer { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int lineCount = 1; while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.print(lineCount + " "); System.out.println(line); lineCount += 1; } System.out.println("Done"); } }

And this is Deck.Java:

package lab7; import java.util.Random; import lab7.Card.Suit; /** * Class representing a standard 52-card deck of playing * cards from which cards can be selected at random. */ public class Deck { /** * The cards comprising this deck. */ private Card[] cards; /** * The random number generator to use for selecting cards. */ private Random rand; /** * Constructs a new deck with a default random number generator. */ public Deck() { rand = new Random(); init(); } /** * Constructs a new deck with the given random number generator. */ public Deck(Random givenGenerator) { rand = givenGenerator; init(); } /** * Returns a new array containing k elements selected * at random from this deck. */ public Card[] select(int k) { // TODO return null; } /** * Initializes a new deck of 52 cards. */ private void init() { cards = new Card[52]; int index = 0; for (int rank = 1; rank <= 13; ++rank) { cards[index] = new Card(rank, Suit.CLUBS); index += 1; cards[index] = new Card(rank, Suit.DIAMONDS); index += 1; cards[index] = new Card(rank, Suit.HEARTS); index += 1; cards[index] = new Card(rank, Suit.SPADES); index += 1; } } }

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

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

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899