|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Help with Java Pizza
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
4.0 GHz
![]() |
Ok so i am working on an assignment and iv been trying to figure out the error i am getting when compling heres a screen shot of the error and below is the code:
Code:
public class DemoSwitch
{
public static void main(String args[])
{
char num = 's';
String checksize;
switch(num)
{
case 's' : checksize = "Small";
break;
case 'm' : checksize = "Medium";
break;
case 'l' : checksize = "Large";
}
if ((checksize == "Small")||(checksize == "Medium")||(checksize == "Large"))
{
System.out.println("Your Size is: " + checksize);
}
else
{
System.out.println("Invalid");
}
}
}
__________________
3
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||
|
Programmer
![]() |
String checksize = null;
You never set checksize to anything. So checksize would need a value of some sort in order for it to check against another variable
|
|||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
4.0 GHz
![]() |
ah yes right before u posted i figured it ou what i did was this.. thanks but maybe u could help me out i will make a seperate post below this of whta my real problem is now with my three classes...
Code:
public class DemoSwitch
{
public static void main(String args[])
{
char num = 'x';
String checksize;
switch(num)
{
case 's' : checksize = "Small";
break;
case 'm' : checksize = "Medium";
break;
case 'l' : checksize = "Large";
break;
default : checksize = "Invalid";
}
if ((checksize == "Small")||(checksize == "Medium")||(checksize == "Large"))
{
System.out.println("Your Size is: " + checksize);
}
else
{
System.out.println("Invalid Size");
}
}
}
__________________
3
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
4.0 GHz
![]() |
so here is the big problem... the point of this assignment was to make a program that accepts 2 arguments of which only the first letter of each is read so i understand i would have to use the .charAt method to read Them
after it reads the strings and accepts the char values it is supposed to switch them out for strings after it has done that it must check the validity of the switch and output a message saying either ("your size is: +checksize") or ("invalid size") i understand that part so here is the point of my problem i dont know how to get my argument that i inputed into my checkorder class from my orderform class? both the orderform and the check order use my pizza class. here are my three classes so far... Code:
/**
* Write a description of class Pizza here.
*
* @author Michael Wojtysiak
* @version 1.1
*/
public class Pizza
{
private String size;
private String toppings;
private static int PizzasSold;
public Pizza()
{
System.out.println("Pizza One - Default Constructor");
setSize("Small");
setToppings("Regular");
System.out.println("Size: " + size);
System.out.println("Toppings: " + toppings);
System.out.println("");
}
public Pizza(String setSize, String setToppings)
{
this.size = setSize;
this.toppings = setToppings;
System.out.println("Pizza Three - Two Parameter Constructor");
System.out.println("Size: " + size);
System.out.println("Toppings: " + toppings);
System.out.println("");
}
public Pizza(String setSize)
{
setSize("Medium");
setToppings("Regular");
System.out.println("Pizza Two - One Parameter Constructor");
System.out.println("Size: " + size);
System.out.println("Toppings: " + toppings);
System.out.println("");
}
public void setSize(String size)
{
this.size = size;
}
public void setToppings(String toppings)
{
this.toppings = toppings;
}
public String getSize()
{
return this.size;
}
public String getToppings()
{
return this.toppings;
}
public static int getPizzasSold()
{
return PizzasSold;
}
// public boolean equal(Pizza CompPizza)
// {
// if(this.getSize()==(CompPizza.getSize()))
// {
// if(this.getToppings()==(CompPizza.getToppings()))
// {
// return true;
//}
// else
// {
// return false;
// }
// }
// return false;
// }
public boolean equal(Pizza CompPizza)
{
if(this.getSize()==(CompPizza.getSize()))
{
if(this.getToppings()==(CompPizza.getToppings()))
{
return true;
}
else
{
return false;
}
}
return false;
}
private void calculatePrice()
{
}
public void display(String size, String toppings, double price)
{
System.out.println("Size: " + size);
System.out.println("Toppings: " + toppings);
System.out.println("Price: " + price);
}
}
Code:
import java.util.Scanner;
/**
*Has Pizzas
*
* @author Michael Wojtysiak
* @version 1.1
*/
public class OrderForm
{
public static void main(String args[])
{
String mySize = args[0];
String myToppings = args[1];
CheckOrder.checkSize(args[0]);
// CheckOrder.checkTopping(args[1]);
Pizza One = new Pizza();
Pizza Two = new Pizza(mySize);
Pizza Three = new Pizza(mySize,myToppings);
boolean Res = Three .equal(One);
if(Res == true)
{
System.out.println("They are the same!");
}
else
{
System.out.println("They are different!");
}
}
}
Code:
/**
* Write a description of class CheckOrder here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CheckOrder
{
public static boolean checkSize(String size)
{
char num = size;
String checksize;
switch(num)
{
case 's' : checksize = "Small";
break;
case 'm' : checksize = "Medium";
break;
case 'l' : checksize = "Large";
break;
default : checksize = "Invalid";
}
if ((checksize == "Small")||(checksize == "Medium")||(checksize == "Large"))
{
System.out.println("Your Size is: " + checksize);
}
else
{
System.out.println("Invalid Size");
}
}
//if(boolean checkSize = true)
//{
// size = "Small";
// }
//else
//{
// System.out.println("Invalid");
// }
}
__________________
3
|
|||||||||||||
|
|
|
|
|
#5 (permalink) | |||||||||||||
|
4.0 GHz
![]() |
also heres the instructions on the powerpoint that i was givin maybe they can explain my point better then i can
__________________
3
|
|||||||||||||
|
|
|
|
|
#6 (permalink) | |||||||||||||
|
4.0 GHz
![]() |
sorry bout the bump but i really really need help with this it is due at 12 am est
![]()
__________________
3
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|