Java Code
Java Code
*;
import java.util.*;
public class D2H {
public static void main(String[] args)throws Exception {
AccountDetails obj1=new AccountDetails();
BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Welcome to SatTV");
int option=0;
do {
System.out.println("\n1 . View Account Balance and Current
Subscription");
System.out.println("2 . Recharge Account");
System.out.println("3 . View Available packs and Channels");
System.out.println("4 . Subscribe to base pack");
System.out.println("5 . Add channels to an existing
subscription");
System.out.println("6 . Update mail and phone number for
notification");
System.out.println("7 . Exit");
option = Integer.parseInt(br.readLine());
switch(option) {
case 1:
obj1.showDetails();
break;
case 2:
System.out.print("Enter the amount to Recharge :");
int amount=Integer.parseInt(br.readLine());
obj1.recharge(amount);
break;
case 3:
obj1.packs();
break;
case 4:
System.out.print("Enter the Pack you wish to Subscribe :(
Silver :'S' ,Gold: 'G')");
char choice =br.readLine().charAt(0);
System.out.print("\nEnter the months : ");
int duration =Integer.parseInt(br.readLine());
obj1.subscribe(choice,duration);
break;
case 5:
System.out.print("\nEnter channel names to
add:Discovery ,Nat Geo ");
String s=br.readLine();
obj1.addChannel(s);
break;
case 6:
obj1.updateDetails();
break;
}
}while(option != 7);
}
}
class AccountDetails{
int accountBalance;
String name;
long phone;
String currentSubscription;
static HashMap<String,Integer> channelDetails=new
HashMap<String,Integer>();
static {
channelDetails.put("Zee", 10);
channelDetails.put("Sony", 15);
channelDetails.put("Discovery", 10);
channelDetails.put("Nat Geo",20);
channelDetails.put("Star Plus", 20);
}
public AccountDetails() {
this.accountBalance=100;
this.currentSubscription="Not Subscribed";
}
public void recharge(int rec) {
if(rec>0) {
this.accountBalance+=rec;
System.out.println("Recharge Completed Successfully . Current
balance is "+this.accountBalance);
}
}
public void packs() {
System.out.println("Available Packs for subscription\n");
System.out.println("Silver pack: Zee ,Sony ,Star Plus : 50Rs ");
System.out.println("Gold Pack : Zee , Sony ,Star plus,
Discovery,NatGeo : 100Rs\n");
System.out.println("Available Channels for Subscription\n");
System.out.println("Zee : 10Rs,Sony: 15Rs, Star plus: 20Rs,Discovery:
10Rs,NatGeo: 20Rs");
}
}
else {
this.accountBalance -= totalPrice;
System.out.println("Channel Added Successfully");
}
System.out.println("Account Balance :"+this.accountBalance);
}
public void updateDetails() throws Exception {
System.out.println("Update email and number for notifications");
BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter the email : ");
String name=br.readLine();
this.name=name;
System.out.print("Enter phone :");
long num=Long.parseLong(br.readLine());
this.phone=num;
System.out.println("\nEmail and Phone Updated Successfully ");
}
}