473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

when i run my coffe driver i get null for program print

got rid of all errors but it will not print what it is suposed to it runs and prints out

Welcome to Coffee Driver! Do you want to see our menu sorted by item name or price?/nEnter 'p' for price and 'n' for item name:
p
null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

null $0.0

here are my codes

///"ITEM.JAVA"



public class Item{

//delcare instance fields
private String itemName;
private double itemPrice;

//declare constructor
public Item(String itemName){
itemName = itemName;
}
public Item(double itemPrice){
itemPrice = itemPrice;

}

//delcare setters
public void setItemName (String itemName){
itemName = itemName;
}
public void setItemPrice (double itemPrice){
itemPrice = itemPrice;
}

//declare getters
public String getItemName(){
return itemName;
}
public double getItemPrice(){
return itemPrice;
}


}//ends class


////"COFFEEDRIVER.JAVA"
import java.util.*;

public class CoffeeDriver{

public static void main(String[] args){

Scanner keyboard = new Scanner(System.in);

Item[] item = new Item[5];
Item[] price = new Item[5];
String answer;
String itemName;
double itemPrice;


//load array

item[0] = new Item("Coffee");
item[1] = new Item("Water");
item[2] = new Item("Milk");
item[3] = new Item("Bagel");
item[4] = new Item("Donut");

price[0] = new Item(1.00);
price[1] = new Item(2.00);
price[2] = new Item(1.50);
price[3] = new Item(1.25);
price[4] = new Item(0.75);
//get user input
System.out.println("Welcome to Coffee Driver! Do you want to see our menu sorted by item name or price?" +
"/nEnter 'p' for price and 'n' for item name: ");
answer = keyboard.nextLine();

if(answer.equalsIgnoreCase("p")){
sortPrice(item);
displayItems(item);
} else {
displayItems(item);
}//ends if..else

displayItems(item);
sortPrice(item);
displayItems(item);
}//ends main
public static void sortPrice(Item[] p){
Item temp;
for(int a = 0; a < p.length-1; a++){
for(int b = 0; b < p.length-1; b++){
if(p[b].getItemPrice() >= p[b+1].getItemPrice()){
temp=p[b];
p[b]=p[b+1];
p[b+1]=temp;
}//end if
}//end for
}//end for
}//end sortUnits method

public static void displayItems(Item[] n){
for(int i=0; i < n.length; i++){
System.out.println(n[i].getItemName() + "\t" + "$" + n[i].getItemPrice());
System.out.println();
}//end for
}//end displayItems method

}//ends class
Jul 17 '12 #1
0 1324

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: xegfault | last post by:
Here is a simple script: #!/usr/bin/python print "No newline, please.", # End of script When the program runs, python is still printing a newline when the program exits. How does one keep...
5
by: aleksander.helgaker | last post by:
I've completely rewritten a calculator I wrote to help me learn Python. After someone told me about the def command I reliesed that I could make the program much better, but there is a very anoying...
7
by: Miktor | last post by:
At the minute I am using the following rather unwieldy function to prevent the console window in Dev C++ from closing before I can see the output from my program: // function to prevent the...
8
by: Michael A. Covington | last post by:
Is there a way to make a C# program print the date on which it was compiled? Finding the file date of the executable is one way, but it's not foolproof. Thanks!
9
by: David A. Beck | last post by:
When I do a debug.print("blabla") in VB (VS2005) it doesn't show up in the output window, what gives?
5
by: Web learner | last post by:
while (dr.Read()) //dr is an instance of sqlDataReader { double minAirTemp = (double)(Single)dr; // minAirTemp is column in SQLExpress table (data type: real, allows nulls) } The above...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
6
by: Peter Michaux | last post by:
Suppose I have implemented a language with garbage collection in C. I have wrapped malloc in my own C function. If malloc returns NULL then I can run the garbage collector and then try malloc...
1
by: matthew brown | last post by:
class Temperature{ // Convert temperature from Fahrenheit to Centigrade //Author : Samuel N. Kamin, June 1 , 1996 public static void main(Stringargs) { int temperature; //The Fahrenheit...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.