Question
Phase one implementation:

1-The menu of selections implemented in main function.

2- Each choice should be implemented in the main function.

3- The data is saved permanently in a file.
Problem Description: Assume one of the companies in Qatar who is renting flats for people asks you to develop a small system
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package abc;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Renter {

  
   public static List<String> readFullFile(String fileName)
   {
  
   List<String> lines = Collections.emptyList();
   try
   {
   lines =
   Files.readAllLines(Paths.get(fileName), StandardCharsets.UTF_8);
   }
  
   catch (IOException e)
   {
       e.printStackTrace();
   }
   return lines;
   }
  
   public static void displayAllRenters(String fileName)
   {
       List<String> renterList = readFullFile(fileName);
      
       System.out.println("Renter ID\t Renter Name\t Flat Number\t Fine\t Status\t");
      
       for(String obj : renterList)
       {
           String splitObj[] =obj.split("[|]");
           for(int i = 0; i < splitObj.length;i++ )
           {
               System.out.print(splitObj[i]+"\t ");
           }
           System.out.println();
       }
   }
  
   public static void displayRenterByFlat(String fileName,String flatNum)
   {
       List<String> renterList = readFullFile(fileName);
       boolean flag=false;
      
       System.out.println("Renter ID\t Renter Name\t Flat Number\t Fine\t Status\t");
      
       for(String obj : renterList)
       {
           String splitObj[] =obj.split("[|]");
           for(int i = 0; i < splitObj.length;i++ )
           {
               if(splitObj[2].equals(flatNum))
               {
                   System.out.print(splitObj[i]+"\t ");
                   flag=true;
               }
           }
          
       }
       if(!flag)
           System.out.println("Here is no information saved on such Flat Number");
   }
  
   public static void displayRenterNotPaid(String fileName)
   {
       List<String> renterList = readFullFile(fileName);
      
       System.out.println("Renter ID\t Renter Name\t Flat Number\t Fine\t Status\t");
      
       for(String obj : renterList)
       {
           String splitObj[] =obj.split("[|]");
           for(int i = 0; i < splitObj.length;i++ )
           {
               if(splitObj[4].equalsIgnoreCase("Not_Paid"))
               {
                   System.out.print(splitObj[i]+"\t ");
               }
           }
           System.out.println();
       }
   }
public static void writeToFile(String fileName,
String str)
{
   try {
      
       File file = new File(fileName);

       // if file doesnt exists, then create it
       if (!file.exists()) {
           file.createNewFile();
       }
  
       // Open given file in append mode.
       BufferedWriter out = new BufferedWriter( new FileWriter(fileName, true));
       out.write(str);
       out.close();
       System.out.println("Record Added");
   }
   catch (IOException e) {
       System.out.println("exception occoured" + e);
   }
}
   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
   //   String renterList[] ;
       Scanner sc = new Scanner(System.in);  
       boolean flag =true;
       String del ="|";
       int input;
       String fileName = "Rentfile.txt";
       String renterId, renterName,flatNum,fine,status;
      
       while(flag==true)
       {
           System.out.println("Menu:\n1.Add a New Rent Record\n2.Display all renters' information\n"
                   + "3.Search for rent information by Flat number\n"
                   + "4.Display all rent information that are not paid yet.\n"
                   + "5.Exit");
           input = sc.nextInt();
          
           switch(input)
           {
           case 1:
               System.out.println("Enter Renter ID : ");
               renterId = sc.next();
               System.out.println("Enter Renter Name (First Name and Last Name: ");
               renterName = sc.nextLine()+" "+sc.nextLine();
                 
               System.out.println("Enter Flat Number : ");
               flatNum = sc.next();
               System.out.println("Enter Fine : ");
               fine = sc.next();
               System.out.println("Enter Status : ");
               status = sc.next();
              
               String rec = renterId+ del + renterName + del +flatNum + del + fine+ del+ status+"\n";
               writeToFile(fileName,rec);
              
               break;
              
           case 2:
               displayAllRenters(fileName);
               break;
              
           case 3:
               System.out.println("Enter Flat Number: ");
               flatNum= sc.next();
               displayRenterByFlat(fileName, flatNum);
               break;
           case 4:
               displayRenterNotPaid(fileName);
               break;
              
           case 5:
               flag =false;
               break;
              
           default :
               System.out.println("Invalid Input");
              
              
           }
          
          
       }
      
       System.out.println("Thank you for using our Menu Services");
   }

}

//**************//

/*

Methods Name are self Explanatory

Output:

Menu:
1.Add a New Rent Record
2.Display all renters' information
3.Search for rent information by Flat number
4.Display all rent information that are not paid yet.
5.Exit
2
Renter ID   Renter Name   Flat Number   Fine   Status  
223   Sami Ahmed   A7   6000   Paid     
333   Sourabh kumar   501   2000   Not_Paid     
Menu:
1.Add a New Rent Record
2.Display all renters' information
3.Search for rent information by Flat number
4.Display all rent information that are not paid yet.
5.Exit
2
Renter ID   Renter Name   Flat Number   Fine   Status  
223   Sami Ahmed   A7   6000   Paid     
333   Sourabh kumar   501   2000   Not_Paid     

Menu:
1.Add a New Rent Record
2.Display all renters' information
3.Search for rent information by Flat number
4.Display all rent information that are not paid yet.
5.Exit

4
Renter ID   Renter Name   Flat Number   Fine   Status  

333   Sourabh kumar   501   2000   Not_Paid     
Menu:
1.Add a New Rent Record
2.Display all renters' information
3.Search for rent information by Flat number
4.Display all rent information that are not paid yet.
5.Exit
3
Enter Flat Number:
501
Renter ID   Renter Name   Flat Number   Fine   Status  

333   Sourabh kumar   501   2000   Not_Paid     
Menu:
1.Add a New Rent Record
2.Display all renters' information
3.Search for rent information by Flat number
4.Display all rent information that are not paid yet.
5.Exit

3
Enter Flat Number:
eee
Renter ID   Renter Name   Flat Number   Fine   Status  
Here is no information saved on such Flat Number
Menu:
1.Add a New Rent Record
2.Display all renters' information
3.Search for rent information by Flat number
4.Display all rent information that are not paid yet.
5.Exit
5
Thank you for using our Menu Services

*/

Add a comment
Know the answer?
Add Answer to:
Phase one implementation: 1-The menu of selections implemented in main function. 2- Each choice should be...
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
  • Serve the user in two phases: In C++ Phase A: (1) Read all input records one...

    Serve the user in two phases: In C++ Phase A: (1) Read all input records one by one into arrays in main memory. (2) Display all the records on the screen in the order they are read from the input data file. (3) Do a Selection Sort (must be implemented as a function) to sort the records in ascending order on STUDENT_ID and display all the full records correctly in the correct order after sorting. Phase B: (1) Then, the...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

  • You are given a file that contains employee data. The first entry in the file indicates...

    You are given a file that contains employee data. The first entry in the file indicates the number of employees stored in the file. After that, each entry in the file consists of the name of the employee, job title, number of promotions since hiring on, and the years the promotions occured. For example, one possible entry in the employee data file might be Mario Speedwagon Systems Engineer 2 2003 2006 which indicates that Mario Speedwagon is a Systems Engineer...

  • the OOP project is needed to be coded in netbeans and store a information in file...

    the OOP project is needed to be coded in netbeans and store a information in file on local machine it could be stored with xml tags since its easier. OOP Project Description Requirements: You are to design and build software media rental system. The software will track each user’s account with its rentals. A user can rent multiple media of different type/genre and all that user’s rentals are managed under their account (single account per user). A user will be...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • Java Computer Labs Assignment! The code NEEDS to be commented properly! Every class file should have a header comment that includes your name and assignment number and briefly documents what the prog...

    Java Computer Labs Assignment! The code NEEDS to be commented properly! Every class file should have a header comment that includes your name and assignment number and briefly documents what the program does! If there are known deficiencies with your program such as known problems or incomplete features, these should be clearly listed in the header comment! Every method should have a method header comment that documents what the method does, what its parameters are, and what it returns! You...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • Assignment on Java programing 1. Write programs for the following exercises in Java. Each file should...

    Assignment on Java programing 1. Write programs for the following exercises in Java. Each file should have short description of the implemented class and for files with main method the problem it is solving. Make sure your files have appropriate names. Programs should write output to the Console. b) BST: Implement Binary Search Tree ADT with insert(int key), delete(int key), Node find(int key), and in-order traverse() where it prints the value of the key. Your operations should use recursion. The...

  • You will be developing an Advising Scheduling Management System (ASMS) that can be used managing the advising appointments for Salisbury University professors and their advisees (students). ASMS shoul...

    You will be developing an Advising Scheduling Management System (ASMS) that can be used managing the advising appointments for Salisbury University professors and their advisees (students). ASMS should have the following functionalities: - There are three kinds of users: professor, student and admin. When ASMS starts, a login screen asks user which kinds of users and then asks user id and password. If id or password are incorrect, issue a warning and redisplay the login screen. - When an admin...

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