The code box below includes two live PricedLime objects, referred to as jacksLim
ID: 3853739 • Letter: T
Question
The code box below includes two live PricedLime objects, referred to as jacksLime, and jillsLime. You cannot see their declarations or initializations. The code for the Lime and PricedLime classes are given below.
Lime.java
PricedLime.java
Your job - using what you know about method accessibility for derived classes - is to write statements that identify the country of origin for the more expensive of the two limes. When you find the answer, print the name of that country to the console.
Enter your code in the box below.
THE CODES ARE AS FOLLOWED:
Explanation / Answer
Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.
____________________________
Lime.java
public class Lime {
private String origin; // where was lime grown?
// Setters and getters
public Lime(String where) {
origin = where;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String where) {
origin = where;
}
}
____________________
PricedLime.java
public class PricedLime extends Lime {
private double price; // cost of a lime
// Parameterized constructor
public PricedLime(String where, double amt) {
super(where);
price = amt;
}
// getters and setters
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
_________________________
Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//Declaring variables
double price;
String origin;
// Scanner object is used to get the inputs entered by the user
Scanner sc = new Scanner(System.in);
//Getting the inputs entered by the user
System.out.println(":: Lime#1 Details ::");
System.out.print("Enter the Price :$");
price = sc.nextDouble();
System.out.print("Enter the Origin :");
origin = sc.next();
/* Creating an PricedLime object by passing
* the user entered inputs as arguments
*/
PricedLime l1 = new PricedLime(origin, price);
//Getting the inputs entered by the user
System.out.println(":: Lime#2 Details ::");
System.out.print("Enter the Price :$");
price = sc.nextDouble();
System.out.print("Enter the Origin :");
origin = sc.next();
/* Creating an PricedLime object by passing
* the user entered inputs as arguments
*/
PricedLime l2 = new PricedLime(origin, price);
//Based on highest price among Two Limes displaying its origin
if (l1.getPrice() > l2.getPrice())
System.out.println("The Place of Origin of Lime#1 is :"+ l1.getOrigin());
else
System.out.println("The Place of Origin of Lime#2 is :"+ l2.getOrigin());
}
}
______________________
Output:
:: Lime#1 Details ::
Enter the Price :$3.5
Enter the Origin :America
:: Lime#2 Details ::
Enter the Price :$4.5
Enter the Origin :Australia
The Place of Origin of Lime#2 is :Australia
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.