Question

Programming Language is Java In class you learned how to work with collections and streams. This...

Programming Language is Java

In class you learned how to work with collections and streams. This lab allows you to apply the skills you learned to a list of riders.

With your first two assignment complete, the coordinator at the Car Safety Academy decided to begin collecting names for a monthly mailing list. You've been asked to collect the names and perform some processing. First you will create a Riders class. Then you will create an array of riders with the names below (DO NOT SKIP THIS STEP!):

Full Name* Address City State Zip Code Phone
John Harbaugh 8397 Zip Rd Baltimore MD 21999 123-456-7890
Mike Tomlin 147 LedStock Ave Pittsburg PA 07001 890-123-4567
Kevin Stepanski 34 Main St Cleveland OH 07001 456-789-0123
Zac Taylor 1222 Mover Rd Cincinnati OH 90001 345-678-9012
Ron Rivera 190 Princeton Ct Washington DC 20001 678-901-2345

Do not divide name into first and last at any stage of this lab.

Next you will create and display a rider list.

Then you should display a menu to the user asking what he or she would like to do next based on the following options:

  1. Add a new entry
    1. Prompt the user for the rider information and add it to the rider list
  2. Remove an entry
    1. Prompt the user for a full name, then remove any matching rider from the list
  3. Sort by zip code
  4. Search by state
  5. Search by full name (exactly match the full name)
  6. Print riders
  7. Quit

After displaying the menu, you should read in a number from the user. (You should check to ensure that the user enters a number 1-7.) Next you will perform the corresponding operation. (Operations 3,4, & 6 should be performed using a stream operations.)

Homework Answers

Answer #1

Short Summary:

  • Implemented the program as per the requirement
  • Attached source code and output

**************Please do upvote to appreciate our time. Thank you!******************

Source Code:

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

//This class holds the riders information

public class Riders {
   //Instance variables

   private String name;
   private String address;
   private String city;
   private String state;
   private String zipCode;
   private String phone;

   //Constructor to set values for instance variables

   public Riders(String name, String address, String city, String state, String zipCode, String phone) {
       this.name = name;
       this.address = address;
       this.city = city;
       this.state = state;
       this.zipCode = zipCode;
       this.phone = phone;
   }

   //Accessors
   public String getName() {
       return name;
   }


   public String getAddress() {
       return address;
   }


   public String getCity() {
       return city;
   }


   public String getState() {
       return state;
   }


   public String getZipCode() {
       return zipCode;
   }


   public String getPhone() {
       return phone;
   }

   //Main method to test
   public static void main(String args[])
   {
       //Hold the list of riders
       ArrayList<Riders> arrayOfRiders=new ArrayList<>();
       arrayOfRiders.add(new Riders("John Harbaugh", "8397 Zip Rd", "Baltimore", "MD", "21999", "123-456-7890"));
       arrayOfRiders.add(new Riders("Mike Tomlin", "147 LedStock Ave", "Pittsburg", "PA", "07001", "890-123-4567"));
       arrayOfRiders.add(new Riders("Kevin Stepanski", "34 Main St", "Cleveland", "OH", "07001", "456-789-0123"));
       arrayOfRiders.add(new Riders("Zac Taylor", "1222 Mover Rd", "Cincinnati", "OH", "90001", "345-678-9012"));
       arrayOfRiders.add(new Riders("Ron Rivera", "190 Princeton Ct", "Washington", "DC", "20001", "678-901-2345"));
       //display riders
       displayRiders(arrayOfRiders);
       //Get input from user
       Scanner input=new Scanner(System.in);
       //Display menu
       System.out.println("**********Menu***********");
       System.out.println("1. Add a new entry\n2. Remove an entry\n3. Sort by zip code\n4. Search by state\n5. Search by full name\n"
               + "6. Print Riders\n7. Quit\nEnter your choice:");
       int choice=input.nextInt();
       input.nextLine();
       //Validate the input
       while(choice<1 || choice>7)
       {
           System.out.println("Wrong choice! Please enter a number between 1 and 7");
           choice=input.nextInt();
           input.nextLine();

       }
       //Switch to perform the operations based on user choice
       switch(choice)
       {
       case 1:
           //Get rider details and add to list
           System.out.print("Enter new Rider's full name:");
           String name=input.nextLine();
           System.out.print("Enter address:");
           String address=input.nextLine();
           System.out.print("Enter city:");
           String city=input.nextLine();
           System.out.print("Enter state:");
           String state=input.nextLine();
           System.out.print("Enter zip code:");
           String zip=input.nextLine();
           System.out.print("Enter phone#:");
           String phone=input.nextLine();
           Riders rider=new Riders(name, address, city, state, zip, phone);
           arrayOfRiders.add(rider);
           System.out.println("Rider added successfully!");
           displayRiders(arrayOfRiders);
           break;
       case 2:
           //Remove by rider name
           System.out.print("Enter full name of the rider:");
           String fullName=input.nextLine();
           Iterator <Riders> iter=arrayOfRiders.iterator();
           while(iter.hasNext())
           {
               Riders riderObj=iter.next();
               if(riderObj.getName().equalsIgnoreCase(fullName))
                   iter.remove();
           }
           System.out.println("Rider removed successfully!");
           displayRiders(arrayOfRiders);
           break;
       case 3:
           //Sort by zipcode
           List<Riders> sortedList = arrayOfRiders.stream()
           .sorted(Comparator.comparing(Riders::getZipCode))
           .collect(Collectors.toList());
           sortedList.forEach(System.out::println);
           break;
       case 4:
           //Search by state
           System.out.print("Enter the state:");
           String enteredState=input.nextLine();
           List<Riders> stateRidersList = arrayOfRiders.stream()
                   .filter(n -> n.getState().equalsIgnoreCase(enteredState))
                   .collect(Collectors.toList());
           stateRidersList.forEach(System.out::println);
           break;
       case 5:
           //Get rider by full name
           System.out.print("Enter the full name:");
           String enteredName=input.nextLine();

           List<Riders> nameRidersList = arrayOfRiders.stream()
                   .filter(n -> n.getName().equalsIgnoreCase(enteredName))
                   .collect(Collectors.toList());
           nameRidersList.forEach(System.out::println);
           break;
       case 6:
           //display riders
           displayRiders(arrayOfRiders);
           break;
       case 7:
           //Exit
           System.exit(0);
           break;
       }

       input.close();
   }
   @Override
   public String toString() {
       return "Rider [name=" + name + ", address=" + address + ", city=" + city + ", state=" + state + ", zipCode="
               + zipCode + ", phone=" + phone + "]";
   }

   //This method prints the list of riders
   private static void displayRiders(List<Riders> arrayOfRiders)
   {
       System.out.println("--------Displaying Riders list--------");
       arrayOfRiders.forEach(s -> System.out.println(s.toString()));
       System.out.println();

   }
}

Code Screenshot:

Output:

1. Add a Rider

2. Remove a rider by name


3. Sort by zipcode

4. Search by state

5. Search by Full Name

**************Please do upvote to appreciate our time. Thank you!******************

Know the answer?
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
Similar Questions
2). Question with methods use scanner (Using Java): You are going to invest the amount, then...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then you going to compute that amount with annual interest rate. 1) Prompt the user to enter student id, student name, student major 2) Declare variables consistent with names that you are prompting and relate them to the scanner 3) Declare the amount invested in college, prompt the user to ask for amount and declare variable and scanner to input 4) Declare the annual interest...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
Part 1 - LIST Create an unsorted LIST class ( You should already have this code...
Part 1 - LIST Create an unsorted LIST class ( You should already have this code from a prior assignment ). Each list should be able to store 100 names. Part 2 - Create a Class ArrayListClass It will contain an array of 27 "list" classes. Next, create a Class in which is composed a array of 27 list classes. Ignore index 0... Indexes 1...26 correspond to the first letter of a Last name. Again - ignore index 0. index...
***Programming language is Java. After looking at this scenario please look over the requirements at the...
***Programming language is Java. After looking at this scenario please look over the requirements at the bottom (in bold) THIS IS ALL THAT WAS PROVIDED. PLEASE SPECIFY ANY QUESTIONS IF THIS IS NOT CLEAR (don't just say more info, be specific)*** GMU in partnership with a local sports camp is offering a swimming camp for ages 10-18. GMU plans to make it a regular event, possibly once a quarter. You have been tasked to create an object-oriented solution to register,...
Description In this project you will practice what we have learned in class about Design, ER...
Description In this project you will practice what we have learned in class about Design, ER Diagrams, Relational Models, DDL, SQL, CRUD (Create, Update, Delete) operations, associated queries, and mock data population. The goal is to create a realistic professional database/development experience. This assignment will describe the requirements for the database as you might receive them. You will need to fill in the details as you work on it. You will find that your work may be iterative, and you...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
In Assignment 1, you created a program for Marshall’s Murals that prompts a user for the...
In Assignment 1, you created a program for Marshall’s Murals that prompts a user for the number of interior and exterior murals scheduled to be painted during the next month. The program computes the expected revenue for each type of mural when interior murals cost $500 each and exterior murals cost $750 each. In this assignment, you are going to design a GUI version using Visual Studio Form. The programs prompt a user for the number of interior and exterior...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT