Click here to Skip to main content
15,893,564 members
Home / Discussions / Java
   

Java

 
AnswerRe: Biometric attendace machine data Pin
Richard MacCutchan4-Oct-19 3:19
mveRichard MacCutchan4-Oct-19 3:19 
AnswerRe: Biometric attendace machine data Pin
Gerry Schmitz4-Oct-19 6:35
mveGerry Schmitz4-Oct-19 6:35 
QuestionNeed to develop a program on Java for desktop Pin
Ryder Weber1-Oct-19 3:32
Ryder Weber1-Oct-19 3:32 
AnswerRe: Need to develop a program on Java for desktop Pin
Richard MacCutchan1-Oct-19 4:13
mveRichard MacCutchan1-Oct-19 4:13 
AnswerRe: Need to develop a program on Java for desktop Pin
Gerry Schmitz4-Oct-19 20:35
mveGerry Schmitz4-Oct-19 20:35 
Questionhow to reuse open browser in java selenium? Pin
nadavrock29-Sep-19 19:23
nadavrock29-Sep-19 19:23 
AnswerRe: how to reuse open browser in java selenium? Pin
Leanbridge Technologies1-Nov-19 23:07
professionalLeanbridge Technologies1-Nov-19 23:07 
QuestionJava Cant pass the value that user input as the string and view it Pin
raigen27-Sep-19 5:44
raigen27-Sep-19 5:44 
First off I am a newbie and I hope you can understand what I trying to imply, thanks for understanding.

the problem is its seem my method cant pass the string value that inputted by user

Imgur: The magic of the Internet[^]







I want to convert the input of faculty id and name as one string and return it as string when show the data.

this is the uml view, I aware the uml may differ with my code, but the big picture of implementation still same.

[^]

this is the code that solely focus on Faculty view
the fragment of the code is here

Data access object contain method add, delete, show
Java
package penugasan;
public class DataAccesObject {
    private Database dataBase;
    private long currentFalcutyID;
    private String currentFalcutyName;
    private long currentStudentID;
    private String currentStudentName;
    public String string;
    public String name;



    public DataAccesObject() {
        this.dataBase = new Database();
    }

    public boolean deleteFaculty(Long ID){
        final Faculty[] faculty = this.dataBase.getFaculty();
        for (int i = 0; i < faculty.length; ++i) {
            if (faculty[i] != null && faculty[i].getID().equals(ID)) {
                faculty[i] = null;
                return true;
            }
        }
        return false;
    }

    public boolean createFaculty(Long ID, String name){
        final Faculty faculty = new Faculty(ID, name);
        this.currentFalcutyID = ID;
        this.currentFalcutyName = name;
        final Faculty[] faculty2 = this.dataBase.getFaculty();
        if (faculty2[ID.intValue()] == null) {
            faculty2[ID.intValue()] = faculty;
            return true;
        }
        return false;

    }
   
    //convert value to string and pass it as paramater to showFaculty in facultyView
    public String readFaculties(){
        String string = "";
        final Faculty[] faculty = this.dataBase.getFaculty();
        for (int i = 0; i < faculty.length; ++i) {
            if (faculty[i] != null) {
                string = string + faculty[i].getID() + " " + faculty[i].getName() + "\n";
            }
        }
        //this.string = string;
        return string;
    }

    //find faculty by input name
    public Faculty readFacultyByName(String name){
        final Faculty[] faculty = this.dataBase.getFaculty();
        for (int i = 0; i < faculty.length; ++i) {
            if (faculty[i] != null && faculty[i].getName().equals(name)) {
                return faculty[i];
            }
        }
        return null;
    }
}


Facultyview
Java
package penugasan;

import java.util.Scanner;

public class FacultyView {
    private DataAccesObject dao;
    public String name;
    public FacultyView(DataAccesObject dao) {
        this.dao = dao;
    }
		
    public void start() {
    	// cant grab the string value from readFaculties
        this.showFaculty(this.dao.readFaculties());
        System.out.println("Faculty View Menu : ");
        System.out.println("1 Create Faculty");
        System.out.println("2 Delete Faculty");
        System.out.println("3 Main Menu");
        System.out.print("Input your choice : ");
        final String nextLine = new Scanner(System.in).nextLine();
        if (nextLine.equals("1")) {
            this.createFaculty();
        }
        else if (nextLine.equals("2")) {
            this.deleteFaculty();
        }
        else {
            if (nextLine.equals("3")) {
                return;
            }
            System.out.println("Unrecognize Menu\n\n");
            this.start();
        }
    }


    //print the string
    public void showFaculty(final String name) {
        System.out.println("\n\nList Of Faculty : ");
        System.out.println(name);
    }

    public void createFaculty() {
        System.out.print("\nInput ID : ");
        final String nextLine = new Scanner(System.in).nextLine();
        System.out.print("Input Name : ");
        final String nextName = new Scanner(System.in).nextLine();
        this.dao.createFaculty(Long.parseLong(nextLine), nextName);
        this.start();
    }

    public void deleteFaculty() {
        System.out.print("\nInput ID : ");
        this.dao.deleteFaculty(Long.parseLong(new Scanner(System.in).nextLine()));
        this.start();
    }
}


Class Database to store array of Faculty
Java
package penugasan;
public class Database{
    private Faculty[] faculties;


    public Database() {
        Faculty faculty = new Faculty();
    }

    public Faculty[] getFaculty() {

        //Long facultyID = super.getCurrentFalcutyID();
        //String facultyName = super.getCurrentFalcutyName();

        this.faculties = new Faculty[10];
        return faculties;
    }
}



Java
package penugasan;

import java.util.Scanner;

/// Main class
public class Test {
    public static void main(String[] args) {
        DataAccesObject dao = new DataAccesObject();
        FacultyView facultyView = new FacultyView(dao);
        StudentView studentView = new StudentView(dao);

        while(true){
            System.out.println("\nMain Menu : ");
            System.out.println("1. Student");
            System.out.println("2. Faculty");
            System.out.println("3. Exit");
            System.out.println("Input your choice : ");

            Scanner scanner = new Scanner(System.in);
            String choice = scanner.nextLine();
            if (choice.equals("1")){
                studentView.start();
            }else if (choice.equals("2")){
                facultyView.start();
            }else if(choice.equals("3")){
                System.exit(0);
            }else {
                System.out.println("Wrong Choice");
            }
        }
    }
}



for full code here
https://codeshare.io/G88rDB[^]

modified 27-Sep-19 20:58pm.

AnswerRe: Java Cant pass the value that user input as the string and view it Pin
Richard MacCutchan27-Sep-19 6:56
mveRichard MacCutchan27-Sep-19 6:56 
GeneralRe: Java Cant pass the value that user input as the string and view it Pin
raigen27-Sep-19 14:52
raigen27-Sep-19 14:52 
GeneralRe: Java Cant pass the value that user input as the string and view it Pin
Richard MacCutchan27-Sep-19 21:48
mveRichard MacCutchan27-Sep-19 21:48 
QuestionJava Swing app dragging and dropping components with snapping Pin
Member 1457730716-Sep-19 5:27
Member 1457730716-Sep-19 5:27 
AnswerRe: Java Swing app dragging and dropping components with snapping Pin
Richard MacCutchan16-Sep-19 6:22
mveRichard MacCutchan16-Sep-19 6:22 
GeneralWhich language is best for developing sms api java Or .net ? Pin
Msg Club3-Sep-19 22:30
Msg Club3-Sep-19 22:30 
GeneralRe: Which language is best for developing sms api java Or .net ? Pin
OriginalGriff3-Sep-19 22:40
mveOriginalGriff3-Sep-19 22:40 
GeneralRe: Which language is best for developing sms api java Or .net ? Pin
MadMyche10-Sep-19 8:16
professionalMadMyche10-Sep-19 8:16 
GeneralRe: Which language is best for developing sms api java Or .net ? Pin
Wishe199129-Sep-19 23:27
Wishe199129-Sep-19 23:27 
GeneralRe: Which language is best for developing sms api java Or .net ? Pin
ReolusTechnologies12-Nov-19 3:08
professionalReolusTechnologies12-Nov-19 3:08 
QuestionRestaurant Reservation java code Pin
Member 1456547721-Aug-19 22:12
Member 1456547721-Aug-19 22:12 
AnswerRe: Restaurant Reservation java code Pin
Richard MacCutchan21-Aug-19 22:18
mveRichard MacCutchan21-Aug-19 22:18 
QuestionRecommendation: Learn from GITHUB project Pin
Anisul Huq7-Aug-19 18:20
Anisul Huq7-Aug-19 18:20 
AnswerRe: Recommendation: Learn from GITHUB project Pin
Richard MacCutchan7-Aug-19 22:04
mveRichard MacCutchan7-Aug-19 22:04 
AnswerRe: Recommendation: Learn from GITHUB project Pin
Wishe199129-Sep-19 23:29
Wishe199129-Sep-19 23:29 
QuestionLearning from GITHUB projects Pin
Anisul Huq6-Aug-19 13:13
Anisul Huq6-Aug-19 13:13 
Questionhow to use class for sending notification in android? Pin
Member 145520336-Aug-19 2:53
Member 145520336-Aug-19 2:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.