The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 2 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
1. Write a Circle class that has the following fields:
  -radius: a double
  -PI: a double (DO NOT include Pl as an attribute - use the constant from the Math class (check the Math API)
2. The class should have the following methods:
-Constructor. Â Accepts the radius of the circle as an argument
-Constructor.  A no-argument constructor that sets the radius field to 0.0
-setRadius. A mutator method for the radius field.
-getRadius. A accessor method for the radius field.
-getArea. Returns the area of the circle, which is calculates as area = PI * radius * radius.
-getDiameter. Returns the diameter of a circle, which is calculated as diameter = radius * 2.
-getCircumference. Returns the circumference of a circle, which is calculated as circumference = 2 * PI * radius
-toString(). Displays the current state of the object, include in the state the radius, diameter, area, and circumference of the circleÂ
(DO NOT create attributes for the diameter, area and circumference).
3. Write a RetailItemDriver class and include the following items:
-two Circle objects (this is read in from the retailItems.txt file)
-determineLargerCircle() - this method will display the larger of two circle objects (pass the circle objects into this method from main() )
-getACircle() - this method will read the radius of the circle from the data file (one by one), call this method twice from main() and return the circle object back to main()
-displayACircle() - this will display the current state of the circle object, including the radius, diameter, area, and circumference.
---
So I have attached the beginnings of my Java code for RetailItem & RetailItemDriver but I can't quite figure out how to implement the methods: displayACircle(), getACircle(), and determineLargerCircle(). Â I am also confused on how to "read" in data from the file.
Â
Â
public class RetailItem {
private String description;
private int units;
private double price;
private static final double DISCOUNT = 0.20;
public RetailItem() {
description = "";
units = 0;
price = 0.0;
}
public RetailItem(String description, int unit, double price)
{
this.description = description;
this.units = units;
this.price = price;
}
public void setDescription(String description)
{
this.description = description;
}
public void setPrice(double price)
{
this.price = price;
}
public void setUnits(int units) //Accessor for units on hand
{
this.units = units;
}
public int getUnits() {
return units;
}
public String getDescription() {
return description;
}
public double getPrice() {
return price;
}
public double applyDiscount(double getPrice) {
double amountDiscount = getPrice * DISCOUNT;
return (getPrice - amountDiscount);
}
public String toString() {
String str = "";
str += "Description: " + description;
str += "\nUnits: " + units;
str += "\nPrice: $" + price;
str += "\nPrice after Discount: $" + applyDiscount(price) + "\n";
return str;
}
}//end class
import java.io.*;
import java.util.Scanner;
class RetailItemDriver{
public static void main(String args) throws IOException {
File infile = new File("retailItems.txt");
if(!infile.exists()) {
System.out.println("File not found. Exiting...");
System.exit(0);
}//end find file
String readIn = "";
Scanner scan = new Scanner(infile);
//RetailItem w/ 3 objects
r1 = new RetailItem(readIn);
r2 = new RetailItem();
r3 = new RetailItem();
while(scan.hasNext()) {
readIn = scan.next(); }
//function call to set values
r3.setDescription();
r3.setUnits();
r3.setPrice();
//output data
System.out.println(r1 + "\n" + r2
}//end main + "\n" + r3); public static void displayAll(RetailItem items) {
for(RetailItem item: items)
System.out.println(item);
}
public static RetailItem getRetailObject() {
String des = scan.next();
int unit = scan.nextInt();
double price = scan.nextDouble();
} }//end class
Â
Attachments: