Click here to Skip to main content
14,355,618 members
   

Java

 
PinnedForum Guidelines - PLEASE READ Pin
Chris Maunder28-Jul-09 3:36
adminChris Maunder28-Jul-09 3:36 
Question!!Please Help!! Student Needs Help It Shows me exercise/ wrong catagory moved to web dev JS Pin
Member 1465076510-Nov-19 7:04
memberMember 1465076510-Nov-19 7:04 
QuestionRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Richard MacCutchan10-Nov-19 7:24
protectorRichard MacCutchan10-Nov-19 7:24 
AnswerRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Member 1465076510-Nov-19 12:15
memberMember 1465076510-Nov-19 12:15 
AnswerRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Member 1465076510-Nov-19 13:03
memberMember 1465076510-Nov-19 13:03 
QuestionGlobal Histogram Implementation in Java Pin
Member 146130164-Oct-19 12:37
memberMember 146130164-Oct-19 12:37 
AnswerRe: Global Histogram Implementation in Java Pin
phil.o4-Oct-19 23:06
mvephil.o4-Oct-19 23:06 
QuestionBiometric attendace machine data Pin
Member 146125164-Oct-19 2:15
memberMember 146125164-Oct-19 2:15 
AnswerRe: Biometric attendace machine data Pin
Richard MacCutchan4-Oct-19 4:19
protectorRichard MacCutchan4-Oct-19 4:19 
AnswerRe: Biometric attendace machine data Pin
Gerry Schmitz4-Oct-19 7:35
mveGerry Schmitz4-Oct-19 7:35 
QuestionNeed to develop a program on Java for desktop Pin
Ryder Weber1-Oct-19 4:32
memberRyder Weber1-Oct-19 4:32 
AnswerRe: Need to develop a program on Java for desktop Pin
Richard MacCutchan1-Oct-19 5:13
protectorRichard MacCutchan1-Oct-19 5:13 
AnswerMessage Closed Pin
1-Oct-19 6:44
memberWishe19911-Oct-19 6:44 
AnswerRe: Need to develop a program on Java for desktop Pin
Gerry Schmitz4-Oct-19 21:35
mveGerry Schmitz4-Oct-19 21:35 
AnswerMessage Closed Pin
3-Nov-19 21:11
memberseemasinghh3-Nov-19 21:11 
Questionhow to reuse open browser in java selenium? Pin
nadavrock29-Sep-19 20:23
membernadavrock29-Sep-19 20:23 
AnswerRe: how to reuse open browser in java selenium? Pin
Leanbridge Technologies2-Nov-19 0:07
professionalLeanbridge Technologies2-Nov-19 0:07 
QuestionJava Cant pass the value that user input as the string and view it Pin
raigen27-Sep-19 6:44
memberraigen27-Sep-19 6: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
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
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
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;
    }
}



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 7:56
protectorRichard MacCutchan27-Sep-19 7:56 
GeneralRe: Java Cant pass the value that user input as the string and view it Pin
raigen27-Sep-19 15:52
memberraigen27-Sep-19 15:52 
GeneralRe: Java Cant pass the value that user input as the string and view it Pin
Richard MacCutchan27-Sep-19 22:48
protectorRichard MacCutchan27-Sep-19 22:48 
QuestionJava Swing app dragging and dropping components with snapping Pin
Member 1457730716-Sep-19 6:27
memberMember 1457730716-Sep-19 6:27 
AnswerRe: Java Swing app dragging and dropping components with snapping Pin
Richard MacCutchan16-Sep-19 7:22
protectorRichard MacCutchan16-Sep-19 7:22 
GeneralWhich language is best for developing sms api java Or .net ? Pin
Msg Club3-Sep-19 23:30
groupMsg Club3-Sep-19 23:30 
GeneralRe: Which language is best for developing sms api java Or .net ? Pin
OriginalGriff3-Sep-19 23:40
protectorOriginalGriff3-Sep-19 23:40 

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.