Solved

Sever Client

Posted on 2007-11-15
24
211 Views
Last Modified: 2010-03-30
I have set up a server client in java. Recently addes in a new class dvd. Similar to my class reneters. I need to develop a method which will display either all the renters or all the dvds. Not sure how to do this. Obviously if i figure out one I can figure out the other. Any help appreciated

##########Server
import java.io.*;
import java.net.*;

public class DVDserver extends Thread {

    protected Admin myadmin;
    protected Socket s;

   
    DVDserver(Socket theSocket, Admin myadmin) {
        System.out.println("New client.");
        this.myadmin = myadmin;
        s = theSocket;
    }
   
    public void run() {

        PrintWriter toClient = null;
        BufferedReader fromClient = null;
        try {
            // Set up the input / output streams for the server
            toClient = new PrintWriter(s.getOutputStream(), true);
            fromClient = new BufferedReader(new InputStreamReader(s.getInputStream()));
                                       
            String inputLine; // holds line from client
            String surname, forename, username, title, classification, leadingCharacter, director;
            boolean available;
            int initialBalance, accNum, balance, amount, price, uniqueID;
           
            // Initiate conversation with client
            while ((inputLine = fromClient.readLine()) != null) {
                if (inputLine.equalsIgnoreCase("A")) {
                    System.out.println("New User Account");
                    forename= fromClient.readLine();
                    surname = fromClient.readLine();
                    username = fromClient.readLine();
                    inputLine = fromClient.readLine(); // read initial balance as string
                    initialBalance = Integer.parseInt(inputLine);
                    accNum = myadmin.newAccount(surname, forename, username, initialBalance);
                    toClient.println(accNum);             //send the client the account number
                   
                } else if (inputLine.equalsIgnoreCase("B")) {
                    System.out.println("Enter in admin No.");
                    accNum = Integer.parseInt(fromClient.readLine());
                    forename = myadmin.getForename(accNum);
                    toClient.println("Forename: "+ forename);
                    surname = myadmin.getSurname(accNum);
                    toClient.println("Surname: "+ surname);
                    username = myadmin.getUsername(accNum);
                    toClient.println("User Name: "+ username);
                    balance= myadmin.getBalance(accNum);
                    toClient.println("Oustanding Balance: " + balance);
                }
                    else if (inputLine.equalsIgnoreCase("C")) {
                        System.out.println("Outstanding Balance: deduct");
                        accNum = Integer.parseInt(fromClient.readLine());
                        amount = Integer.parseInt(fromClient.readLine());
                        balance= myadmin.debit(accNum,amount);
                        toClient.println(balance); //sends the new balance after money was taken off
                    }
                    else if (inputLine.equalsIgnoreCase("D")) {
                        System.out.println("Outstanding Balance: credit");
                        accNum = Integer.parseInt(fromClient.readLine());
                        amount = Integer.parseInt(fromClient.readLine());
                        balance= myadmin.credit(accNum,amount);
                        toClient.println(balance); //sends the new balance after money was taken off
                    }  
                    else if   (inputLine.equalsIgnoreCase("E")) {
                            System.out.println("Enter DVD ID");
                            title= fromClient.readLine();
                            classification = fromClient.readLine();
                            leadingCharacter = fromClient.readLine();
                            director = fromClient.readLine();
                            available = "available".equalsIgnoreCase(fromClient.readLine().trim());
                            inputLine = fromClient.readLine(); // read initial balance as string
                            price= Integer.parseInt(inputLine);
                            uniqueID = myadmin.newDVD(title, classification, leadingCharacter, director, available, price);
                            toClient.println(uniqueID);             //send the client the account number
                    }else {
                System.out.println("Unknown command");
            }
            if (inputLine.equals("exit"))
                break;
            }
                // Close all streams
                System.out.println("Closing Echo Server...");
                toClient.close();
                fromClient.close();
                s.close();
               
            } catch (IOException ioe) {
                System.out.println("IO Exception: " + ioe);
                System.exit(1);
            }
        } // run
       
    } // DVDserverapp

######DVDClient
import java.io.*;
import java.net.*;

public class DVDClient {

    public static void main(String[] args) throws IOException {

        Socket serverSocket = null;
        PrintWriter toServer = null;
        BufferedReader fromServer = null;
        String remoteServer;
 
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please provide the server ip address");
        remoteServer=stdIn.readLine();
       
        try {
            // Try connecting to the 'remote' machine on port 4445
            serverSocket = new Socket(remoteServer, 4445);
            toServer = new PrintWriter(serverSocket.getOutputStream(), true);
            fromServer = new BufferedReader(new InputStreamReader(
                                        serverSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: " + remoteServer);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for "
                               + "the connection to: " + remoteServer);
            System.exit(1);
        } // try-catch

 
                                     

        String userInput, forename, surname, username, balance, reply, accNum, amount,
        title, classification, leadingCharacter, director, price, uniqueID;
        boolean available;

   
        do {
              
              System.out.println("Please select one of the following options");
              System.out.println("a. Add new renter account");
              System.out.println("b. Retrieve a renters details");
              System.out.println("c. Deduct oustanding balance of a renter");
              System.out.println("d. Add to a renters oustanding balance");  
              System.out.println("e. Add new DVD to collection");
              System.out.println("f. List all the DVD's");
              System.out.println("g. List all the renters currently signed up:");
              System.out.println("<EXIT> to exit program");              
              System.out.print("Option: ");
            userInput = stdIn.readLine();
           
            if (userInput.equalsIgnoreCase("A")) {
                    System.out.println("");
                System.out.print("Forename:  ");
                forename = stdIn.readLine();
                System.out.print("Surname:  ");
                surname = stdIn.readLine();
                System.out.print("username:  ");
                username = stdIn.readLine();
                System.out.print("Set outstanding balance if any: ");
                balance = stdIn.readLine();
                toServer.println(userInput);
                toServer.println(forename);
                toServer.println(surname);
                toServer.println(username);
                toServer.println(balance);
                reply = fromServer.readLine();
                System.out.println("Acount Number:  " + reply);
                System.out.println("");
            }
                else if (userInput.equalsIgnoreCase("B")) {
                        System.out.println("");
                    System.out.print("Renters Account Number: ");
                    accNum = stdIn.readLine();
                    toServer.println(userInput);
                    toServer.println(accNum);
                    reply = fromServer.readLine();
                    System.out.println(reply); //forename
                    reply = fromServer.readLine();
                    System.out.println(reply); //surname
                        reply = fromServer.readLine();
                        System.out.println(reply); //username
                          reply = fromServer.readLine();
                          System.out.println(reply);  // outstanding balance
                        System.out.println(""); }
           
                else if (userInput.equalsIgnoreCase("C")) {
                        System.out.println("");
                    System.out.print("Renters Account Number:  ");
                    accNum = stdIn.readLine();
                    System.out.print("Amount to be deducted: ");
                    amount = stdIn.readLine();
                    toServer.println(userInput);
                    toServer.println(accNum);
                    toServer.println(amount);
                    reply = fromServer.readLine();
                    System.out.println("New oustanding balance stands at " + reply);
                    System.out.println("");
                   
            }                
                else if (userInput.equalsIgnoreCase("D")) {
                  System.out.println("");
                System.out.print("Renters Account Number:  ");
                accNum = stdIn.readLine();
                System.out.print("Amount to be credited: ");
                amount = stdIn.readLine();
                toServer.println(userInput);
                toServer.println(accNum);
                toServer.println(amount);
                reply = fromServer.readLine();
                System.out.println("New oustanding balance stands at " + reply);
                System.out.println("");
                    System.out.println("");
                }
                else if (userInput.equalsIgnoreCase("E")) {
                        System.out.println("");
                    System.out.print("DVD ID:  ");
                        System.out.print("Title:  ");
                    title = stdIn.readLine();
                    System.out.print("Classification:  ");
                    classification = stdIn.readLine();
                    System.out.print("Leading Character:  ");
                    leadingCharacter = stdIn.readLine();
                    System.out.print("Director:  ");
                    director = stdIn.readLine();
                    System.out.print("Available: ");
                    available = "available".equalsIgnoreCase(fromServer.readLine().trim());
                    System.out.print("Price: ");
                    price= stdIn.readLine();
                    toServer.println(title);
                    toServer.println(classification);
                    toServer.println(leadingCharacter);
                    toServer.println(director);
                    toServer.println(available);
                    toServer.println(price);
                    reply = fromServer.readLine();
                    System.out.println("Unique ID Assigned:  " + reply);
                    System.out.println("");
        }      
               
 else {
               
            }
        } while (!userInput.equalsIgnoreCase("Exit"));
   
        toServer.close();
        fromServer.close();
        stdIn.close();
        serverSocket.close();
    } // main
   
} // DVDClient

#############DVDserverapp
import java.io.*;
import java.net.*;

public class DVDServerApp {

    public static void main(String[] args) throws IOException {

        int port = 4445;
       
        // Set up the 'server socket' connection
        ServerSocket sSocket = null;
        try {
            sSocket = new ServerSocket(port);
        } catch (IOException e) {
            System.out.println("Problem listening to: " + port + "; " + e);
            System.exit(1);
        }
       
        while(true) {
            System.out.println("Waiting for client...");
           
            // Set up the client socket
            Socket client;
            client = sSocket.accept();
            System.out.println("Connection established " + client.getInetAddress());
           
            // Initiate a server thread and start it
            DVDserver c = new DVDserver(client, new Admin());
            c.start();
        }
    } // main
   
} // DVDServerApp

#########Methods saved in admin.java


public class Admin
{

      // DECLARING THE USER ACCOUNT VARIABLES
      private static final int MAX_ACCOUNTS = 100;
      private int currentTotal = 0;
      private int currentAccNum = 1;

      Renter renters[] = new Renter[MAX_ACCOUNTS];

      // declaring our DVD VARIABLES
      private final int MAX_DVD = 1000;
      private int currentDVDTotal = 0;
      private int currentUniqueID = 1;

      DVD DVDs[] = new DVD[MAX_DVD];

      public synchronized int newAccount(String forename, String surname,
              String username, int initialBalance)
      {
            // Generates a new account and returns the account
            // number if successful, otherwise returns 0.
            if (currentTotal < MAX_ACCOUNTS)
            {
                  currentAccNum++;
                  renters[currentTotal++] = new Renter(forename, surname, username,
                          initialBalance, currentAccNum);
                  return currentAccNum;
            }
            else
            {
                  return 0;
            }
      } // newAccount

      public synchronized int newDVD(String title, String classification,
              String leadingCharacter, String director, boolean available,
              int price)
      {
            // Generates a new account and returns the account
            // number if successful, otherwise returns 0.
            if (currentDVDTotal < MAX_DVD)
            {
                  currentUniqueID++;

                  DVDs[currentDVDTotal++] = new DVD(title, classification,
                          leadingCharacter, director, available, price,
                          currentUniqueID);
                  return currentUniqueID;
            }
            else
            {
                  return 0;
            }
      } // newAccount

      public synchronized int getBalance(int accNum)
      {
            Renter acc;
            acc = findAcc(accNum);
            if (acc != null)
            {
                  return acc.getBalance();
            }
            else
            {
                  return 0;
            }
      } // getBalance

      public synchronized String getForename(int accNum)
      {
            Renter acc;
            acc = findAcc(accNum);
            if (acc != null)
            {
                  return acc.getForename();
            }
            else
            {
                  return "";
            }
      } // getforename

      public synchronized String getSurname(int accNum)
      {
            Renter acc;
            acc = findAcc(accNum);
            if (acc != null)
            {
                  return acc.getSurname();
            }
            else
            {
                  return "";
            }
      } // getSurname

      public synchronized String getUsername(int accNum)
      {
            Renter acc;
            acc = findAcc(accNum);
            if (acc != null)
            {
                  return acc.getUsername();
            }
            else
            {
                  return "";
            }
      } // getSurname

      public synchronized int credit(int Renter, int amount)
      {
            Renter acc;
            acc = findAcc(Renter);
            if (acc != null)
            {
                  acc.credit(amount);
                  return getBalance(Renter);
            }
            else
            {
                  return 0;
            }
      } // deposit

      public synchronized int debit(int Renter, int amount)
      {
            Renter acc;
            acc = findAcc(Renter);
            if (acc != null)
            {
                  acc.debit(amount);
                  return getBalance(Renter);
            }
            else
            {
                  return 0;
            }
      } // debit

      public synchronized String convertToString()
      {
            String str = "";

            for (int i = 0; i < currentTotal; i++)
            {
                  str = str + renters[i].convertToString() + "\n";
            }
            return str;
      } // convertToString

      private synchronized Renter findAcc(int accountNum)
      {
            for (int i = 0; i < currentTotal; i++)
            {
                  if (renters[i].getAccountNum() == accountNum)
                        return renters[i];
            }
            return null;
      }

      // Create a few accounts. Used for testing
     
      Admin()
      {
            this.newAccount("Ali", "Shaw", "ashaw", 100);
            this.newAccount("Aaron", "Boyle", "aboyle", 200);
            this.newAccount("Cilla", "Black", "cblack", 10);
            this.newAccount("Hugh", "Brown", "hBrown", 50);
            this.newAccount("Barry", "White", "BWhite", 80);
           
            this.newDVD("APOCALYPSE NOW", "18", "Martin Sheen", "Francis Ford Coppola", true, 2);
            this.newDVD("2001:SPACE ODYSSEY", "PG", "William Daniels", "Stanley Kubricks", true, 2);
            this.newDVD("ELEPHANT MAN", "PG", "John Hurt", "Joseph Merrick", true, 2);
            this.newDVD("THE FISHER KING", "15", "Robin Williams", "Roger Crow", false, 2);
            this.newDVD("CARLITO'S WAY", "18", "Al Pacino", "Brian Del Palma", true, 2);
            this.newDVD("WALL STREET", "15", "Michael Doglas", "Oliver Stone", true, 2);
            this.newDVD("ONE FLEW OVER THE CUCKOO'S NEST", "18", "Jack Nicholson", "Milos Forman", true, 2);
            this.newDVD("JACOBS LADDER ", "18", "Tim Robbins", "Adrian Lyne", true, 2);
            this.newDVD("THE INDIAN RUNNER", "unrated", "Charles Bronson", "Sean Penn", false, 2);
            this.newDVD("THE LAST TEMPTATION OF CHRIST", "18", "Harvey Keitel", "William Dafoe", false, 2);
            this.newDVD("PLATOON", "15", "Johny Depp", "Charlie Sheen", false, 2);
            this.newDVD("A RIVER RUNS THROUGH IT", "PG", "Bradd Pitt", "Craig Sheffer", false, 2);
            this.newDVD("TAXI DRIVER", "18", "Robert De Niro", "Martin Scorsese", false, 2);
            this.newDVD("BORN ON THE FOURTH OF JULY ", "18", "Tom Cruise", "Oliver Stone", false, 2);
            this.newDVD("DAS BOOT", "12", "Jürgen Prochnow", "Wolfgang Petersen", false, 2);
            this.newDVD("REAR WINDOW", "PG", "James Stewart", "Alfred Hitchcok", false, 2);
           
      } // Accounts and DVDs created
     
} // admin

class Renter
{

      private String forename;
      private String surname;
      private String username;
      private int balance;
      private int accountNum;

      Renter(String forename, String surname, String username,
              int initialBalance, int accountNum)
      {

            this.forename = forename;
            this.surname = surname;
            this.username = username;
            this.balance = initialBalance;
            this.accountNum = accountNum;
      } // Renter

      public int getBalance()
      {
            return balance;
      }

      public int getAccountNum()
      {
            return accountNum;
      }

      public void credit(int amount)
      {
            balance += amount;
      }

      public void debit(int amount)
      {
            balance -= amount;
      }

      public String getForename()
      {
            return forename;
      }

      public String getSurname()
      {
            return surname;
      }

      public String getUsername()
      {
            return username;
      }

      public String convertToString()
      {
            return (forename + "\t" + surname + "\t" + username + "\t" + accountNum
                    + "\t" + balance);
      }

} // Renter

class DVD
{

      private String title;
      private String classification;
      private String leadingCharacter;
      private String director;
      private boolean available;
      private int price;
      private int uniqueID;

      DVD(String title, String classification, String leadingCharacter,
              String director, boolean available, int price, int uniqueID)
      {

            this.title = title;
            this.classification = classification;
            this.leadingCharacter = leadingCharacter;
            this.director = director;
            this.price = price;
            this.available = available;
            this.uniqueID = uniqueID;
      } // DVD


      public String getTitle()
      {
            return title;
      }

      public String getClassification()
      {
            return classification;
      }

      public String getLeadingCharacter()
      {
            return leadingCharacter;
      }
}
0
Comment
Question by:bigbong00
  • 14
  • 7
  • 3
24 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Each  class should have its own toString implementation. This will then allow you to iterate your arrays and do

System.out.println(array[i].toString());

Simply retuen a String in that method containing the details you want
0
 

Author Comment

by:bigbong00
Comment Utility
could you explain more. I'm not sure how to implement what you've just said
0
 

Author Comment

by:bigbong00
Comment Utility
You answered a question concerning a boolean value I was having trouble implementing here
http://www.experts-exchange.com/Programming/Languages/Java/Q_22961296.html

There were some problems. Now i can no longer enter in values. It simply stops at "Available: "
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
public String toString() {
    return "ID = " + this.id; // etc
}
0
 

Author Comment

by:bigbong00
Comment Utility

so how do i put this which you've said

System.out.println(array[i].toString());

and this

public String toString() {
    return "ID = " + this.id; // etc
}

together. I'm only learning java. So I need a method that will display all the dvds and their details. Or a method that will display all the accounts
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Put the method inside the DVD class. Put the line (or something like it) where you want the DVD to be displayed
0
 

Author Comment

by:bigbong00
Comment Utility
OK I kind of figured it out myself

I created this method in my admin class

      public synchronized String printAllAcounts(String reply)
      {
            for(int n=0; n<currentTotal; n++ )
            {            reply = reply+ "Forename /t"+ renters[n].getSurname()+"/t";
                        reply = reply+ "Forename /t"+ renters[n].getSurname()+"/t";
                        reply = reply+ "Username /t"+ renters[n].getUsername()+"/n";
                  //System.out.println("Surname"+renters[n].getSurname());
                 // System.out.println("Forename"+renters[n].getUsername());
                 // System.out.println("username"+renters[n].getUsername());
            }
            return reply;
      } // getSurname

and made this change to my server

                    else if   (inputLine.equalsIgnoreCase("F")) {
                        String reply = "";
                          reply = myadmin.printAllAcounts(reply);
                          toClient.println(reply);

and this to my client

        }                       else if (userInput.equalsIgnoreCase("F")) {
                                      System.out.println("");
                                      System.out.print("Renters Currently on system:  ");
                                      reply = fromServer.readLine();
                                      System.out.println(reply);
                                      

But when i use the option f at command prompt it will print out the line  "Renters Currently on system: " and wont't really move from there. Do you know how I could fix this
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
you need to send command to server:

                                      System.out.println("");
                                      System.out.print("Renters Currently on system:  ");
                                      toServer.println("F");
                                      reply = fromServer.readLine();
                                      System.out.println(reply);
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
you have another problem though in that it'll only read a single line.

>                         reply = reply+ "Username /t"+ renters[n].getUsername()+"/n";

on the server change that to:

                        reply = reply+ "Username /t"+ renters[n].getUsername()+"|";

That'll return the result in a single line (using the | to mark where new lines need to be)

>                                       System.out.println(reply);

and on the client change that to:

String[] lines = reply.split("|");
for (String line: lines)
{
     System.out.println(line);
}

that splits the lines on the client side
0
 

Author Comment

by:bigbong00
Comment Utility
This is now my code now for the server

It doesnt work

                    else if   (inputLine.equalsIgnoreCase("F")) {
                        String reply = "";
                          reply = myadmin.printAllAcounts;               ######problem here
                          toClient.println(reply); //      toClient

And i have made the alterations to the admin class as stated. But it is putting sending this result from the server

      public synchronized String printAllAcounts(String reply)
      {
            for(int n=0; n<currentTotal; n++ )
            {            reply = reply+ "Forename /t"+ renters[n].getSurname()+"/t";
                        reply = reply+ "Forename /t"+ renters[n].getSurname()+"/t";
                        reply = reply+ "Username /t"+ renters[n].getUsername()+"|";
            }
            return reply;
      } // getSurname
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> reply = myadmin.printAllAcounts;

should be:

reply = myadmin.printAllAcounts();
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
actually change it to this:

                    else if   (inputLine.equalsIgnoreCase("F")) {
                          String reply = myadmin.printAllAcounts();
                          toClient.println(reply); //      toClient




      public synchronized String printAllAcounts()
      {
            String reply = "";
            for(int n=0; n<currentTotal; n++ )
            {            reply = reply+ "Forename /t"+ renters[n].getSurname()+"/t";
                        reply = reply+ "Forename /t"+ renters[n].getSurname()+"/t";
                        reply = reply+ "Username /t"+ renters[n].getUsername()+"|";
            }
            return reply;
      } // getSurname
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:bigbong00
Comment Utility
Still the same problem. It prints out "renters currently on system: " then stops

Soi have this method in my admin class

      public synchronized String printAllAcounts()
      {
            String reply = "";
            for(int n=0; n<currentTotal; n++ )
            {            reply = reply+ "Forename /t"+ renters[n].getSurname()+"/t";
                        reply = reply+ "Forename /t"+ renters[n].getSurname()+"/t";
                        reply = reply+ "Username /t"+ renters[n].getUsername()+"|";
            }
            return reply;
      } // PrintAllaccounts

This piece of code in my client
           else if (userInput.equalsIgnoreCase("F")) {
                          System.out.println("");
                          System.out.print("Renters Currently on system:  ");
                          reply = fromServer.readLine();
                            String[] lines = reply.split("|");
                            for (String line: lines)
                            {
                                 System.out.println(line);
                            }

And this code in my server

                    else if   (inputLine.equalsIgnoreCase("F")) {
                        String reply = myadmin.printAllAcounts();
                        toClient.println(reply); //      toClient

But it doesnt print out anything
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
you haven't added the ine to send command i posted earleir

                                      toServer.println("F");

put that before you read response from server
0
 

Author Comment

by:bigbong00
Comment Utility
ok it is kind of working now to it is printing a letter, new line, letter new line (prints out  name but each character is on a new line and is ) etc followed by /t after it prints out surname, forename etc then it moves onto the next account and same thing

I'm pretty impressed even though it is displaying like it does
0
 

Author Comment

by:bigbong00
Comment Utility
Got it working. Thanks objects
0
 

Author Comment

by:bigbong00
Comment Utility
have you any idea how i could create a method that would allow me to enter a users id and edit their details?
0
 

Author Comment

by:bigbong00
Comment Utility
Well it is kind of working

      public synchronized String printAllAcounts()
      {
            String reply = "";
            for(int n=0; n<currentTotal; n++ )
            {
                              reply = reply+ "Account Number: " + renters[n].getAccountNum() + " ";
                              reply = reply+ "Forename: " + renters[n].getSurname()+" ";
                        reply = reply+ "Forename: " + renters[n].getSurname()+" ";
                        reply = reply+ "Username: " + renters[n].getUsername()+"|";
            }
            return reply;
      } // PrintAllaccounts

And on the client
           else if (userInput.equalsIgnoreCase("G")) {
                  System.out.println("");
                  System.out.print("DVDs Currently on system:  ");
                  toServer.println("F");
                  reply = fromServer.readLine();
                        String[] lines = reply.split("|");
                        for (String line: lines)
                        {
                             System.out.print(line);
                        }

But i need it to take a new line after each username to indicate a new set of results
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
would be a two step process
first send a request to server to retrieve details
then present them to user for editting
then send a second request to server with the updated details
0
 

Author Comment

by:bigbong00
Comment Utility
Cheers. Though i don't have a clue how to implement this
0
 

Author Comment

by:bigbong00
Comment Utility
   public synchronized String printAllAcounts()
      {
            String reply = "";
            for(int n=0; n<currentTotal; n++ )
            {
                              reply = reply+ "Account Number: " + renters[n].getAccountNum() + " ";
                              reply = reply+ "Forename: " + renters[n].getSurname()+" ";
                        reply = reply+ "Forename: " + renters[n].getSurname()+" ";
                        reply = reply+ "Username: " + renters[n].getUsername()+"|";
            }
            return reply;
      } // PrintAllaccounts
     
      public synchronized String printAllDVDs()
      {
            String reply = "";
            for(int n=0; n<currentTotal; n++ )
            {            
                  reply = reply + " Unique ID: " +DVDs[n].getDVDID() + " ";
                  reply = reply + " Title: " +DVDs[n].getTitle() + " ";
                  reply = reply + " Classification: "+DVDs[n].getClassification()+ " ";
                  reply = reply + " Leading Character: "+DVDs[n].getLeadingCharacter();
                  reply = reply + "  Director: " +DVDs[n].getDirector() + " ";
                  reply = reply + "  Availability: "+DVDs[n].getAvailable() + " ";
                  reply = reply + "|";
            }
            return reply;
      } // print AllDVDs

Created the two methods here but i need a line that some code which will automatically take a new line after available (dvd) or for the orther method username (accounts)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
what do you need the new line for exactly?
0
 

Author Comment

by:bigbong00
Comment Utility
Just for presentation
0
 

Author Comment

by:bigbong00
Comment Utility
I've added another questiuon here if you could have a look
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Performance issue while iterating with streams 5 39
count8 challlenge 13 84
for i loop in grovy 1 32
Unable to start eclipse ? 17 82
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now