Menu

[solved]-Class Panic Main Class Name Game Panic Methods Public Static Void Main String Args Actual Q39012783

class Panic

This is the main class. The name of the game is Panic!

Methods

  • public static void main(String[] args).
    • We will actually use the args now. We’re expecting one or twoarguments, which can be supplied when you invoke the program in oneof these two ways:

      or,

      • The first argument must be present, and must be a filename of amap to read.
      • The second argument might be present, describing the “logger” -this is where we will send messages describing what’s happening onthe map. If this argument is present, it is the name of a file thatshould be opened and all log messages written to it, and thenclosed. (Any file previously present with that name is overwritten,not appended). If there is no second argument, then System.out mustbe used by default, and all logging messages will show up on theconsole (this is convenient to use during development).
      • Note: We should use the PrintStream constructor,PrintStream(File), when preparing log to write to a file. Why didwe use PrintStream as the type of log, and not the more fashionablePrintWriter(which handles different encodings better)? Because wewanted to allow either writing to the console (via PrintStreamSystem.out, stuck in the old Java 1.0 mindset) or to an arbitraryfile (perhaps via aPrintWriter), we needed a common type to be usedin either situation. We might find that the newer PrintWriter has aconstructor that accepts an OutputStream (ancestor to PrintStream),which seems promising – but creating a PrintWriter based onSystem.out causes competition for the console, between System.outand your PrintWriter log. Competition for these sorts of resourcesis problematic. This is also why you should never create multiplescanners that read from the same source (such as System.in or aparticular File object), and instead you should create one and passit around as an argument. So for this assignment, we chose insteadto use PrintStream, which contains the constructorPrintStream(File).
    • Once we understand what map file to read (1st argument) andwhere to write log messages (2nd argument), this method will createa Map object. To start the simulation, we send messages to thelogger including both the ‘begin’ message, a listing of any thingsat their locations (two included in this example), and the currentmap:
    • Repeatedly, we print a message indicating the iteration number(starting at zero), and ask the map to iterate() once through allits things. Each successive line would show during a simulation,with many other lines between them of course:

    • when no escaping people remain (all are safe or dead), thesimulation is over, and we send the message:
    • If it refers to a file, close() the log before returning. (Youshouldn’t close the log if it is actually System.out!)

Expert Answer


Answer to class Panic This is the main class. The name of the game is Panic! Methods public static void main(String[] args). We wi… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *