example of function in java programming
Answers
Answer:
hello! hope this helps you
Explanation:
import java.util.function.Function; public class Main { public static void main(String args[]) { // Function which takes in a number.
plzz mark as brainliest
Answer:
import java.util.*;
class Lenskart
{
int shape1;
int colour1;
int rim1;
int texture1;
String name;
int size1;
int company1;
int buy;
String colour[]={"Red","Blue","Black","White","Grey","Brown","Pink","Purple","Green","Yellow","Go back"};
String shape[]={"Rectangle","Round","Wayfarer","Cat eyes","Go back"};
String rim[]={"Full rim","Half rim","Go back"};
String texture[]={"Matte finish","Shiny finish", "Go back"};
String size[]={"Small","Medium","Large","Go back"};
String company[]={"John Jacobs","Vincent Chase","Ray Ban","Go back"};
void Bill()
{
double price=0.0;
double tax=169.29;
switch(company1)
{
case 1:
if(rim1==2 && shape1==1)
price=2300.0;
else if(shape1==1 && rim1==1)
price=2400.0;
else if(shape1==2 && rim1==2)
price=2600.0;
else if(shape1==2 && rim1==1)
price=2700.0;
else if(shape1==3 && rim1==2)
price=2900.0;
else if(shape1==3 && rim1==1)
price=3000.0;
else if(shape1==4 && rim1==2)
price=2400.0;
else if(shape1==4 && rim1== 1)
price =2500.0;
break;
case 2:
if(rim1==2 && shape1==1)
price=1300.0;
else if(shape1==1 && rim1==1)
price=1400.0;
else if(shape1==2 && rim1==2)
price=1600.0;
else if(shape1==2 && rim1==1)
price=1700.0;
else if(shape1==3 && rim1==2)
price=1900.0;
else if(shape1==3 && rim1==1)
price=2000.0;
else if(shape1==4 && rim1==2)
price=1400.0;
else if(shape1==4 && rim1== 1)
price =1500.0;
break;
case 3:
if(rim1==2 && shape1==1)
price=3300.0;
else if(shape1==1 && rim1==1)
price=3400.0;
else if(shape1==2 && rim1==2)
price=3600.0;
else if(shape1==2 && rim1==1)
price=3700.0;
else if(shape1==3 && rim1==2)
price=3900.0;
else if(shape1==3 && rim1==1)
price=4000.0;
else if(shape1==4 && rim1==2)
price=3400.0;
else if(shape1==4 && rim1== 1)
price =3500.0;
break;
default:
System.out.println("Error. Wrong entry. Try again");
System.exit(0);
}
System.out.println("LENSKART BILL");
System.out.println("Description of specs:");
System.out.println(texture[texture1-1]+", "+colour[colour1-1]+", "+rim[rim1-1]+", "+shape[shape1-1]+", "+size[size1-1]+", "+company[company1-1]);
System.out.println("Unit price: "+price);
System.out.println("Taxes(IGST+CGST+SGST)="+tax);
System.out.println("Grand total="+(price+tax));
System.exit(0);
}
void Buying()
{
switch(buy)
{
case 1:
System.out.println("You may pay by cash or card on delivery");
break;
}
Bill();
}
void Check()
{
switch(buy)
{
case 1:
System.out.println("Thanks for entering information about your first specs");
break;
case 2:
Textures();
break;
}
Buying();
}
void Finals()
{
Scanner sc=new Scanner(System.in);
switch(size1)
{
case 1:
case 2:
case 3:
System.out.println("Enter 1 or 2");
System.out.println("1. Buy now \n2. Go back");
buy=sc.nextInt();
break;
case 4:
Textures();
}
Check();
}
void Sizes()
{
Scanner sc=new Scanner(System.in);
switch(texture1)
{
case 1:
case 2:
System.out.println("Enter 1, 2, 3 or 4");
for(int i=0;i<4;i++)
System.out.println((i+1)+". "+size[i]);
size1=sc.nextInt();
break;
case 3:
Rims();
break;
}
Finals();
}
void Textures()
{
Scanner sc=new Scanner(System.in);
switch(rim1)
{
case 1:
case 2:
System.out.println("Enter 1, 2 or 3");
for(int i=0;i<3;i++)
System.out.println((i+1)+". "+texture[i]);
texture1=sc.nextInt();
break;
case 3:
Colours();
break;
}
Sizes();
}
void Rims()
{
Scanner sc=new Scanner(System.in);
switch(colour1)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
System.out.println("Enter 1, 2 or 3");
for(int i=0;i<3;i++)
System.out.println((i+1)+". "+rim[i]);
rim1=sc.nextInt();
break;
case 11:
Shapes();
break;
}
Textures();
}
void Colours()
{
Scanner sc=new Scanner(System.in);
switch(shape1)
{
case 1:
case 2:
case 3:
case 4:
System.out.println("Enter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or 11");
for(int i=0;i<11;i++)
System.out.println((i+1)+". "+colour[i]);
colour1=sc.nextInt();
break;
case 5:
Companies();
break;
}
Rims();
}
void Shapes()
{
Scanner sc=new Scanner(System.in);
switch(company1)
{
case 1:
case 2:
case 3:
System.out.println("Enter 1, 2, 3, 4 or 5");
for(int i=0;i<5;i++)
System.out.println((i+1)+". "+shape[i]);
shape1=sc.nextInt();
break;
case 4:
Names();
break;
}
Colours();
}
void Companies()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 1, 2, 3 or 4");
for(int i=0;i<4;i++)
System.out.println((i+1)+". "+company[i]);
company1=sc.nextInt();
Shapes();
}
String Names()
{
Scanner sc=new Scanner(System.in);
System.out.println("Welcome to Lenskart!\"Ready to look SPECtacular\" Enter your name");
name=sc.nextLine();
Companies();
return name;
}
public static void main()
{
Lenskart obj=new Lenskart();
obj.Names();
obj.Companies();
obj.Shapes();
obj.Colours();
obj.Rims();
obj.Textures();
obj.Sizes();
obj.Finals();
obj.Buying();
obj.Bill();
String name=obj.Names();
System.out.println("Thank you "+name+" Visit again");
}
}