Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
//Trying to store 4 max private first name, last name and Gender String Variables from Client.class from user input in main.Form.class

Java
import java.util.Scanner;
public class Form {
public static void main(String[] args) {

        Client clientObject = new Client();
	clientObject.setName();

{System.out.println
         ("Welcome to Form User Interface."); 
        
    System.out.println 
         ("Press: (Eneter) key to Continue");} 
	
         {Scanner s = new Scanner(System.in);
	    s.nextLine();}


if (personOne = null && personTwo = null && personThree = null && personFour = null){
       
       Client = new Client();
       System.out.println("add Clients first name\n");
       Scanner s = new Scanner (System.in);
       String First Name = scanner.next();

       System.out.println("add Clients last name\n");
       Scanner s = new Scanner (System.in);
       String Last Name = scanner.next();}

       System.out.println("what is clients Gender\n");
       Scanner s = new Scanner (System.in);
       String Gender = scanner.next();}
else{ 
       system.out.println("No space for new Client"); }}


i'm not sure how I get a new class (Client.class) to fully recognise 4 different Strings containing 3 seperate string variables (Client id 1,2,3,4 then First name, Last name and Gender)

I know my code looks like something a mad man made, But any help would be great, i have tried to look on google and have gone through the API for Java and im at a loss.

What I have tried:

Java
public class Client 
{        
        private string Client1;
        private string Client2;
        private string Client3;
        private string Client4;
        
        public Client(String name){
   
    
        private String First Name; 
	private String Last name;
        private String Gender
	
}


basically I know this code is rubbish and has to have completly different logic in order to work I just can't figure that out.

again, I need to know a way to store max 4 private strings that contain 3 fields that the user can decide and that can be stored in the second class and can be called upon as an object in the main form class.
Posted
Updated 25-Apr-18 1:10am
v2

1 solution

Sorry to have to agree with you but yes, your code is not at all well written. You keep creating new scanner objects, when you only need one. Your Client class just will not do what you expect, or anything else useful. I did not bother to look too hard at the rest.

You need to stop and do some serious study and learn how to create classes, and lists of objects, at minimum. Take a look at The Java™ Tutorials[^] for some really useful resources.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900