0

Help with Java class

Help please. Why my code cannot run the test. It shows NUll in all strings and 0 in all int. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); String firstName = read.nextLine(); String secondName = read.nextLine(); int age = read.nextInt(); int roomNumber = read.nextInt(); Customer customer = new Customer(); //set customer's data to object here customer.saveCustomerInfo(); } } public class Customer { //add all necessary attributes here String firstName; String secondName; int age; int roomNumber; public void saveCustomerInfo() { System.out.println("First name: " + firstName); System.out.println("Second name: " + secondName); System.out.println("Age: " + age); System.out.println("Room number: " + roomNumber); } }

30th Mar 2021, 8:54 PM
韩韵萌
韩韵萌 - avatar
1 ответ
0
You are not set or assigned any values in customer class but printing.so thats why all default values you get.. define Customer constructor to set data fields.. and Send or Set input values through constuctor of customer. Print next...
30th Mar 2021, 8:59 PM
Jayakrishna 🇮🇳