Tracking Customer Data - Class Attributes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Tracking Customer Data - Class Attributes

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(); } } 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); } } _____________________________________ Hello😊 I do not know exactly what is meant by „set customer's data to object here" . Can someone help me there? Thank you

3rd Feb 2021, 12:29 AM
Özge Nazli
4 Answers
+ 8
Özge Nazli You can set customer data like this customer.firstName = firstName; here you are setting data in class attribute using object. Why object because you must tell that attribute belongs to the specific class. Because there maybe many classes with same attributes.
3rd Feb 2021, 6:07 AM
A͢J
A͢J - avatar
+ 5
This one is working.) 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(); //присвойте данные клиента атрибутам объекта Customer.firstName = firstName; Customer.secondName = secondName; Customer.age = age; Customer.roomNumber = roomNumber; customer.saveCustomerInfo(); } } class Customer { //добавьте все необходимые атрибуты здесь static String firstName, secondName; static int age, 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); } }
23rd Feb 2021, 10:43 AM
Иван Марсавин
Иван Марсавин - avatar
+ 1
Спасибо Иван!
25th Jan 2022, 6:59 AM
Mgr. art. Peter Varga
0
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(); Customer.firstName = firstName; Customer.secondName = secondName; Customer.age = age; Customer.roomNumber = roomNumber; customer.saveCustomerInfo(); } } class Customer { static String firstName, secondName; static int age, 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); } }
15th Nov 2022, 7:48 AM
Pooja Patel
Pooja Patel - avatar