Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Java Methods Problem
Expert:tay smith
I have to write a program that has three types of pie. Apple, which is the default pie, cherry and pumpkin. I then have to ask the customer what type of pie they like and store it in kind and then ask the user how many slices they would like and store it in num. Then i have to reduce the number of slices in the corresponding pie. How do I loop it until all the slices in each pie are done and then how do I create class variables that tell me the total slices sold and the total amount made for all the pies? This is what I have so far:

import java.util.*;

public class Pie
{

//variables defined here: two types which include class variable (static- access using the class name and the dot operator) and an instance variable (non-static variable- access using the object name and the dot operator)
private int noOfSlices;
private static double price= 3.49;
private static final int DEFAULT_SLICES=8;
// private static final String DEFAULT_TYPE="apple";// default type of pie
private String type;
private OctaviaR_A15 ()// constructor; doesn't take any arguments
{
noOfSlices=DEFAULT_SLICES; }
private OctaviaR_A15 (int a)
{
noOfSlices=a;}
public static OctaviaR_A15 bakeSpecial (String str)
{
Pie specialPie= new OctaviaR_A15();//special pie is a local variable and its not accessible anywhere else in the program
specialPie.type=str; //change the type
return specialPie;
}



public static void main (String[]args)
{

Scanner reader= new Scanner (System.in);
String kind;
int num;
Pie applePie;
Pie thePie;

applePie=new OctaviaR_A15(); //have an applePie ready

System.out.println("What kind of pie would you like?");
kind=reader.nextLine();

if (kind.equals("apple"))// if the customer asks for a default pie
thePie=applePie;

else// otherwise have a special pie
thePie=bakeSpecial(kind);

System.out.println("How many slices would you like?");
num=reader.nextInt();

System.out.println("The amount due is" + num*price);
System.out.println("The number of slices left is" + (DEFAULT_SLICES-num));






}
}
Answers
More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.