Question: Can somone please change the structure for this program and make a bit basic way for my homework? import java.util.ArrayList; import java.util.Random; import java.util.Scanner; class
Can somone please change the structure for this program and make a bit basic way for my homework?
import java.util.ArrayList; import java.util.Random; import java.util.Scanner;
class Cook{
//Private Data members of Cook class
private String type;
private String name;
private String id;
private double baseSalary;
private double bounties;
//Constructor with type as parameter
Cook(String _type){
type=_type;
}
//Constructor with other parameters
Cook(String _type,String _name,double _baseSalary,double _bounties){
type=_type;
name=_name;
baseSalary=_baseSalary;
bounties=_bounties;
}
//Getter and Setter functions
String getType(){return type;}
String getName(){return name;}
String getId(){return id;}
double getBaseSalary(){return baseSalary;}
double getBounties(){return bounties;}
void setName(String _name){name=_name;}
void setId(String _id){id=_id;}
void setBaseSalary(double _baseSalary){baseSalary=_baseSalary;}
void setBounties(double _bounties){bounties=_bounties;}
//Function to calculate total Salary
double calculateTotal(){
//Here I am assuming this is how you want to calculate total Salary
//There are 22 week days and 4 week ends
//First create a random number b/w 200 and 500
Random rand=new Random();
int wekend=rand.nextInt(301)+200;
double sa=baseSalary+bounties*(22*50+wekend*4);
return sa;
}
//Overriding toString() method
public String toString(){
double totalSalary=calculateTotal();
String output="Type: "+type+" Name: "+name+" ";
output=output+"Id: "+id+" Total Salary : "+totalSalary+" ";
return output;
}
//Random id generator function
String RandomIdGenerator(){
//Creating instance of Random and then calculating random String
Random rand=new Random();
int a=rand.nextInt(26);
int b=rand.nextInt(26);
int c=rand.nextInt(26);
int one=rand.nextInt(10);
int two=rand.nextInt(10);
String randomId=((char)(a+'A')+""+(char)(b+'A')+""+(char)(c+'A')+""+(char)(one+'0')+""+(char)(two+'0'));
return randomId;
}
//Method to set Random Id
void setRandomId(){
//Creating instance of Random and then calculating random String
Random rand=new Random();
int a=rand.nextInt(26);
int b=rand.nextInt(26);
int c=rand.nextInt(26);
int one=rand.nextInt(10);
int two=rand.nextInt(10);
String randomId=((char)(a+'A')+""+(char)(b+'A')+""+(char)(c+'A')+""+(char)(one+'0')+""+(char)(two+'0'));
id=randomId;
}
}
class Test
{
public static void main (String[] args) throws java.lang.Exception
{
//You should create three ArrayLists of Cook,since if you create only
//one arraylist then also size would be same but in this case data is
//better formatted.
ArrayList
ArrayList
ArrayList
//These integers will store no of each types of chefs
int chef=0;int assis=0;int sous=0;
//Taking input from User using Scanner
Scanner sc=new Scanner(System.in);
System.out.println("#chefs?");
chef=sc.nextInt();
while(chef<=0){
System.out.println("Invalid Number! Enter Again");
chef=sc.nextInt();
}
System.out.println("#chef assisstants?");
assis=sc.nextInt();
while(assis<=0){
System.out.println("Invalid Number! Enter Again");
assis=sc.nextInt();
}
System.out.println("#sous chefs?");
sous=sc.nextInt();
while(sous<=0){
System.out.println("Invalid Number! Enter Again");
sous=sc.nextInt();
}
//Now asking for details for each type of chef one by one
for(int i=0;i System.out.println("Enter your name please, chef!"); String name=sc.next(); System.out.println("What is your Salary Expectation, "+name); double salary=sc.nextDouble(); while(salary>2000){ System.out.println("Exceeds , try Again!"); salary=sc.nextDouble(); } //Creating a Cook Object Cook var=new Cook("Chef",name,salary,0.5); var.setRandomId(); //Inserting object to ArrayList chefs.add(var); } for(int i=0;i System.out.println("Enter your name please, chef asst!"); String name=sc.next(); System.out.println("What is your Salary Expectation, "+name); double salary=sc.nextDouble(); while(salary>1500){ System.out.println("Exceeds , try Again!"); salary=sc.nextDouble(); } //Creating a Cook Object Cook var=new Cook("Chef Assistant",name,salary,0.4); var.setRandomId(); //Inserting object to ArrayList chef_assisstants.add(var); } for(int i=0;i System.out.println("Enter your name please,sous chef!"); String name=sc.next(); System.out.println("What is your Salary Expectation, "+name); double salary=sc.nextDouble(); while(salary>1000){ System.out.println("Exceeds , try Again!"); salary=sc.nextDouble(); } //Creating a Cook Object Cook var=new Cook("Sous Chef",name,salary,0.25); var.setRandomId(); //Inserting object to ArrayList sous_chefs.add(var); } //Now displaying all Cooks ,Just use System.out //This is because of overriding of toString function for(int i=0;i System.out.println(chefs.get(i)); } for(int i=0;i System.out.println(chef_assisstants.get(i)); } for(int i=0;i System.out.println(sous_chefs.get(i)); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
