Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Shopping.java (Inheritance) code #2990

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Java Fundamentals programs/OOP/Shopping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.company.inheritance;

class User{
String name;
String email;
int cart;

User(String name,String email,int cart){
this.name=name;
this.email=email;
this.cart=cart;
}

void discount() {
System.out.println("Discount provided-");
}

void loyalty() {
System.out.println("Loyalty provided-");
}

void info() {
System.out.println("Cart has "+cart+" items.");
}
}

class GuestUser extends User{
GuestUser(String name,String email,int cart){
super(name,email,cart);
}

void info() {
System.out.println("As a guest user,"+name+" get no discount and loyalty points provided.");
}
}

class RegisteredUser extends User{
int discount;
int loyaltyp;
public RegisteredUser(String name,String email,int cart,int discount,int loyaltyp){
super(name,email,cart);
this.discount=discount;
this.loyaltyp=loyaltyp;
}

@Override
void discount() {
System.out.println("Discount provided-"+discount);
}

@Override
void loyalty() {
System.out.println("Loyalty points provided-"+loyaltyp);
}

void info() {
System.out.println("For RegistereUser, "+name+" got Discount - "+discount+"%, Loyalty points provided-"+loyaltyp);
}
}

public class shoppingsys {
public static void main(String[] args) {
RegisteredUser reg=new RegisteredUser("Shiv","[email protected]",11,21,7);
reg.info();
GuestUser guest=new GuestUser("Ram","[email protected]",10);
guest.info();
}
}