Program:
package firstclass;
import java.util.Scanner;
public class Bookstor {
static Scanner sc = new Scanner(System.in);
static String[] books={"java","c","python"};
static final double ForTeacher=0.5;
static final double ForStudent=0.3;
static final double ForAlien=0.1;
public static void main(String[] args) {
System.out.println("---------------------Welcome to our bookstore------------------");
System.out.println("Which book do you want to purchase??\nAns: ");
String yourchoice=sc.nextLine();
if(books[0].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[0]+ " book-----");
WhichPerson(books[0]);
}else if(books[1].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[1]+ " book-----");
WhichPerson(books[1]);
}else if(books[2].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[2]+ " book");
WhichPerson(books[2]);
}else{
System.out.println("------Sorry your expected book is not available here---------");
}
}
static void WhichPerson(String great){
System.out.println("----Are you teacher,student or alien??\nAns: ");
double price=200;
String mychoice=sc.nextLine();
if(mychoice.toLowerCase().equals("teacher")){
price=price-(price*ForTeacher);
totalprice(price);
}else if(mychoice.toLowerCase().equals("student")){
price=price-(price*ForStudent);
totalprice(price);
}else if(mychoice.toLowerCase().equals("alien")){
price=price-(price*ForAlien);
totalprice(price);
}else{
System.out.println("-----Sorry you are not in this group.So get lost from here-----");
}
}
static void totalprice(double pri){
System.out.println("The total price of your selected book is: "+pri);
System.out.println("------Thank you for shopping--------");
}
}
Output:
---------------------Welcome to our bookstore------------------
Which book do you want to purchase??
Ans:
python
----You are opted for python book
----Are you teacher,student or alien??
Ans:
teacher
The total price of your selected book is: 100.0
------Thank you for shopping--------
package firstclass;
import java.util.Scanner;
public class Bookstor {
static Scanner sc = new Scanner(System.in);
static String[] books={"java","c","python"};
static final double ForTeacher=0.5;
static final double ForStudent=0.3;
static final double ForAlien=0.1;
public static void main(String[] args) {
System.out.println("---------------------Welcome to our bookstore------------------");
System.out.println("Which book do you want to purchase??\nAns: ");
String yourchoice=sc.nextLine();
if(books[0].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[0]+ " book-----");
WhichPerson(books[0]);
}else if(books[1].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[1]+ " book-----");
WhichPerson(books[1]);
}else if(books[2].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[2]+ " book");
WhichPerson(books[2]);
}else{
System.out.println("------Sorry your expected book is not available here---------");
}
}
static void WhichPerson(String great){
System.out.println("----Are you teacher,student or alien??\nAns: ");
double price=200;
String mychoice=sc.nextLine();
if(mychoice.toLowerCase().equals("teacher")){
price=price-(price*ForTeacher);
totalprice(price);
}else if(mychoice.toLowerCase().equals("student")){
price=price-(price*ForStudent);
totalprice(price);
}else if(mychoice.toLowerCase().equals("alien")){
price=price-(price*ForAlien);
totalprice(price);
}else{
System.out.println("-----Sorry you are not in this group.So get lost from here-----");
}
}
static void totalprice(double pri){
System.out.println("The total price of your selected book is: "+pri);
System.out.println("------Thank you for shopping--------");
}
}
Output:
---------------------Welcome to our bookstore------------------
Which book do you want to purchase??
Ans:
python
----You are opted for python book
----Are you teacher,student or alien??
Ans:
teacher
The total price of your selected book is: 100.0
------Thank you for shopping--------
Screenshots
Program:1
Program : 2
Output
No comments:
Post a Comment