Python Program Do not use import please. Problem 1: Rolodex (Note: A Rolodex is
ID: 3794031 • Letter: P
Question
Python Program
Do not use import please.
Problem 1: Rolodex (Note: A Rolodex is a Contact List) Write a program that manages a rolodex. This program prompts the user for the name of a rol file. This program should be able to load any rol file and require that the file extension -i.e the last 4 letters of the file be rol. The file rol is consider a valid file. If the file exists the program loads in the contacts stored in the file. A Rolodex contains unique individuals, no duplicate names are allowed. However, name lookups are case sensitive, so "Apple" and "apple" are considered different names allowed However, nameExplanation / Answer
Rolodex.java
public class Rolodex{
String name;
String phone;
String email;
String note;
Rolodex(String name,String phone,String email,String note){
this.name=name;
this.phone=phone;
this.email=email;
this.note=note;
}
public String tostring(){
return "name:"+name+" phone:"+phone +" email:"+email+ " note:"+note;
}
}
rolodexmain.java
import java.util.*;
public class rolodexmain {
static Scanner sc=new Scanner(System.in);
static List<Rolodex>list=new ArrayList<Rolodex>();
static Set<Rolodex>sets=new HashSet<Rolodex>();
public static void main(String[] args) {
// TODO Auto-generated method stub
while(true){
System.out.println("Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)");
char ch=sc.next().charAt(0);
switch(ch){
case 'I':
insert(list);
break;
case 'R':
deleted(list);
break;
case 'F':
Lookbyname(list);
break;
case 'N':
Lookbyphonenumber(list);
break;
case 'E':
Lookbyemail(list);
break;
case 'P':
printall(list);
break;
case 'X':
System.exit(0);
case 'S':
saves(list);
break;
case 'Q':
savesandquit(list);
System.exit(0);
}
}
}
public static void insert(List<Rolodex> list){
System.out.println("please enter contact name:");
String name=sc.next();
System.out.println("please enter contact phone number:");
String phone=sc.next();
System.out.println("please enter contact email id:");
String email=sc.next();
System.out.println("please enter contact note:");
String note=sc.next();
Rolodex r=new Rolodex(name,phone,email,note);
list.add(r);
}
public static void deleted(List<Rolodex> list){
boolean flag=false;
System.out.println("enter name of contact to delete :");
String dname=sc.next();
for(int i=0;i<list.size();i++){
Rolodex r=(Rolodex)list.get(i);
if(r.name.equals(dname)){
list.remove(i);
flag=true;
}
}
if(flag==true)
System.out.println("Record Deleted:");
else
System.out.println("Record is not present");
}
public static void Lookbyname(List<Rolodex> list){
System.out.println("enter name of contact which you want to look :");
String lname=sc.next();
for(int i=0;i<list.size();i++){
Rolodex r=(Rolodex)list.get(i);
if(r.name.equals(lname)){
System.out.println(r.tostring());
}
}
}
public static void Lookbyphonenumber(List<Rolodex> list){
System.out.println("please enter phone number which you want to look:");
String lphone=sc.next();
for(int i=0;i<list.size();i++){
Rolodex r=(Rolodex)list.get(i);
if(r.phone.equals(lphone)){
System.out.println(r.tostring());
}
}
}
public static void Lookbyemail(List<Rolodex> list){
System.out.println("please enter phone number which you want to look:");
String lemail=sc.next();
for(int i=0;i<list.size();i++){
Rolodex r=(Rolodex)list.get(i);
if(r.email.equals(lemail)){
System.out.println(r.tostring());
}
}
}
public static void printall(List<Rolodex> list){
for(int i=0;i<list.size();i++){
Rolodex r=(Rolodex)list.get(i);
System.out.println(r.tostring());
}
}
public static void saves(List<Rolodex> list){
sets.addAll(list);
for (Rolodex o : sets) {
// Rolodex r=(Rolodex)sets;
System.out.println(o.tostring());
}
}
public static void savesandquit(List<Rolodex> list){
sets.addAll(list);
for (Rolodex o : sets) {
// Rolodex r=(Rolodex)sets;
System.out.println(o.tostring());
}
}
}
output:
Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)
I
please enter contact name:
SWARUP
please enter contact phone number:
567889
please enter contact email id:
SWARUP@
please enter contact note:
CONTACT
Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)
I
please enter contact name:
ALISA
please enter contact phone number:
123
please enter contact email id:
ALISE@
please enter contact note:
NEW
Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)
F
enter name of contact which you want to look :
SWARUP
name:SWARUP
phone:567889
email:SWARUP@
note:CONTACT
Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)
N
please enter phone number which you want to look:
567889
name:SWARUP
phone:567889
email:SWARUP@
note:CONTACT
Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)
E
please enter phone number which you want to look:
ALISE@
name:ALISA
phone:123
email:ALISE@
note:NEW
Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)
P
name:SWARUP
phone:567889
email:SWARUP@
note:CONTACT
name:ALISA
phone:123
email:ALISE@
note:NEW
Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)
S
name:ALISA
phone:123
email:ALISE@
note:NEW
name:SWARUP
phone:567889
email:SWARUP@
note:CONTACT
Rolodex comands Insert(i),remove(R), Lookbyname(F),LookbyPhone number(N),Lookby email(E)saves(S),save and quit(Q),printall(P),quit and dont save(X)
X
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.