Java multi-class question: I have multiple classes in a project. One class is "Guests" and other is 'Files". I want the

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Java multi-class question: I have multiple classes in a project. One class is "Guests" and other is 'Files". I want the

Post by answerhappygod »

Java multi-class question:
I have multiple classes in a project. One class is "Guests" and
other is 'Files". I want the resulting variable from
one method of one class to be accessible as a variable into another
method of second class. The variable should be of
same type i.e. string variable should stay as a
string variable. Sample code is attached below. Please provide a
solution as soon as possible.
Java Multi Class Question I Have Multiple Classes In A Project One Class Is Guests And Other Is Files I Want The 1
Java Multi Class Question I Have Multiple Classes In A Project One Class Is Guests And Other Is Files I Want The 1 (46.76 KiB) Viewed 17 times
Guests.java X ⒸFile.java X 3 4 5 6 7 8 19 10 11 12 13 14 15 16 17 18 19 public class Guests { A H public static void main(String[] args) { new Guests().method1(); } 1 usage public void method1 () { int A = 5; int B = 10; double sum = 0; sum = A + B; System.out.println(sum); A } public void method2() { A //Get the value of String_ID from Class "File" as a string in this function and use it further.For EXAMPLE: Scanner in = new Scanner (System.in); // System.out.print("Full name: "); // String name = in.nextLine(); //System.out.print("Full name:" + "Your ID is: "+ String_ID); } }|
File.java 1 import java.util. Random; 2 public class File { 3 public void generateID() { 4 5 //Example Code. It could be anything in here. I want the resulting variable here (String_ID) to be accessible in // other methods of different class. 6 7 String chars = "0123456789"; Random rand = new Random(); StringBuilder id = new StringBuilder( capacity: 5); for (int i = 0; i < 5; i++) { id.append(chars.charAt(rand.nextInt (chars.length()))); } String String_ID = id.toString(); System.out.println("ID = " + String_ID); 8 9 10 11 12 13 14 15 17 18 Guests.java X G
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply