Results 1 to 5 of 5
  1. #1
    Qaqiaq is offline Member
    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0

    Default Classes and constructors

    Im doing a lab project to learn Classes and constructors and I'm kinda lost and what to do/where to begin

    I made UML Class diagram in the prelab, that checks out, here it is:http://pastebin.com/z1w0gi87
    Im still pretty new to Java so im a bit puzzled here. Maybe just some examples would do wonders

    This is the assignment: Implement the Book class you designed for pre-lab. Sales tax would be 7.5%. Create a Java program class named BookDriver that creates two Book objects. First object is for the book "Life of Pi " priced at $13.50 and the second is for the book "Harry Potter: Goblet of Fire" priced at $22.00. Sales program should ask the user for number sold for each book and display the resulting sales amount for each, properly labeled and indicating for which book. Then the program will ask the user for percentage increase in price for each book, and update the Book objects accordingly. Display the sales amounts again using the updated prices. All money amounts should be formatted with a dollar sign and two decimal places.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Classes and constructors

    What have you tried so far?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Qaqiaq is offline Member
    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0

    Default Re: Classes and constructors

    Well right now i have


    Java Code:
    public class Book 
    {
    	private String title;
    	private double price;
    	private double SALES_TAX = .075;
    	
    	public String getTitle() {
    		return title;
    	}
    	public void setTitle(String title) {
    		this.title = title;
    	}
    	public double getPrice() {
    		return price;
    	}
    	public void setPrice(double price) {
    		this.price = price;
    	}
    	public double getSALES_TAX() {
    		return SALES_TAX;
    	}
    	public void setSALES_TAX(double STAX) {
    		SALES_TAX = STAX;
    	}	
    }
    I'm not really sure how i would go about coding these two: +increasePrice(double increasePercent):void and +calculateSales(int numberofBooks): double
    Also not sure if there should be a setter of the sales tax if its a constant?
    Last edited by Qaqiaq; 09-23-2014 at 09:50 PM.

  4. #4
    Qaqiaq is offline Member
    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0

    Default Re: Classes and constructors

    Also what i have set in the bookdriver class atm:

    Java Code:
    import java.util.Scanner;  
    
    public class BookDriver {
    	
    public static void main(String[] args) {
    	
    	Book harry = new Book();
    	harry.setTitle("Harry Potter: Goblet of Fire");
    	harry.setPrice(13.50);
    	
    	Book life = new Book();
    	life.setTitle("Life of Pi");
    	life.setPrice(22.00);
    Last edited by Qaqiaq; 09-23-2014 at 09:49 PM.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Classes and constructors

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Classes, constructors and methods
    By GRGoucho in forum New To Java
    Replies: 3
    Last Post: 02-17-2013, 07:54 PM
  2. Constructors
    By zhider in forum New To Java
    Replies: 5
    Last Post: 11-13-2012, 04:43 AM
  3. Constructors Objects and Classes
    By Tykk in forum New To Java
    Replies: 4
    Last Post: 10-11-2009, 12:31 AM
  4. constructors
    By khamuruddeen in forum New To Java
    Replies: 2
    Last Post: 12-01-2007, 04:15 PM

Posting Permissions

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