need help with JAVA exercise

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alternative49e
    New Member
    • Nov 2007
    • 5

    #1

    need help with JAVA exercise

    Hello. I'm trying to figure out an exercise. I started working on it but I kind of hit a wall. I'm not very good at the programming thing and the book I have is not very helpful. I could use some help or suggestions. I don’t know if what I have started so far is even the correct way to do this. Here is exercise.

    Create a class called CarRental that contains fields that hold a renter's name, zip code, size of the car rented, daily rental fee, length of the rental in days, and total rental fee. The class contains a constructor that requires all the rental data except the daily rate and total fee, which are calculated, based on the size of the car: economy at $29.99 per day, midsize at $38.99 per day, or full size at $43.50 per day. The class also includes a display() method that displays all the rental data. Create a subclass named LuxuryCarRental . This class sets the rental fee at $79.99 per day and prompts the user to respond to the option including a chauffeur at $200 more per day. Override the parent class display() method to include chauffer fee information, Write an application named UseCarRental that prompts the user for the data needed for a rental and creates an object of the correct type. Display the total rental fee. Save the files as CarRental.java, LuxuryCarRental .java and UseCarRental.ja va

    I haven’t started the LuxuryCarRental .java yet
    Here is what I have so far.


    Code:
    import javax.swing.*;
    public class CarRental
    {
    	private String renterName;
    	private int renterZip;
    	private int carSize;
    	private double dailyFee;
    	private int daysRented;
    	private int totalCost;
    
    	public void setRenterName()
    	{
    		String inString;
    		inString = JOptionPane.showInputDialog(null, 
    			"What is your name? ");
    	}
    	public void setRenterZip()
    	{
    		String inString;
    		inString = JOptionPane.showInputDialog(null, 
    			"What is your zip code? ");
    	}
    	public void setCarSize()
    	{
    		String sizeChoice;
    		sizeChoice = JOptionPane.showInputDialog(null, 
    			"Please enter what size car you would like\n" + 
    			"1. economy\n" +
    			"2. mid-sized\n" +
    			"3. full-sized\n");
    		carSize = Integer.parseInt(sizeChoice);
    	}
    	public void setDaysRented()
    	{
    		String inString;
    		inString = JOptionPane.showInputDialog(null, 
    			"How many days will you be renting the car? ");
    	}
    }
    and


    Code:
    public class UseCarRental
    {
    	public static void main(String[] args)
    	{
    		CarRental aCarRental = new CarRental();
    		aCarRental.setRenterName();
    		aCarRental.setRenterZip();
    		aCarRental.setCarSize();
    		aCarRental.setDaysRented();
    		System.exit(0);
    	}
    }
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    There are lots of ways to do any problem. My suggestion to you is to write these out with UML - get a good idea of what your program is doing and the architecture behind it. That will help you get a clear view of the methods you will have and the interactions between all three classes.

    You should really design your program before you jump in and start coding, or else you run into situations like this - where you get a bunch of code, but aren't sure if it is useful or not.

    Comment

    Working...