Solved

Sever Client

Posted on 2007-11-15
24
212 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
ID: 20290900
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
ID: 20290929
could you explain more. I'm not sure how to implement what you've just said
0
 

Author Comment

by:bigbong00
ID: 20290952
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
ID: 20290959
public String toString() {
    return "ID = " + this.id; // etc
}
0
 

Author Comment

by:bigbong00
ID: 20291035

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
ID: 20291492
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
ID: 20291733
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
ID: 20293361
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
ID: 20293464
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
ID: 20296817
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
ID: 20296833
> reply = myadmin.printAllAcounts;

should be:

reply = myadmin.printAllAcounts();
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 20296839
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:bigbong00
ID: 20296879
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
ID: 20296943
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
ID: 20296966
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
ID: 20296994
Got it working. Thanks objects
0
 

Author Comment

by:bigbong00
ID: 20296996
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
ID: 20297019
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
ID: 20297020
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
ID: 20297043
Cheers. Though i don't have a clue how to implement this
0
 

Author Comment

by:bigbong00
ID: 20297083
   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
ID: 20297116
what do you need the new line for exactly?
0
 

Author Comment

by:bigbong00
ID: 20297201
Just for presentation
0
 

Author Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

910 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

20 Experts available now in Live!

Get 1:1 Help Now