Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Worksheet 3-2: working with various data types in Java Suppose that we want to w

ID: 3913867 • Letter: W

Question

Worksheet 3-2: working with various data types in Java Suppose that we want to write a computer program. The program will be used to process information about the personal accounts for all clients of a Bank. In order to do that, the program should store various pieces of data for each account holder and their corresponding account. The data that needs to be stored in the program is listed in the following table. For each piece of data, indicate the smallest data type that could be used for storing the data in the program. Thern assuming that the program will be written in Java, indicate also the amount of memory in bytes that would be needed for each account holder and their corresponding account. Number of Bytes Required in Java Data to be Stored Data Type Needed Client ID: a number between 1 and 30,000 Client Name: text with maximum 25 characters including spaces Client Age: a number between 21 and 100 Client Gender: a letter 'M' or 'F Client Date of Birth: text in the format dd/mm/yyyy Client Postal Address: text with maximum 50 characters including spaces Account Number: a number between 055555 and 099999 Premium Account: True or False Account Balance: a number including dollars and cents and possibly of negative value Then write a Java program called BankAccounts to capture and then display all the above information for one person.

Explanation / Answer

50 bytes(max, char is 2 bytes in java)

Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

import java.util.Scanner;

public class BankAccounts {
public static void main(String[] args) {
short id;
String name, dob, address;
byte age;
char gender;
int accNumber;
boolean premium;
float balance;

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter id (1 - 30000): ");
id = keyboard.nextShort();

keyboard.nextLine(); //get rid of newline before using nextLine()
System.out.print("Enter name: ");
name = keyboard.nextLine();

System.out.print("Enter age (21 - 100): ");
age = keyboard.nextByte();

System.out.print("Enter gender (M/F): ");
gender = keyboard.next().charAt(0);

System.out.print("Enter date of birth: ");
dob = keyboard.next();

keyboard.nextLine(); //get rid of newline before using nextLine()
System.out.print("Enter address: ");
address = keyboard.nextLine();

System.out.print("Enter account number (55555 - 99999): ");
accNumber = keyboard.nextInt();

System.out.print("Is it premium (true/false)? ");
premium = keyboard.nextBoolean();

System.out.print("Enter account balance: ");
balance = keyboard.nextFloat();


System.out.println("------------------------");
System.out.println("Id: " + id);
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Gender: " + gender);
System.out.println("Date of Birth: " + dob);
System.out.println("Address: " + address);
System.out.println("Account Number: " + accNumber);
System.out.println("Premium: " + premium);
System.out.printf("Balance: %.2f ", balance);

}
}

output
-----
Enter id (1 - 30000): 1
Enter name: John Smith
Enter age (21 - 100): 25
Enter gender (M/F): M
Enter date of birth: 15/02/1997
Enter address: 123 street Washington DC
Enter account number (55555 - 99999): 56565
Is it premium (true/false)? true
Enter account balance: 2500.00
------------------------
Id: 1
Name: John Smith
Age: 25
Gender: M
Date of Birth: 15/02/1997
Address: 123 street Washington DC
Account Number: 56565
Premium: true
Balance: 2500.00

Data to be stored Data type No. of bytes in Java Client Id (between 1 and 30000) short 2 bytes Client name(max 25 chars) String

50 bytes(max, char is 2 bytes in java)

Client age (between 21 and 100) byte 1 byte Client Gender char 2 byte Client DOB(dd/mm/yyyy) String 20 bytes ( 10 chars*2 bytes) Client Postal Address String 100 bytes ( 50 chars * 2 bytes) Account number int 4 bytes Premium Account boolean 1 byte Account Balance float 4 bytes
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote