Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming in Java, Need Some Help!
New Posts  All Forums:Forum Nav:

Programming in Java, Need Some Help!

post #1 of 7
Thread Starter 
So i have fallen a little behind in my programming class and I am having problems starting my next assignment. I would really appreciate some help please.

Here is the assignment. (Caution wall of text)
Warning: Spoiler! (Click to show)
Program Overview: An Internet Service Provider has three different subscription packages for its customers:

Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $13.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.

Your program should be capable of producing the following sample I/O session when it runs, where the user’s input is shown
underlined for clarity; the pink lines will be discussed later in the document:

How many bills to compute? 5
Enter package subscription #1 (A, B, or C) > F
Invalid package type F. Bill not computed.

Enter package subscription #2 (A, B, or C) > a
Enter hours used > -12
Invalid hours. Bill not computed.

Enter package subscription #3 (A, B, or C) > a
Enter hours used > 12.5
===================================================
Internet Service Provider Billing
===================================================
Hours Used: 12.50

Package Type A monthly fee: $ 9.95
2.50 hours @ $2.00: $ 5.00
========
Total Charges: $ 14.95
===================================================

Enter package subscription #4 (A, B, or C) > B
Enter hours used > 12.5
===================================================
Internet Service Provider Billing
===================================================
Hours Used: 12.50

Package Type B monthly fee: $ 13.95
0.00 hours @ $1.00: $ 0.00
========
Total Charges: $ 13.95
===================================================

Enter package subscription #5 (A, B, or C) > c
===================================================
Internet Service Provider Billing
===================================================
Package Type C monthly fee: $ 19.95
========
Total Charges: $ 19.95
===================================================

Total amount billed: $48.85


Grading Criteria for Style and General Education

1 pt Appropriate, consistent indentation such as that shown throughout the textbook sample programs is used in your program.

1 pt Use meaningful (self-documenting) identifiers for all variables, methods, classes.

1 pt Use blank lines and spaces appropriately in your program. See page 21 in your textbook for a discussion of readability.

1 pt The program file begins with comments containing the programmer name(s) and a brief description of the problem(s) or task(s) performed by the program.

Program Specifications: The name of the file containing your Java program for Lab04 should be ISPcharges.java. The program should meet the following specifications

7 pts In order to anticipate the possible future change in the values of monthly rates, monthly hourly limits, and/or hourly overcharge rates, the program should declare and use 7 appropriate class constants. REMINDER: By Java convention, the names of class constants contain all uppercase letters. You were introduced to class constants on page 107.

1 pt The program accepts and responds appropriately to both uppercase and lowercase input from the user. HINT: See page 239 for how to ignore the case of String value.

1 pt The user is prompted for the subscription #1, #2, #3, etc. as shown in the sample I/O sessions above.
HINT: See the sample code on page 243.

3 pts The program computes correct total charges for A, B and C packages.

3 pts The program defines and calls appropriately a method named showFirst4Lines that is responsible for displaying the first four lines of the bill for package A and B customers shown in pink above. It accepts the total hours used as a parameter value. It returns no value back to the calling method.

3 pts The program defines and calls appropriately a method named getPackage that is responsible for prompting the user for, and accepting their input for, the package subscription (A, B or C). Be sure to use the next() Scanner method to input the user’s response. The getPackage method accepts a Scanner object associated with System.in, and a bill number (i.e. 1 or 2 or 3 or etc.) as parameters when it is called, and it returns the value of the package type input by the user.

5 pts The program defines and calls appropriately a method named A_BILL that is responsible for prompting the user for the hours used. If the user enters a valid value for the hours of usage the A_BILL method computes and displays the resulting bill for an A-package customer. It should call the showFirst4Lines method appropriately. The A_BILL method accepts a Scanner object associated with System.in as a parameter when it is called, and it returns the total charge on the bill (or zero if the value input for hours of usage was invalid).

5 pts The program defines and calls appropriately a method named B_BILL that is responsible for prompting the user for the hours used. If the user enters a valid value for the hours of usage the B_BILL method computes and displays the resulting bill for an B-package customer. It should call the showFirst4Lines method appropriately. The B_BILL method accepts a Scanner object associated with System.in as a parameter when it is called, and it returns the total charge on the bill (or zero if the value input for hours of usage was invalid).

3 pts The program defines and calls appropriately a method named C_BILL that is responsible for displaying the bill for a Cpackage customer.

5 pts The bills are formatted as shown above, with a 3-line heading, the hours, hourly rates and dollars displayed to the nearest tenths, and the dollar amounts aligned in a column. HINT: See page 260 for a list of printf format specifiers that might be handy.

5 pts The program correctly computes and displays the total amount billed. HINT: See page 243 (custom page 261) for computing a cumulative sum.

Edited by steelblue - 5/1/12 at 11:41pm
post #2 of 7
What specifically do you need help with? e.g. basic strategy, reading from console, math functions etc.
FermIntel Inside
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k 5Ghz 24/7 ASUS Maximus IV Extreme Gen 3 GTX 470 SLI + HD5450 16GB G.Skill Ripjaws 
Hard DriveOptical DriveOSMonitor
lots none Win7 Ultimate (b:7600) LG W2353V + LG W2343T + LG W2254TQ 
KeyboardPowerCaseMouse
Apple Aluminum Seasonic SS 850HT Sunbean ACTS Razer Deathadder 3500dpi 
  hide details  
Reply
FermIntel Inside
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k 5Ghz 24/7 ASUS Maximus IV Extreme Gen 3 GTX 470 SLI + HD5450 16GB G.Skill Ripjaws 
Hard DriveOptical DriveOSMonitor
lots none Win7 Ultimate (b:7600) LG W2353V + LG W2343T + LG W2254TQ 
KeyboardPowerCaseMouse
Apple Aluminum Seasonic SS 850HT Sunbean ACTS Razer Deathadder 3500dpi 
  hide details  
Reply
post #3 of 7
Thread Starter 
Quote:
Originally Posted by B7ADE View Post

What specifically do you need help with? e.g. basic strategy, reading from console, math functions etc.

I need some help with what the basic structure of the program and strategy to tackle it. Its my first large program (for me anyway) and I get lost just looking at it not knowing where to begin.
post #4 of 7
Quote:
Originally Posted by steelblue View Post

I need some help with what the basic structure of the program and strategy to tackle it. Its my first large program (for me anyway) and I get lost just looking at it not knowing where to begin.

I's personally handle it in four phases:
  1. Get all of the user prompts and inputs working without validation.
  2. Get all of the input validation and 'error' messages working as intended.
  3. Get the calculations required working and producing proper results.
  4. Format the output as shown in the assignment.
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
post #5 of 7
Quote:
Originally Posted by steelblue View Post

I need some help with what the basic structure of the program and strategy to tackle it. Its my first large program (for me anyway) and I get lost just looking at it not knowing where to begin.

When I was learning Java these problems confused me as well. This program isn't that difficult, it just the task of knowing where to start can be tricky.

The first thing you will want to start at is to code each of the input sections. These are the easiest and you should already know how to do so. This can be done in a If/Else statement, if you find it easiest, for each of the inputs. Then once you get the input sections working youll have to work on the calculation part and the error handling. Don't worry about the format with the breaks and everything, that is really simple to edit in just have it say Your Bill is:

Hopefully this helps without giving you any code. Don't over think problems like this, I don't see this code being that long in line code other than with white space. If you need any other help, just say so and I can try to help you through it.
teh_ownerer
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 950 @ 4.01 Asus rampage 3 EVGA GeForce GTX 470 Corsair XMS3 6GB 
Hard DriveOptical DriveOSMonitor
Samsung Spinpoint F3 500GB + 60GB OCZ Vertex 2 SSD Asus Black DVD Combo Burner Windows 7 Professional LG 24" HD 
KeyboardPowerCaseMouse
Logitech G15 Corsair HX series 750W Cool Master HAF 932 Razer Mamba 
  hide details  
Reply
teh_ownerer
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 950 @ 4.01 Asus rampage 3 EVGA GeForce GTX 470 Corsair XMS3 6GB 
Hard DriveOptical DriveOSMonitor
Samsung Spinpoint F3 500GB + 60GB OCZ Vertex 2 SSD Asus Black DVD Combo Burner Windows 7 Professional LG 24" HD 
KeyboardPowerCaseMouse
Logitech G15 Corsair HX series 750W Cool Master HAF 932 Razer Mamba 
  hide details  
Reply
post #6 of 7
It's May..... and it's not that large or complex of a program. First thing, first.... define requirements and pseudo-code it.

The logic is the hardest part. Converting it into code is easy....just look up references to see how to do what you want.
Once again...
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 [4.28GHz, HT] Asus P6T + Broadcom NetXtreme II VisionTek HD5850 [900/1200] + Galaxy GT240 2x4GB G.Skill Ripjaw X [1632 MHz] 
Hard DriveOSMonitorKeyboard
Intel X25-M 160GB + 3xRAID0 500GB 7200.12 Window 7 Pro 64 Acer H243H + Samsung 226BW XARMOR-U9BL  
PowerCaseMouseMouse Pad
Antec Truepower New 750W Li Lian PC-V2100 [10x120mm fans] Logitech G9 X-Trac Pro 
  hide details  
Reply
Once again...
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 [4.28GHz, HT] Asus P6T + Broadcom NetXtreme II VisionTek HD5850 [900/1200] + Galaxy GT240 2x4GB G.Skill Ripjaw X [1632 MHz] 
Hard DriveOSMonitorKeyboard
Intel X25-M 160GB + 3xRAID0 500GB 7200.12 Window 7 Pro 64 Acer H243H + Samsung 226BW XARMOR-U9BL  
PowerCaseMouseMouse Pad
Antec Truepower New 750W Li Lian PC-V2100 [10x120mm fans] Logitech G9 X-Trac Pro 
  hide details  
Reply
post #7 of 7
I find that a basic model makes everything easier, then adding logic is simpler. The model for you will be statically coded, and the sample properties are here:
Quote:
For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour

This means something like:
Code:
public class ServicePackage {

  private String name;
  private double price;
  private int hoursLimit;
  private double additionalHoursRate;

  // make a constructor for convenience (used below)
  public ServicePackage(String name, double price, int hoursLimit, double additionalHoursRate){
     // call property setters here
  }

  // code accessors here, use Eclipse to source | generate getters/setters
}


So now codify:
Quote:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $13.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.

In your main application, you may initialize your model objects with your packages:
Code:
public class Application{

  private ServicePackage A = new ServicePackage("A", 9.95, 10, 2.0);
  private ServicePackage B = new ServicePackage("B", 13.95, 20, 1.0);
  // use -1 as a signal to the logic (you need to code) that it is unlimited
  private ServicePackage C = new ServicePackage("C", 19.95, -1, -1.0);

  public static void main() {
  
    // you must write your own code now...
  }
}

This is a structure or model you can wrap your head around. Now that you have the information structured, as @DuckieHo says, just break down the logic to pseudo code, then codify that as Java syntax using the model I have provided.

I find that many new coders do not start with a model, which makes doing any kind of logic infinitely more complex to wrap your head around.

That should be a great start, now it is time for you to struggle like the rest of us to find your way as a coder!
 
Sim Gear
(10 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i7 3820 RAMPAGE IV EXTREME EVGA GeForce GTX 680 SC+ w/Backplate EVGA GeForce GTX 680 SC+ w/Backplate 
GraphicsRAMHard DriveOptical Drive
EVGA GeForce GTX 680 SC+ w/Backplate CORSAIR DOMINATOR GT 16GB  Samsung 830 Pioneer BDR-206DBK 12x Internal Blu-ray Disc/DV... 
CoolingCoolingCoolingCooling
Bitspower Compression fittings - shiny Noiseblocker NB-BlackSilentPro PK-1 140mm x 25m... Noiseblocker NB-Multiframe M12-S1 120mmx25mm Ul... EK-Supreme HF - Acetal+EN (Nickel) 
CoolingCoolingCoolingCooling
Lamptron FC4 Lamptron FC8 EK GeForce 680 GTX VGA Liquid Cooling Block EK GeForce 680 GTX VGA Liquid Cooling Block 
CoolingCoolingCoolingCooling
EK GeForce 680 GTX VGA Liquid Cooling Block EK-FC680 GTX Backplate EK-FC680 GTX Backplate EK-RAM Dominator - Acetal+EN (Nickel) 
CoolingCoolingCoolingCooling
EK-FC680 GTX Backplate EK-RAM Dominator - Acetal+EN (Nickel) Watercool MO-RA3 4 x 180mm PRO Extreme Radiator... 24v PMP-450S 
CoolingCoolingCoolingCooling
24v PMP-450S RP-45X2 version 2.0 CTR-SPD24X2 Dual 24V Pump Controller Primochill LRT 1/2" x 3/4" 
CoolingOSMonitorMonitor
Koolance Quick Disconnect VL3N Windows 7 x64 Asus VG278H 27-Inch LED 3D Monitor Asus VG278H 27-Inch LED 3D Monitor 
MonitorKeyboardPowerCase
Asus VG278H 27-Inch LED 3D Monitor Microsoft wireless Silverstone ST1500 CaseLabs M10 and Pedestal 
MouseMouse PadAudioAudio
Razer Naga Epic Razer Megasoma Sennheiser PC360 FiiO E10 Headphone DAC/Amp 
OtherOtherOtherOther
Simcraft Apex 3 GT Motion Simulator CubeControls N35 Wheel + Quick Release CubeControls Cube GT Wheel + Quick Release CubeControls SLI-Box 
OtherOtherOtherOther
CST Gated Shifter DSD Sequential Shifter Bodnar FFB Wheel Hydraulic Tilton 600 Series Pedals 
OtherOther
Cobra Technology Evolution Pro Outlast Carbon F... CubeControls Formula Momo Wheel + Quick Release 
  hide details  
Reply
 
Sim Gear
(10 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i7 3820 RAMPAGE IV EXTREME EVGA GeForce GTX 680 SC+ w/Backplate EVGA GeForce GTX 680 SC+ w/Backplate 
GraphicsRAMHard DriveOptical Drive
EVGA GeForce GTX 680 SC+ w/Backplate CORSAIR DOMINATOR GT 16GB  Samsung 830 Pioneer BDR-206DBK 12x Internal Blu-ray Disc/DV... 
CoolingCoolingCoolingCooling
Bitspower Compression fittings - shiny Noiseblocker NB-BlackSilentPro PK-1 140mm x 25m... Noiseblocker NB-Multiframe M12-S1 120mmx25mm Ul... EK-Supreme HF - Acetal+EN (Nickel) 
CoolingCoolingCoolingCooling
Lamptron FC4 Lamptron FC8 EK GeForce 680 GTX VGA Liquid Cooling Block EK GeForce 680 GTX VGA Liquid Cooling Block 
CoolingCoolingCoolingCooling
EK GeForce 680 GTX VGA Liquid Cooling Block EK-FC680 GTX Backplate EK-FC680 GTX Backplate EK-RAM Dominator - Acetal+EN (Nickel) 
CoolingCoolingCoolingCooling
EK-FC680 GTX Backplate EK-RAM Dominator - Acetal+EN (Nickel) Watercool MO-RA3 4 x 180mm PRO Extreme Radiator... 24v PMP-450S 
CoolingCoolingCoolingCooling
24v PMP-450S RP-45X2 version 2.0 CTR-SPD24X2 Dual 24V Pump Controller Primochill LRT 1/2" x 3/4" 
CoolingOSMonitorMonitor
Koolance Quick Disconnect VL3N Windows 7 x64 Asus VG278H 27-Inch LED 3D Monitor Asus VG278H 27-Inch LED 3D Monitor 
MonitorKeyboardPowerCase
Asus VG278H 27-Inch LED 3D Monitor Microsoft wireless Silverstone ST1500 CaseLabs M10 and Pedestal 
MouseMouse PadAudioAudio
Razer Naga Epic Razer Megasoma Sennheiser PC360 FiiO E10 Headphone DAC/Amp 
OtherOtherOtherOther
Simcraft Apex 3 GT Motion Simulator CubeControls N35 Wheel + Quick Release CubeControls Cube GT Wheel + Quick Release CubeControls SLI-Box 
OtherOtherOtherOther
CST Gated Shifter DSD Sequential Shifter Bodnar FFB Wheel Hydraulic Tilton 600 Series Pedals 
OtherOther
Cobra Technology Evolution Pro Outlast Carbon F... CubeControls Formula Momo Wheel + Quick Release 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming in Java, Need Some Help!