Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsClasses and members

Records

Class Home

Report a typo

Rewrite the Home class into its equivalent record presentation.

Sample Input 1:

123 Main St
Anytown
CA
12345

Sample Output 1:

Home[address=123 MAIN ST, city=ANYTOWN, state=CA, zipCode=12345]
Write a program in Java 17
import java.util.Locale;
import java.util.Scanner;

class Home {
private final String address;
private final String city;
private final String state;
private final String zipCode;

Home(String address, String city, String state, String zipCode) {
if (zipCode == null) {
this.zipCode = "unknown";
} else {
this.zipCode = zipCode;
}

this.address = address.toUpperCase(Locale.ENGLISH);
this.city = city.toUpperCase(Locale.ENGLISH);
this.state = state.toUpperCase(Locale.ENGLISH);
}
}

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Home home = new Home(scanner.nextLine(), scanner.nextLine(), scanner.nextLine(), scanner.nextLine());
System.out.println(home);
}
}
___

Create a free account to access the full topic