Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1-can you write this program in java: public class Items { private String name,desc; private double cost; public Items(String nm, String dc,double ct){ name=nm; desc=dc;

1-can you write this program in java:

public class Items { private String name,desc; private double cost; public Items(String nm, String dc,double ct){ name=nm; desc=dc; cost=ct; } protected void setName(String name){ this.name=name; } protected String getName(){ return name; } protected void setDescription(String desc){ this.desc=desc; } protected String getDescription(){ return desc; } protected void setCost(double cost){ this.cost=cost; } protected double getCost(){ return cost; } }

-------------------------------

ublic class GasStation { private String shopName, itemName[]; private int count=0;

public GasStation(String nm,String cfnm[]) { shopName=nm; itemName=new String[10]; for(int i=0;i<10;i++){ if(!cfnm[i].equals("null")){ count++; } itemName[i]=cfnm[i]; } } protected String getShopName(){ return shopName; } protected String[] getCoffeeName(){ return itemName; } protected void setShopName(String nm){ shopName=nm; } protected void setCoffeeName(String nm[]){ for(int i=0;i<10;i++){ itemName[i]=nm[i]; } } protected int getCount(){ return count; } }

Project requirements:

Create a new Project: Project2 and copy the GasStation and Items classes and put them in this new project.

What you will need: - A Partnership class that has: a. A name for your Partnership (i.e.: This can be funny or serious, real or not). b. An ArrayList of GasStations. You will need at least 4 GasStations. You can have more if you want.

- The GasStation class: a) will need to sort its Items by cost. Since the cost of Items is part of an Object, you will need to swap all the data around during the sort and not just the cost. b) If you plan on all of your GasStations having the same name, change the name variable to a location (either city or street if in the same city) c) You will need a method to print each of the Items from a gas station that costs more than $7.00 or be able to print a message saying no Items at this station is over $7.00.

-The Items class: you will add a toString method (a toString returns a String that represents the state of the object). - A DriverP2 class that has a class attribute of a Partnership class (there should not be a variable or instantiation for GasStation or Items classes). All the data for your classes should be hard coded in the Driver.

-----------------------------

Your program will need to - Pass all hard-coded data from the DriverP2 to the Partnership class - Print a Welcoming message stating your Partnership name - Print each GasStation and its Items (all data associated with Items) be sure to use the new toString method from the Items class in your print method. - Sort the Items in each GasStation in ascending order by cost. - Print a line stating that the Items data is now sorted

Re-Print each GasStation and its Items as well as Calculate and print each GasStation average Items cost. - Print the GasStations again but this time only displaying the Items with a cost over $7.00 for each GasStation. If a GasStation has no Items over $7.00 you should have an appropriate message saying so (Hint: to make sure your program tests all possibilities, there should be at least one GasStation that does not have any Items with a cost over $7.00). - Print a good-bye message. All of the above will require methods in the Partnership class and a few new methods in the GasStation class. As in project 1, each GasStation will need at least 5 Items.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions