JAVA: Create a class that allows the user to ask what type of phone they want an
ID: 3723790 • Letter: J
Question
JAVA:
Create a class that allows the user to ask what type of phone they want and what main feature.
Return a yes if you have it and the price.
Create a second class that has two arrays, one of type String that has the phone manufacturer, and two columns for feature one and feature two. A second array of type double that has the price.
Create methods to allow the first class to determine if you have a phone of the type requested and if it has the feature desired. Also a method to return the price. (price explicitly)
Explanation / Answer
Hi.. I have written above in java code.
PhnClass.java
import java.util.Arrays;
public class PhnClass {
String manufacture[] = {"Samsung","Apple"};
String features[][] = {{"Camera","Android"},{"Clarity","IOS"}};
double price[] = {15000.00,35000.00};
//both[0][0] = "ab";
public double checkMobile(String type,String feature){
for(int i=0;i<manufacture.length;i++){
if(manufacture[i].equalsIgnoreCase(type)){
if(features[i][0].equalsIgnoreCase(feature) || features[i][1].equalsIgnoreCase(feature)){
return price[i];
}
}
}
return 0;
}
}
CheckDriver.java
import java.util.Scanner;
public class CheckDriver {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter type of phone:");
String type = sc.nextLine();
System.out.println("Enter feature of phone:");
String feature = sc.nextLine();
PhnClass p = new PhnClass();
double rate = p.checkMobile(type, feature);
if(rate==0){
System.out.println("Sorry item not found with the above details!");
}else{
System.out.println("Rate of phone: $"+rate);
}
}
}
Output:
Enter type of phone:
Apple
Enter feature of phone:
IOS
Rate of phone: $35000.0
Please test the code and let me know any issues. Thank you. All the best.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.