HloProblem DescriptionOne day a farmer goes to the market, taking with him a cabbage and a goat. On the way he captured awolf, he’s a mighty farmer, and took it with him to the market. They came to a...

1 answer below »
HloProblem DescriptionOne day a farmer goes to the market, taking with him a cabbage and a goat. On the way he captured awolf, he’s a mighty farmer, and took it with him to the market. They came to a river. And on the Bank,there’s a boat. Now, the problem is that the boat just big enough to carry the farmer and one of the others.If the farmer leaves the wolf and the goat together, in his absence, the wolf would make a meal of the goat.Neither, could he leave the goat and the cabbage alone: the goat would eat the cabbage. Being used tohardship, the farmer was quite prepared to make several trips back and forth, just so long as he couldeventually bring them all to the other side and went on to the market. How should he arrange the trips?Figure 1. CLI version of the river crossing.Part 1 RequirementsYour task as a software developer is to write a Command Line Interface (CLI) applicationRiverCrossingCLI simulating the river crossing. The farmer (player) can then work out the steps requiredto safely move all items to the other side of the river. In Part 1 you will need to do two tasks:1. Your first task is to design and create a RiverCrossing class to represent the river crossing with theappropriate attributes and methods. Assume river flows west to east (left to right of the page),farmer moves north (straight up) and requires to transport items from the South Bank to NorthBank of the river. Design class so it can be re-used in Part 2 of the assignment, the GUI version ofRiver Crossing.(a) Write the RiverCrossing constructor.(b) Use a boolean (or integer) array elements as place holders for the Farmer’s items (boat,cabbage, goat, wolf). False value to represent an item located on the South Bank and Trueon the North Bank of river.(c) Write a row() method to transport an item from one Bank to another Bank.(d) Write get() methods to return string with inventory (a list of all items, including the boat)located on the North Bank and another get() method for the South Bank.(e) Write other methods as required.2. Write a Command Line Interface class with main method to allow the user to play the game. Asample of a dialogue between the computer and the user (farmer) trying to cross from the southBank to the north Bank:NIT2112 Object Oriented ProgrammingPage 4The above dialogs are meant as a sample only. You are at liberty to design the game in any way you likeand you should. In particular, you should inform the user the consequences of a bad decision, i.e., thecabbage or the goat was eaten and the game is overA sample of an UML diagram shows the class diagram forRiverCrossing class.Instance attributes are all private;• Bank[ ] array contains boolean values representing position ofan item, south Bank false and true if its in the north Bank• item[ ] array comprise of strings "boat", "cabbage", "goat","wolf"• other attributes as necessaryRiverCrossing Methods• RiverCrossing( ) constructor sets all item to false (south Bank)• getItemStatus(int item) returns a String with location of item i• getNorthBank( ) return String with north Bank inventory• getSouthBank( ) return String with south Bank inventory• row(int item) transport the boat with the selected item. Farmer is allowed to take an empty boatacross the river. The method returns the following integer codes:0 the move successful1 all items transported to north Bank, player won11 the selected item is already across the river, error code12 the goat ate the cabbage, end of the game13 the wolf ate the goat, end of the game14 the goat ate the cabbage and wolf ate the goat, end of the game.Part 2Create a Windows GUI (JFrame) application for launching RiverCrossing game.Choose GUI components that reduce user errors and provide a feedback to the player. For example, thereis no need for a “boat” button because “row” button always moves the boat with or without an item.One simple GUI interface is shown in the Figure 2 below. Click the button “row” to immediately row theboat across or to transport the wolf select button “wolf” followed by click on the “row” buttonFigure 2. Basic river crossing layout.Once again, this is only a sample interface to illustrate the idea of the game. You are free to choose yourown colour scheme and buttons. Movement can be achieved by clicking a button. Make use of layoutmanagers to design colourful and a well-organized game. Consider the following controls as a minimumrequirement:• one button to reset and start the game again,• a text field for the player’s name (a player may choose to leave it blank).• a text area to display a warning messages (and the past history), for example, “This is not a goodidea” or to inform the player that cabbage or the goat was eaten and game is lost. You can provideyour own appropriate messages.An advanced River crossing is shown in Figure 3. Full marks will be given to fully functional basic layoutbut additional marks may be given by better GUI as long it is fully functional.Figure 3. An example of advanced river crossing layout with button icons (pictures) and boat drawing.What do you have to hand in?An electronic copy of1. Readme.docx file with information on how to run your program. Include any extra informationabout your design and program that you wish the marker to know.2. Summary of tasks allocations—who did what?3. A word document with the evidence of trial runs of your program, i.e., screen printouts of the resultswhere you have tested all the features of your code.4. UML diagram for all classes in your program.5. Code for all the classes that has been compiled and are ready to run. (jGRASP will be used to runand test your application).6. A brief description of the class. At the start of each method, there should be a comment clearlydescribing what the method does.Each class should be fully documented commencing with a heading. In particular, the headingshould include your name, unit, assignment details, date written and a brief description of theclass. At the start of each method, there should be a comment clearly describing what the methodd
Answered Same DaySep 30, 2021NIT2112

Answer To: HloProblem DescriptionOne day a farmer goes to the market, taking with him a cabbage and a goat. On...

Mohd answered on Oct 09 2021
129 Votes
updated solution/a.PNG
updated solution/b.PNG
updated solution/c.PNG
updated solution/class.PNG
updated solution/d.PNG
updated solution/e.PNG
updated solution/f.PNG
updated solution/g.PNG
updated solution/Readme.docx
Report
Steps to run program:
Step 1: Open Project in jGRASP,
Step 2: Run DisplayDriver.java file for console based output,
Step 3: Run RiverGUI.java file for GUI based output.
Screenshot:
UML class diagram
updated solution/River Crossing Game/River Crossing Game.gpj
!1561;s
A
SAU0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH=+%;%\012CYGWIN=nodosfilewarning\012GCC_COLORS=\012-Run\012ADD_EXE_PATH==Y\012
SCU0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH=+%;%\012CYGWIN=nodosfilewarning\012GCC_COLORS=\012-Run\012ADD_EXE_PATH==Y\012
S+U0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH=+%;%\012CYGWIN=nodosfilewarning\012GCC_COLORS=\012-Run\012ADD_EXE_PATH==Y\012
SJU0JGRASP_MAIN_BOUNDS=%\012CLASSPATH=+%;%\012CLASSPATH+=%%;\012File\012CLASSPATH+=.%;\012CLASSPATH+=%%;\012ProjectOrFile\012PATH+=%%;\012PAT
H+=%%;\012Debug +Debug_Applet\012CLASSPATH=+%;%\012Compile\012NOT_FOUND_MESSAGE==Make sure you have the full JDK, not just the JRE, installed.\\nThe JDK is available from http://www.oracle.com/technetwork/java/index.html.\012Run_Applet +Debug_Applet\012ADD_APPLETVIEWER_CLASSPATH==Y\012Document\012CLASSPATH=+%;%\012CLASSPATH+=%%;\012
SXU0
SOU0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH=+%;%\012CYGWIN=nodosfilewarning\012GCC_COLORS=\012-Run\012ADD_EXE_PATH==Y\012
SyU0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH+=%%;\012CYGWIN=nodosfilewarning\012GCC_COLORS=
SPU0
s#i0
s#k0
s#j0
s#l0
s#m0src
s#n0classes
s#p0doc
s#q0test
s#w0canvas
!101;g
%\011src%sRiverGUI.java
%\011src%sDisplayRiver.java
%\011src%sBank.java
%\011src%sRiverCrossing.java
!101;f
%\011src%sRiverGUI.java
%\011src%sDisplayRiver.java
%\011src%sBank.java
%\011src%sRiverCrossing.java
updated solution/River Crossing Game/src/Bank.java
updated solution/River Crossing Game/src/Bank.java
public class Bank {
}
updated solution/River Crossing Game/src/DisplayRiver.java
updated solution/River Crossing Game/src/DisplayRiver.java
import java.util.HashSet;
import java.util.Scanner;
public class DisplayRiver {

    static Scanner input = new Scanner(System.in);

    static HashSet north = new HashSet<>();
    static HashSet south = new HashSet<>();

    static boolean check = true;

    public static void printRiver() {


        south.add("boat");
        south.add("cabbage");
        south.add("goat");
        south.add("wolf");

        System.out.println("Welcome to the CLI version of the River Crossing Game.\r\n" + 
                "Farmer crossing a river has boat, cabbage, goat and wolf.\r\n" + 
                "Boat can carry two items at the time and cannot leave\r\n" + 
                "the cabbage alone with the goat or the goat with the wolf.");

        do {
            System.out.println("\n\n");
            System.out.print("North Bank: ");
            for(String s : north)
            {
                System.out.print(s+", ");
            }
            System.out.println("\n────────────────────────────────────────");
            System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            System.out.println("────────────────────────────────────────");
            System.out.print("South Bank: ");
            for(String s : south)
            {
                System.out.print(s+", ");
            }
 
            System.out.println("\n\nYou have the following choices:");
            System.out.println("\t1 Row across by yourself\r\n" + 
                    "\t2 Take the cabbage with you\r\n" + 
                    "\t3 Take the goat with you\r\n" + 
                    "\t4 Take the wolf with you\r\n" + 
                    "\t5 Quit");
 
            System.out.print("What is your choice (1, 2, 3, 4 or 5)? ");
            String choice = input.next();
 
            switch(choice)
            {
                case "1":
                    acrossYourSelf();
                    break;
                case "2":
                    cabbageWithYou();
                    break;
                case "3":
                    goatWithYou();
                    break;
                case "4":
                    wolfWithYou();
                    break;
                case "5":
                    System.out.println("Thank u for using !!!");
                    System.exit(0);
                    break;
                default:
                    System.out.println("Wrong choice, please enter correct choice as per given options");
                    break;
 
            }
        }while(check);

        if(south.size() == 0)
            System.out.println("\n\n\n***** You won *****");
        else
            System.out.println("***** Game over *****");
    }

    public static void acrossYourSelf()
    {
        if(south.contains("boat"))
        {
            south.remove("boat");
            north.add("boat");
        }
        else
        {
            south.add("boat");
            north.remove("boat");
        }
 
    }

    public static void cabbageWithYou()
    {
        if(north.size() == 0)
        {
            north.add("cabbage");
            north.add("boat");
 
            south.remove("cabbage");
            south.remove("boat");
 
            if(south.size() == 2)
            {
                if(south.contains("goat") && south.contains("wolf"))
                {
                    System.out.println("\n\n");
                    System.out.print("North Bank: ");
                    for(String s : north)
                    {
                        System.out.print(s+", ");
                    }
                    System.out.println("\n────────────────────────────────────────");
                    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    System.out.println("────────────────────────────────────────");
                    System.out.print("South Bank: ");
                    for(String s : south)
                    {
                        System.out.print(s+", ");
                    }
                    System.out.println("\n\nThe wolf ate the goat");
                    check = false;
                }
            }
        }
        else if(north.contains("cabbage") && north.contains("boat"))
        {
            north.remove("cabbage");
            north.remove("boat");
 
            south.add("cabbage");
            south.add("boat");
        }
        else if(north.contains("wolf") || north.contains("goat"))
        {
            north.add("cabbage");
            north.add("boat");
 
            south.remove("cabbage");
            south.remove("boat");
 
            if(north.size() == 4)
            {
                System.out.println("\n\n");
                System.out.print("North Bank: ");
                for(String s : north)
                {
                    System.out.print(s+", ");
                }
                System.out.println("\n────────────────────────────────────────");
                System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                System.out.println("────────────────────────────────────────");
                System.out.print("South Bank: ");
                for(String s : south)
                {
                    System.out.print(s+", ");
                }
                check = false;
            }
        }
        else {
            check = false;
        }
    }

    public static void goatWithYou()
    {
        if(north.size() == 0)
        {
            north.add("goat");
            north.add("boat");
 
            south.remove("goat");
            south.remove("boat");
        }
        else if(north.contains("goat") && north.contains("boat"))
        {
            north.remove("goat");
            north.remove("boat");
 
            south.add("goat");
            south.add("boat");
        }
        else if(north.contains("cabbage") || north.contains("wolf"))
        {
            north.add("goat");
            north.add("boat");
 
            south.remove("goat");
            south.remove("boat");
 
            if(north.size() == 4)
            {
                System.out.println("\n\n");
                System.out.print("North Bank: ");
                for(String s : north)
                {
                    System.out.print(s+", ");
                }
                System.out.println("\n────────────────────────────────────────");
                System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                System.out.println("────────────────────────────────────────");
                System.out.print("South Bank: ");
                for(String s : south)
                {
                    System.out.print(s+", ");
                }
                check = false;
            }
 
        }
        else
        {
            check = false;
        }
    }

    public static void wolfWithYou()
    {
        if(north.size() == 0)
        {
            north.add("wolf");
            north.add("boat");
 
            south.remove("wolf");
            south.remove("boat");
        }
        else if(north.contains("wolf") && north.contains("boat"))
        {
            north.remove("wolf");
            north.remove("boat");
 
            south.add("wolf");
            south.add("boat");
        }
        else if(north.contains("goat") || north.contains("cabbage"))
        {
                north.add("wolf");
                north.add("boat");
 
                south.remove("wolf");
                south.remove("boat");
 
                if(north.size() == 4)
                {
                    System.out.println("\n\n");
                    System.out.print("North Bank: ");
                    for(String s : north)
                    {
                        System.out.print(s+", ");
                    }
                    System.out.println("\n────────────────────────────────────────");
                    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    System.out.println("────────────────────────────────────────");
                    System.out.print("South Bank: ");
                    for(String s : south)
                    {
                        System.out.print(s+", ");
                    }
                    check = false;
                }
        }
        else
        {
            check = false;
        }
    }







    public static void main(String[] args)
    {
        printRiver();
    }
}
updated solution/River Crossing Game/src/RiverCrossing.java
updated solution/River Crossing Game/src/RiverCrossing.java
public class RiverCrossing {
    private boolean Bank[];
    private final String item[] = {"boat", "cabbage", "goat","wolf"};

    public RiverCrossing()
    {}

    public String getItemStatus(int item)
    {
        return "";
    }

    public String getNorthBank()
    {
        return "";
    }

    public String getSouthBank()
    {
        return "";
    }

    public int row(int a)
    {
        return 1;
    }





}
updated solution/River Crossing Game/src/RiverGUI.java
updated solution/River Crossing...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here