0% found this document useful (0 votes)
0 views4 pages

Java Code

The document is a Java program for managing a satellite TV account, allowing users to view account details, recharge, subscribe to packs, add channels, and update personal information. It includes an interactive menu for user options and maintains account balance and subscription status. The program utilizes a class structure to handle account details and channel pricing, with methods for each functionality.

Uploaded by

Pika Chu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

Java Code

The document is a Java program for managing a satellite TV account, allowing users to view account details, recharge, subscribe to packs, add channels, and update personal information. It includes an interactive menu for user options and maintains account balance and subscription status. The program utilizes a class structure to handle account details and channel pricing, with methods for each functionality.

Uploaded by

Pika Chu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.io.

*;
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");
}

public void showDetails() {


System.out.println("Account Balance : "+this.accountBalance);
System.out.println("Current Subscription :
"+this.currentSubscription);
}
public void subscribe(char choice,int duration) {
int price=0;
int discount=0,r=0;
if(choice=='G') {
r=100;
this.currentSubscription="Gold";
if(duration >=3) {
price=r*duration;
discount=price*10/100;
price=price-discount;
this.accountBalance -=price;
}
else {
price=duration*r;
this.accountBalance-=price;
}
}
else if(choice == 'S') {
r=50;
this.currentSubscription="Silver";
if(duration >=3) {
price=r*duration;
discount=price*10/100;
price=price-discount;
this.accountBalance -=price;
}
else {
price=duration*r;
this.accountBalance-=price;
}
}
System.out.println("You have Successfully Subscribed the following
pack-"+this.currentSubscription);
System.out.println("Monthly Price : "+r);
System.out.println("No of Months : "+duration);
System.out.println("Subscription Amount : "+r*duration);
System.out.println("Discount applied : "+discount);
System.out.println("Final Price after discount : "+price);
System.out.println("Email notification send successfully ");
System.out.println("SMS notification sent Successfully");
}
public void addChannel(String channelNames) {
// System.out.println("Enter channel names to add (Separated by commas):");
String channels[]=channelNames.split(",");
int totalPrice=0;
for(int i=0;i<channels.length;i++) {
String ch=channels[i].trim();
int p=channelDetails.get(ch);
totalPrice+=p;
}
if(totalPrice > this.accountBalance) {
System.out.println("Insufficient Balance");

}
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 ");
}
}

You might also like