Question

Object Oriented Programming The assignment can be done individually or in teams of two. Submit one assignment per team of two
h. equals: This method will return true if the calling object and the passed object have the same number of passengers. Using
- If the metro train is at the 1st station in any given direction, there will only be people waiting to get on as the train i
Note: Some information is left out, this is only a rough sketch of what your program should behave Welcome to Metro Manager E
Passenger(s) new passengers waiting to board: 25 Passenger(s) got on: 25 Passenger(s) left behind waiting for next train: e D
Al1 out Metro 411 leaving station 3 east bound with e passenger(s) Passenger(s) got off:211 Passenger(s) new passengers waiti
ROGERS 7:21 PM 92% × Output Example.pdf Type y or for yes, anything else for no: y In the middle (Passengers Left fron last
Metro 411 leaving station 1 west bound with passenger(s) Passenger(s) got off:115 Passenger(s) new passengers waiting to boar

java
Object Oriented Programming The assignment can be done individually or in teams of two. Submit one assignment per team of two via Omnivox and NOT MIO.Assignments sent via MIO will be deducted marks. Assignments must be done alone or in groups and collaboration between individuals or groups is strictly forbidden. There will be a in class demo on June 1 make sure you are prepared, a doodle will be created to pick your timeslot. If you submit late, there is a 10% penalty for every day you submit late and you get 0 if it is submitted more than 5 days late. General Guidelines When Writing Your Programs: Include the following in comments at the top of your program: // Project Metro Written by: (include your name(s) and student ID(s)) Il Short Description of your project/code and how you designed it. Throughout your program, include comments in your describing the main steps. program Write a program which controls a metro train and that keeps track of stations and who gets on and off. Design and implement a class called train, which has at least the following: a. At least the following attributes (you can incl ude others): i. metroll ii. stationNum which keeps track of the station that the train is at. iii. direction which keeps track of the direction the train is travelling in. iv. pass Total which keeps track of the number of passengers currently on the train b. A default constructor which sets the metrolD to a random number between 1 and 1000, the station number to 0, the direction (int), and the pass Tot to 0 (train is empty) c. A constructor with one parameter; the parameter is the metro id. The constructor assigns the passed integer to the metrolD attribute; the rest of the attributes are set as described in the default contrustor d. Accessor methods for each attributes. e. Mutator methods for each attributes. f. nextStation(int lastStation) which determines the next station the train is to go to, and changes the direction of the train when necessary. (See the rules set in assignment 3). This method should return a integer value which will specify the action that needs to be done: passengers leaving, passengers boarding or passengers getting off and boarding g. toString: This method will return in a string the metrolD, the current station number, the direction the train is travelling in as well as the number of passengers on the train. h. equals: This method will return true if the calling object and the
h. equals: This method will return true if the calling object and the passed object have the same number of passengers. Using all of these methods may not be necessary in your design but they must be present either way (can also be used to add something Your program driver should: - Display a welcome message - Ask the user for the number of metro stations. There should be at least 3 stations. Make sure the user enters a number 2 3, if not keep asking until they enter at least 3. You may as well ask the user for input to name the stations. Create a Train object using the default constructor - As long as the user wants: 1. Advance the train to the next station. At each station, using a random number generate the number of people who will disembark the train (where applicable), and the number of people who have arrived wishing to embark on the train (where applicable). Rules: If the metro train is at the 1st station in any given direction, there will only be people waiting to get on as the train is empty. - If the metro train is at the last station, all passengers must get off and no one can get on until the train turns around. Any other station, there are people waiting to get on (a max of 300), and some people will get off the train (can't have more people getting off than there are people on the train). If the number of places available on the train, after people leave is less than the number of people waiting to get on, some people will be left waiting on the platform for the next train. 2. Keep track of the number of people who did not get on the train, as they will try and embark on the next train. (Recommend having a 2 dimensional array with size 2 by the number of stations; each row represents a direction). 3. Display the Train ID, the station that the train is leaving and the number of passengers. As well: -indicate the number of people who got off the train -the number of people who were left behind at this station the last time and are hoping to embark the train this time -the new people who arrived on the platform -the number of people who actually got on the train -the number who are left behind on the platform because the train was full this time. Include the train id, the station number and the direction the train is travelling in (info that is displayed when output a train object). 4. Ask the user if they would like to continue following the metro

Note: Some information is left out, this is only a rough sketch of what your program should behave Welcome to Metro Manager Enjoy your metro experience Enter number of metro stations (minimum 3): 3 This Metro line has 3 stations Only in (New Passengers waiting 188) (Passengers Left from last time e) Metro 411 (new Train) leaving station 1 east bound with 180 passenger(s) Passenger(s) got off:e Passenger(s) ne passengers waiting to board: 1ee Passenger(s) got on: 10 Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411? Type "y" or "Y" for yes, anything else for no: y In the middle (Passengers Left from last time e) Metro 411 leaving station 2 east bound with 97 passenger(s) Passenger(s) got off:38 Passenger(s) new passengers waiting to board: 27 Passenger(s) got on: 27 Passenge(s) left behind waiting for next train: Do you want to continue following Metro train 411? Type "y" or "Y" for yes, anything else for no: y All out Metro 411 leaving station 3 east bound with 8 passenger(s) Passenger(s) got off:97 Passenger (s) new passengers waiting to board: e Passenger(s) got on: 8 Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411? Type "y" or "Y" for yes, anything else for no: y Only in (New Passengers waiting 25) (Passengers Left from last time 8) Metro 411 leaving station 3 west bound with 25 passenger (s) Passenger(s) got off:e
Passenger(s) new passengers waiting to board: 25 Passenger(s) got on: 25 Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411? Type "y" or "Y" for yes, anything else for no: y In the middle (Passengers Left from last time e) Metro 411 leaving station 2 west bound with 87 passenger(s) Passenger(s) got off:15 Passenger(s) new passengers waiting to board: 77 Passenger(s) got on: 77 Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411 Type "y" or "Y" for yes, anything else for no: y All out Metro 411 leaving station 1 west bound with passenger(s) Passenger (s) got off:87 Passenger(s) new passengers waiting to board: e Passenger(s) got on: Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411 Type "y" or "Y" for yes, anything else for no: y Only in (New Passengers waiting 53) (Passengers Left from last time ) Metro 411 leaving station 1 east bound with 53 passenger(s) Passenger(s) got off :0 Passenger (s) new passengers waiting to board: 3 Passenger(s) got on: 53 Passenger(s) left behind waiting for next train: Do you want to continue following Metro train 411? Type "y" or "Y" for yes, anything else for no: y In the middle (Passengers Left from last time e) Metro 411 leaving station 2 east bound with 211 passenger(s) Passenger(s) got off:41 Passenger(s) new passengers waiting to board: 199 Passenger(s) got on: 199 Passenger (s) left behind waiting for next train: Do you want to continue following Metro train 411 Type "y" or "Y" for yes, anything else for no: y
Al1 out Metro 411 leaving station 3 east bound with e passenger(s) Passenger(s) got off:211 Passenger(s) new passengers waiting to board: Passenger(s) got on: e Passenger(s) left behind waiting for next train Do you want to continue following Netro train 411 Type "y" or "Y" for yes, anything else for no: y Only in (New Passengers waiting 35) (Passengers Left fron last time e) Metro 411 leaving station 3 west bound with 35 passenger(s) Passenger(s) got off:e Passenger(s) new passengers waiting to board: 35 Passenger(s) got on: 35 Passenger(s) left behind waiting for next train:0 Do you want to continue following Metro train 411? Type "y" or "V" for yes, anything else for no: y In the middle (Passengers Left from last time e) Metro 411 leaving station 2 west bound with 63 passenger(s) Passenger(s) got off:1 Passenger(s) new passengers waiting to board: 29 Passenger(s) got on: 29 Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411? Type "y" or "Y" for yes, anything else for no: y All out Metro 411 leaving station 1 west bound with passenger(s) Passenger(s) got off:63 Passenger s) new passengers waiting to board: e Passenger(s) got on: Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411 Type "y" or "V" for yes, anything else for no: y Only in (New Passengers waiting 104) (Passengers Left fron last time e) Metro 411 leaving station 1 east bound with 184 passenger(s) Passenger(s) got off: Passenger(s) new passengers waiting to board: 184 Passenger(s) got on: 184
ROGERS 7:21 PM 92% × Output Example.pdf Type "y" or for yes, anything else for no: y In the middle (Passengers Left fron last time e) Metro 411 leaving station 2 east bound with 166 passenger(s) Passenger(s) got off:8 Passenger(s) new passengers waiting to board: 7e Passenger(s) got on: 70 Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411 Type "y" or-V" for yes, anything else for no: y All out Metro 411 leaving station 3 east bound with e passenger(s) Passenger(s) got off:166 Passenger(s) new passengers waiting to board: Passenger(s) got on: e Passenger(s) left behind waiting for next train: Do you want to continue following Metro train 411? Type "y" or "Y" for yes, anything else for no: y Only in (New Passengers waiting 153) (Passengers Left fron last tinee) Metro 411 leaving station 3 west bound with 153 passenger(s) Passenger(s) got off:e Passenger(s) new passengers waiting to board: 153 Passenger s) got on: 153 Passenger(s) left behind waiting for next train: θ Do you want to continue following Metro train 411? Type "y-or-V" for yes, anything else for no: y In the middle (Passengers Left fron last time e) Metro 411 leaving station 2 west bound with 115 passenger(s) Passenger(s) got off:13e Passenger(s) new passengers waiting to board: 92 Passenger(s) got on: 92 Passenger(s) left behind waiting for next train: Do you want to continue following Metro train 411? Type "y-or-r for yes, anything else for no: y All out
Metro 411 leaving station 1 west bound with passenger(s) Passenger(s) got off:115 Passenger(s) new passengers waiting to board: e Passenger(s) got on: Passenger(s) left behind waiting for next train Do you want to continue following Metro train 411? Type "y or Y for yes, anything else for no: y Only in (New Passengers waiting 189) (Passengers Left from last time e) Metro 411 leaving station 1 east bound with 189 passenger(s) Passenger(s) got off:e Passenger(s) new passengers waiting to board: 189 Passenger(s) got on: 189 Passenger(s) left behind waiting for next train: e Do you want to continue following Metro train 411? Type "y" or-r for yes, anything else for no: y In the middle (Passengers Left fron last time e) Metro 411 leaving station 2 east bound with 159 passenger(s) Passenger(s) got off:69 Passenger(s) new passengers waiting to board: 39 Passenger(s) got on: 39 Passenger(s) left behind waiting for next train: Do you want to continue following Metro train 411 Type y or Y for yes, anything else for no: n Thank you for using Metro Manager 3.0 Be sure to look out for future enhancenents!
0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • I have pasted the code and screenshot of successful run below.
  • In case of any doubts just comment down.
  • Please do upvote if you found it helpful. :)

-------------------------Screenshot-----------------------

ksmukta:19.java-metro -> javac *.java&& java Driver Welcome to Metro Manager Enjoy your metro experience Enter number of metr

Do you Want to continue following Metro train 952? Type y or Y for yes, anything else for no: y Only in (New Passengers w

only in (New Passengers waiting 76) (Passengers left from last time θ) Metro 952 leaving station 1 east bound with 76 passeng
-------------------------Metro.java-----------------------

import java.util.Random;

public class Metro{
   private int metroID;
   private int stationNum;
   private int direction;
   private int passTotal;
   private Random randomGenerator;

   public Metro(){
       randomGenerator = new Random();
       metroID = randomGenerator.nextInt(1000)+1;
       stationNum = 0;
       direction = 1;
       passTotal = 0;
   }

   public Metro(int metroID){
       randomGenerator = new Random();
       this.metroID = metroID;
       stationNum = 0;
       direction = 1;
       passTotal = 0;
   }

   public String toString(){
       String str = "Metro " + metroID;
       str += " leaving station " + stationNum;
       if(direction==1)
           str += " east bound";
       else
           str += " west bound";
       str += " with " + passTotal + " passenger(s)";
       return str;
   }

   public Boolean equals(Metro other){
       return other.getPassTotal()==this.passTotal;
   }

   public int nextStation(int lastStation){
       if((stationNum+direction>lastStation) || (stationNum+direction<1)){
           direction = -direction;
       }
       return stationNum+direction;
   }

   public int getMetroID(){return metroID;}
   public int getStationNum(){return stationNum;}
   public int getDirection(){return direction;}
   public int getPassTotal(){return passTotal;}

   public void setMetroID(int metroID){this.metroID = metroID;}
   public void setStationNum(int stationNum){this.stationNum = stationNum;}
   public void setDirection(int direction){this.direction = direction;}
   public void setPassTotal(int passTotal){this.passTotal = passTotal;}
}

-------------------------Driver.java-----------------------

import java.util.Random;
import java.util.Scanner;

public class Driver{
   public static void main(String[] args) {
       Random randomGenerator = new Random();
       Scanner s = new Scanner(System.in);
       System.out.println("Welcome to Metro Manager - Enjoy your metro experience");
       System.out.println("-----------------------------------------");
       System.out.print("Enter number of metro stations (minimum 3): ");
       int numStations = s.nextInt();
       while(numStations<3){
           System.out.print("Enter number of metro stations (minimum 3): ");
           numStations = s.nextInt();
       }
       System.out.println("This Metro has 3 stations.\n");
       System.out.println("-----------------------------------------");
       Metro m = new Metro();
       m.setStationNum(1);
       int[][] passengersLeft = new int[numStations+1][3];
       for(int i=0;i<numStations+1;i++){
           for(int j=0;j<3;j++){
               passengersLeft[i][j] = 0;
           }
       }
       char cont = 'y';
       while(cont=='y' || cont=='Y'){
           int newPassengers = randomGenerator.nextInt(120);
           int snum = m.getStationNum();
           int dir = m.getDirection();
           System.out.println("--------------------------");
           if((snum==1 && dir==1) || (snum==numStations && dir==-1)){
               System.out.println("Only in");
               System.out.println("(New Passengers waiting "+newPassengers+")");
               System.out.println("(Passengers left from last time "+passengersLeft[snum][1+dir]+")");
           }else if((snum==numStations && dir==1) || (snum==1 && dir==-1)){
               System.out.println("All out");
               newPassengers = 0;
           }else{
               System.out.println("In the middle");
               System.out.println("(Passengers left from last time "+passengersLeft[snum][1+dir]+")");
           }
           System.out.println("--------------------------");
           int toBoard = newPassengers + passengersLeft[snum][1+dir];
           int gotOff = randomGenerator.nextInt(m.getPassTotal()+1);
           if((snum==numStations && dir==1) || (snum==1 && dir==-1)) gotOff = m.getPassTotal();
           m.setPassTotal(m.getPassTotal()-gotOff);
           int gotOn = Math.min(300-m.getPassTotal(),toBoard);
           m.setPassTotal(m.getPassTotal()+gotOn);
           passengersLeft[snum][1+dir] = toBoard-gotOn;
           System.out.println(m);
           System.out.println("\tPassenger(s) got off: " + gotOff);
           System.out.println("\tPassenger(s) new passengers waiting to board: " + toBoard);
           System.out.println("\tPassenger(s) got on: " + gotOn);
           System.out.println("\tPassenger(s) left behind waiting for next train: " + passengersLeft[snum][1+dir]);
           System.out.println("\nDo you want to continue following Metro train "+m.getMetroID()+"?");
           System.out.print("Type \"y\" or \"Y\" for yes, anything else for no: ");
           cont = s.next().charAt(0);
           if((snum==1 && dir==1) || (snum==numStations && dir==-1)){
               m.setStationNum(snum+dir);
           }else if((snum==numStations && dir==1) || (snum==1 && dir==-1)){
               m.setDirection(-dir);
           }else{
               m.setStationNum(snum+dir);
           }
       }
       m.setStationNum(3);
   }
}

Add a comment
Know the answer?
Add Answer to:
java Object Oriented Programming The assignment can be done individually or in teams of two. Submit one as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment...

    Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment is meant to introduce you to design and implementation of exceptions in an object-oriented language. It will also give you experience in testing an object-oriented support class. You will be designing and implementing a version of the game Nim. Specifically, you will design and implement a NimGame support class that stores all actual information about the state of the game, and detects and throws...

  • 60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictio...

    60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictionary.txt) required to run your program Background Boggle is a word game using a plastic grid of lettered dice, in which players attempt to find words in sequences of adjacent letters. The dice are randomly arranged in the grid, and players have 90 seconds to form as many words as possible from adjacent top-facing letters For example, the word SUPER is spelled in the gameboard to...

  • Solve it for java Question Remember: You will need to read this assignment many times to...

    Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...

  • please help!!!! JAVA I done the project expect one part but I still give you all...

    please help!!!! JAVA I done the project expect one part but I still give you all the detail that you needed... and I will post my code please help me fix the CreateGrid() part in main and make GUI works    List Type Data Structures Overview : You will be implementing my version of a linked list. This is a linked list which has possible sublists descending from each node. These sublists are used to group together all nodes which...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

  • hello there, i have to implement this on java processing. can someone please help me regarding...

    hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...

  •    Available Feb 11 at 12am - Mar 8 at 11:59pm 26 days Not for IV...

       Available Feb 11 at 12am - Mar 8 at 11:59pm 26 days Not for IV Use: The Story of an Enteral Tubing Misconnection The Story of Robin and Addison Lowe (United States) LEARNING OBJECTIVES After completing this case study, you will be able to: 1. Explore the scientific feld of human factors and how errors like tubing misconnections can be prevented. 2. Discuss the complexity of having two patients to treat, a mother and her fetus. 3. Describe suitable...

  • While reading the story, consider the culture (or sub culture) and related communication styles the story...

    While reading the story, consider the culture (or sub culture) and related communication styles the story reveals. Consider too, possibly, the values, behavioral norms, social practices, social artifacts, etc. After reading the story through the lens of this idea, please compose a full academic length (evidence-based 7 to 11 sentence long) paragraph which addresses the following prompt: What does the story reveal about the culture it portrays and/OR the communication styles the culture shares? In other words, what does the...

  • Chapter 12 Patlent Teaching 105 Part 3. Review Questions Circle the correct answer(s). In some questions,...

    Chapter 12 Patlent Teaching 105 Part 3. Review Questions Circle the correct answer(s). In some questions, more than one answer is correct. Select all that apply 13. Which of the following is the best rationale for nurses 19. Tell the patient to wait until you harve fin ished teaching before asking questions. Adults learn best when they understand the relevance of the information presented Do not assume an interpreter will be needed. Always ask the patient if he or she...

  • Hello, my name is Shady Slim. I understand you are going to help me figure out...

    Hello, my name is Shady Slim. I understand you are going to help me figure out my gross income for the year... whatever that means. It's been a busy year and I'm a busy man, so let me give you the lowdown on my life and you can do your thing I was unemployed at the beginning of the year and got $2,000 in unemployment compensation. I later got a job as a manager for Roca Cola. I earned $57,500...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT