Hey guys So i need help writing this program in Java please! If we could put the
ID: 3847730 • Letter: H
Question
Hey guys So i need help writing this program in Java please! If we could put the phone numbers and email addresses in an array instead of strings that would be wonderful! Thank you for your help! - Ben :)
Create Person class which includes firstName, middleName, lastName, multiple phone numbers, multiple addresses(should contains
street, city, state, and country), multiple notes, and groupName.
Write Week05_yourName_Assignment.java to display the menu such as 1 for writeData, 2 for readData, and x for terminating the program.
Week05_yourName_Assignment.java should create 10 Person objects to serialize and 3 of them has 3 phones and 2 addresses, 2 of them has 3 notes and 2 phones.
Note: be careful where to store serialization file and read from.
Explanation / Answer
this java program Creates a Person class which includes firstName, middleName, lastName, multiple phone numbers, multiple addresses(should contains
street, city, state, and country), multiple notes, and groupName.
Write Week05_yourName_Assignment.java to display the menu such as 1 for writeData, 2 for readData, and x for terminating the program.
Week05_yourName_Assignment.java should create 10 Person objects to serialize and 3 of them has 3 phones and 2 addresses, 2 of them has 3 notes and 2 phones.the java programming code is:
import java.io.*;
import java.util.Scanner;
class Person
{
String firstName;
String middleName;
String LastName;
String Group_name;
String city;
String state;
String street;
String country;
long phone_num[]=new long[100];
String arr[]=new String[100];
String notes[]=new String[100];
int i=0;
int n=0;
Person(long phone)
{
phone_num[i]=phone;
i++;
}
Person(String street,String city,String state,String country)
{
this.street=street;
this.city=city;
this.state=state;
this.country=country;
}
Person(String note)
{
notes[i]=note;
n++;
}
void method(PrintWriter obj)
{
for (int i=0;i<2;i++)
{
obj.print(phone_num[i]);
}
}
}
public class week05_yourName_Assignment
{
public static void main (String[] args) throws IOException
{
FileWriter fw=new FileWriter("D:\New folder\output.txt");
PrintWriter obj=new PrintWriter(fw);
BufferedWriter out= new BufferedWriter(fw);
Scanner sc=new Scanner(System.in);
Person obj1=new Person(994946557L);
Person obj2=new Person(882571657L);
Person obj3=new Person(898665548L);
Person obj4=new Person("lalithanagar","visakhapatnam","a.p","india");
Person obj5=new Person("gajapathinagar","vizianagaram","a.p","india");
Person obj6=new Person("this is text 1");
Person obj7=new Person("this is text2");
Person obj8=new Person("this is text3");
Person obj9=new Person(9923453326L);
Person obj10=new Person(7844655338L);
obj2.method(obj);
out.close();
while(true)
{
System.out.println("***menu***");
System.out.println("1.writedata");
System.out.println("2.readdata");
System.out.println("3.terminating");
System.out.println("enter your choice:");
int opt=sc.nextInt();
switch(opt)
{
case 1:break;
case 2:break;
case 3:System.exit(0);
default:System.out.println("wrong choice selected");
}
}
}
}