Results 1 to 4 of 4
  1. #1
    syntrax is offline Member
    Join Date
    Sep 2009
    Location
    http://www.kouje.com
    Posts
    16
    Rep Power
    0

    Default HELP working with 2 classes!!! URGENT!

    ok, I need help connecting these 2 files, this code used to be in all in the same class, but my instructor won't accept it like that.

    I've always had problems moving anything between classes and files and now I'm stuck trying to select the package type.

    This program is for an ISP. It includes 3 pakcages, A, B, and C. each one has their own pricing and internet access. The program should ask the user to input their package type and hours of use. But I cannot send data to a class,, how to do it? ty in advanace,, here's my code:

    Java Code:
    import java.text.DecimalFormat;
    import java.text.*;
    
    public class ISP
    {
    	     String input; //to hold user's input
             char pk_type; 
             Double pk_price;
             Double internetHours;
             Double payPrice;
             private Double calculate;
             
    	public void setCalculate(String fgh)
    	{  
          // decimal format object
             DecimalFormat formatter = new DecimalFormat("#,##0.00");
    
    	 	switch(pk_type)
             {
                case 'a':
                case 'A':
                   if(internetHours > 10)
                   {
                      payPrice = internetHours + 2;
                      System.out.println("****** You went over your monthly limit of 10 hours. "
                         			+ "This month's bill is $" + formatter.format(payPrice) + " ******");
                   }
                   else
                   {
                      System.out.println("Package A this month's bill is: $9.95");
                   }
                   break;
             	
                case 'b':
                case 'B':
                   if(internetHours > 20)
                   {
                      payPrice = internetHours + 1;
                      System.out.println("You went over your monthly limit of 20 hours. "
                         			+ "This month's bill is $" + formatter.format(payPrice));
                   }
                   else
                   {
                      System.out.println("Package B this month's bill is: $14.95");
                   }
                   break; 
             		   			
                case 'c':
                case 'C':
                   System.out.println("Package C has Unlimited internet acces. This month's bill is: $19.95");
                   break;
                
                default:
                   System.out.println("Invalid internet package. Please choose between package A, package B, or package C. SINGLE LETTERS ONLY");
             }
    	}
    	public double getCalculate()
    	{
    		return calculate;
    	}
    }
    ================================================== ========

    Java Code:
       import java.text.*;
       import java.util.Scanner;
       import java.text.DecimalFormat;
    
        public class Assignment04 
       {
           public static  void main(String args[])
          {
          	ISP ispPk = new ISP();
             String input; //to hold user's input
             char pk_type; 
             Double pk_price;
             Double internetHours;
             Double payPrice;
          
          // Get current date
             CurrentDateTime today = new CurrentDateTime();
          
          // read input
             Scanner keyboard = new Scanner(System.in);
          
          // decimal format object
             //DecimalFormat formatter = new DecimalFormat("#,##0.00");
          
          // Print Date
             //System.out.println("''''''''''''''''''''''''''''''''''");
             //System.out.println(today.getDateTime());
             //System.out.println("''''''''''''''''''''''''''''''''''\n");
          
          // get internet package type
             System.out.print("Enter your Internet package type: ");
             input = keyboard.nextLine();
          	
             System.out.print("For how many hours did you surf the web? ");
             internetHours = keyboard.nextDouble();
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Could you describe your problem in greater detail? You state that you are "stuck" but don't elaborate how. The more you tell us, the easier it would be for us to help you. Much luck!

    edit: also, as an aside, you may wish to go easy on the "urgent" business. All of us are volunteers, and no one likes to be rushed. While it may be urgent for you, it's not for us, and pressuring us may have an opposite effect. Again, much luck.
    Last edited by Fubarable; 12-09-2009 at 03:31 AM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Also, in all likelihood, your ISP class should have no user interaction but rather be class for holding, well, ISP information and nothing more. It should have getters and setters though, and I don't see that you've given it any.

    Your other class, the "test" class with the main method should have all of the user interaction code.

  4. #4
    syntrax is offline Member
    Join Date
    Sep 2009
    Location
    http://www.kouje.com
    Posts
    16
    Rep Power
    0

    Default

    the problem is that i don't know how to move data between different files. This program was written as 1, but my instructor wont accept it.

Similar Threads

  1. I need Help Urgent..
    By vidhyaprakash85 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-18-2009, 07:49 AM
  2. Urgent Help!!
    By Winniee in forum New To Java
    Replies: 5
    Last Post: 02-17-2009, 04:32 AM
  3. Need help urgent! Is this possible ?
    By meodihia in forum Sun Java Wireless Toolkit
    Replies: 1
    Last Post: 09-28-2008, 10:05 PM
  4. Help. It's urgent
    By monir6464 in forum AWT / Swing
    Replies: 2
    Last Post: 08-24-2008, 06:57 PM
  5. Replies: 8
    Last Post: 05-28-2008, 08:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •