Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need help with Java Lab
New Posts  All Forums:Forum Nav:

Need help with Java Lab

post #1 of 2
Thread Starter 
I have a lab that is due next week and I am having trouble with it. I am a beginner.


Have your main() method instantiate two Cab objects, passing the cab IDs of 1111 for the first Cab and 2222 for the second Cab into their constructors.

What does that mean? How do I pass in the IDs?

Here is just the set-up based on the UML diagram. In addition to my first question, is my set-up correct?

Code:
package cab;

import java.util.Scanner;

public class Cab {

    private double companyTotalFare = 0.0;
    private double rate = 1.95;
    private double taxiTotalFare;
    private double tripFare;
    private int tripCounter;
    private int cabID;
    private int rider;

   public void Cab(int cabID) {

   }

    public void pickUp(double weight, boolean front) {
    }

    public void dropOff(int minutes) {
    }

    public void endOfShift() {
    }

    public void displayStats() {
    }

    public static void main(String args[]) {

        Scanner input = new Scanner(System.in);

       
    }
}

559

I do not want the answers. I just need guidance.

Thanks in advance.
Edited by PyroTechNiK - 3/8/12 at 12:07pm
post #2 of 2
For a class that has a constructor you can create an object like this:
(for example our class is called Foo)
Code:
Foo thisIsOurVariableName = new Foo();


Passing a variable is when a method requires an argument:
(for example our method is called Bar and is defined like this:
Code:
public Bar(String anImput){}
)
Code:
Bar("This is the inputed string");



This should be simple enough to figure out how to combine the two....


Your construction of the class from the diagram looks good....
though that scanner is unnecessary,
and a class's constructor doesn't have a return type, cause its a constructor...
Edited by rush2049 - 3/8/12 at 12:35pm
 
Tragbar
(14 items)
 
 
CPUMotherboardGraphicsRAM
Ryzen 1800X Asus Crosshair VI Hero Nvidia Geforce Titan X F4-3600C15D-16GTZ 
Hard DriveHard DriveHard DriveHard Drive
Combined: 6.13 TB of space Samsung SSD 960 EVO 500GB Crucial_CT1050MX300SSD1 M4-CT128M4SSD2 
CoolingCoolingCoolingCooling
EK-Supremacy EVO White Edition PrimoChill PrimoFlex Advanced LRT EK-RES X4 250 (R2.0) Reservoir EK-CoolStream XE 360 
CoolingCoolingCoolingOS
EK-Vardar F4-120ER (2200rpm)  EK-Ekoolant EVO Liquid Coolant EK-XTOP Revo D5 PWM Pump Windows 10 Pro 
MonitorKeyboardPowerCase
Asus VG278H Ducky YOTG Keyboard Corsair AX1200 Corsair Obsidian 800D 
MouseAudioAudioAudio
Logitech G700s Schiit Gungnir Multibit Schiit Mjolnir 2 Schiit LISST 
Audio
Audeze LCD 2 - pre fazor 
CPUMotherboardGraphicsRAM
intel i7 4770K ASRock Z87E-ITX Nvidia Geforce GTX Titan X GSkill F3-2400C10D-16GTX R 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro 512GB Silverstone 12.7mm Slot Load Blu-Ray Burner Noctua NH-L12 Windows 8 Pro 
MonitorCaseAudioAudio
LG PA75U Slim LED Projector Silverstone SG08 Schiit Bifrost Schiit Asgard 2 
AudioOther
AKG Q701 Headphones Pelican 1510 Green Case  
  hide details  
Reply
 
Tragbar
(14 items)
 
 
CPUMotherboardGraphicsRAM
Ryzen 1800X Asus Crosshair VI Hero Nvidia Geforce Titan X F4-3600C15D-16GTZ 
Hard DriveHard DriveHard DriveHard Drive
Combined: 6.13 TB of space Samsung SSD 960 EVO 500GB Crucial_CT1050MX300SSD1 M4-CT128M4SSD2 
CoolingCoolingCoolingCooling
EK-Supremacy EVO White Edition PrimoChill PrimoFlex Advanced LRT EK-RES X4 250 (R2.0) Reservoir EK-CoolStream XE 360 
CoolingCoolingCoolingOS
EK-Vardar F4-120ER (2200rpm)  EK-Ekoolant EVO Liquid Coolant EK-XTOP Revo D5 PWM Pump Windows 10 Pro 
MonitorKeyboardPowerCase
Asus VG278H Ducky YOTG Keyboard Corsair AX1200 Corsair Obsidian 800D 
MouseAudioAudioAudio
Logitech G700s Schiit Gungnir Multibit Schiit Mjolnir 2 Schiit LISST 
Audio
Audeze LCD 2 - pre fazor 
CPUMotherboardGraphicsRAM
intel i7 4770K ASRock Z87E-ITX Nvidia Geforce GTX Titan X GSkill F3-2400C10D-16GTX R 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro 512GB Silverstone 12.7mm Slot Load Blu-Ray Burner Noctua NH-L12 Windows 8 Pro 
MonitorCaseAudioAudio
LG PA75U Slim LED Projector Silverstone SG08 Schiit Bifrost Schiit Asgard 2 
AudioOther
AKG Q701 Headphones Pelican 1510 Green Case  
  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 › Need help with Java Lab