Help me with this programming/java problem. Thank you! Let\'s apply our OO princ
ID: 2247633 • Letter: H
Question
Help me with this programming/java problem. Thank you!
Let's apply our OO principles. Create a can class, such as a can of soup, only it can be anything on a shelf at a grocery store. Call your file/class canYourLastName First define your class variables: Company, Content, Size (usually in ounces), Price. (decide which data types make the most sense) Next, define a default constructor (takes no arguments) and various other constructors. Next, define getters and setters and where appropriate. Eclipse is your friend on this task. View the following video: https: //www.screencast.eom/t/oGABQBQEn54e Next, make sure you have toString() method Make sure you have driver class called CanTesterYourLastName.java In this file, create and print objects. Here is an example driver class: public class canTesterRuse { public static void main(String[] args) { can SWPeaches = new can("S&W;", "Peaches", 12.0, 2.39): can GreenGiantGreenBeans = new can ("Green Giant", "Green Beans"): can DelMonteCreamedCorn = new can("Del Monte", "Creamed Com", 13.4, 2.49): GreenGiantGreenBeans.setSize(11.9): GreenGiantGreenBeans. setPrice(1.79): System.out.println("Can 1: " + SWPeaches.toString()): System.out.println("Can 2: " + GreenGiantGreenBeans.toString()): System.out.println(Can 3: " + DelMonteCreamedCorn): } } Can 1: can [Company = S&W;, Content = Peaches, Size = 12.0, Price = 2.39] Can 2: can [Company = Green Giant, Content = Green Beans, Size = 11.9, Price=1.79] Can 3: can [Company = Del Monte, Content = Creamed Com, Size = 13.4, Price=2.49] Submit both java files in a zipped folder named CanClassYourLastName. See Submitting Assignments folder for more information.Explanation / Answer
Can.java
public class Can {
// Declaring instance variables
private String company;
private String content;
private double size;
private double price;
// Zero argumented constructor
public Can() {
}
// Parameterized constructor
public Can(String company, String content, double size, double price) {
super();
this.company = company;
this.content = content;
this.size = size;
this.price = price;
}
// Parameterized constructor
public Can(String company, String content) {
super();
this.company = company;
this.content = content;
}
// getters and setters
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public double getSize() {
return size;
}
public void setSize(double size) {
this.size = size;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
// toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "Can [company=" + company + ", content=" + content + ", size=" + size + ", price=" + price + "]";
}
}
____________________
CanTesterUse.java
public class CanTesterUse {
public static void main(String[] args) {
//Creating can Class Objects
Can SWPeaches = new Can("S&W", "Peaches", 12.0, 2.39);
Can GreenGaintGreenBeans = new Can("Green Gaint", "Green Beans");
Can DelMonteCreamedCorn = new Can("Del Monte", "Creamed Corn", 13.4, 2.49);
//calling the setter methods on Can Class
GreenGaintGreenBeans.setSize(11.9);
GreenGaintGreenBeans.setPrice(1.79);
//Displaying the Can class objects content
System.out.println("Can 1:" + SWPeaches.toString());
System.out.println("Can 2:" + GreenGaintGreenBeans.toString());
System.out.println("Can 3:" + DelMonteCreamedCorn.toString());
}
}
___________________
Output:
Can 1:Can [company=S&W, content=Peaches, size=12.0, price=2.39]
Can 2:Can [company=Green Gaint, content=Green Beans, size=11.9, price=1.79]
Can 3:Can [company=Del Monte, content=Creamed Corn, size=13.4, price=2.49]
_____________Could you rate me well.Plz .Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.