Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Need help ASAP

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help ASAP

    I'm taking a beginner course for Java programming. The current assignment I'm on is giving me some issues and I've been trying all day to figure out how to go about completing the assignment.

    Here is the outline of the assignment:

    Create a public class named PaintingHarness and a class below it in the same file named Painting. Programmers use the term "harness" to refer to a class that tests the functionality of another class. In this case, our harness class will have a main method in it where we can write code to test the Painting class. Structure your file the way it appears below:

    public class PaintingHarness
    {
    public static void main(String[] args)
    {
    // put code here
    }
    }

    class Painting
    {
    // put code here
    }

    And these are the instructions:

    Continue to design the Painting class as follows:

    Create fields for a painting's title, artist, medium (such as water color), and price.

    Create four accessor methods (get) and four mutator methods (set), one pair for each of the fields.

    Create a field to hold the gallery commission. This field cannot be set from outside the class. It is computed as 20% of the price, and should be set whenever the price is set. Put the code to calculate and set the commission in the setPrice() method.

    Create a method called describe() that returns a String that contains the title, artist, medium, price, and commission of the painting in a presentable format. Each attribute should be clearly labeled, and the price and commission values should be displayed appropriately.

    Back in the PaintingHarness class, write the code to accomplish the following tasks:

    Create an instance of the Painting class and choose an appropriate variable name.

    Ask the user for a painting's title, artist, medium, and price, calling the appropriate methods in the Painting object to set each attribute.

    Call the Painting object's describe() method and display the String it returns out to the screen.

    When the program runs, the user should see all of the data they entered reflected back to them as the Painting object "describes itself" on the screen. The gallery commission should also appear and be 20% of the price. Verify that everything is accurately described.

    I'm really stumped. I've been trying to figure out how to continue but, I'm hitting a wall. If anyone can help me I'd greatly appreciate it.



    Here is as far as I've gotten.

     
    import java.util.Scanner;
     
    public class PaintingHarness
    {
       public static void main(String [] args)
       {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the title of the painting >>");
        System.out.println("Enter the artist of the painting >>");
        System.out.println("Enter the medium of the painting >>");
        System.out.println("Enter the price of the painting >>");
     
       } 
    }
     
     
     
     
    class Painting
    {
       public String paintingTitle;
       public String paintingArtist;
       public String paintingMedium;
       public int paintingPrice;
       int commision;
       int commRate;
       commRate = .20
       commision = paintingPrice * commRate;
     
          }        
       public String getPaintingTitle()
       {
          return paintingTitle;
       }
       public void setPaintingTitle(String title)   
       {
          paintingTitle = title;
       }
       public String getPaintingArtist()
       {
          return paintingArtist;
       }
       public void setPaintingArtist(String artist)
       {
          paintingArtist = artist;
       }
       public String getPaintingMedium()
       {
          return paintingMedium;
       }
       public void setPaintingMedium(String medium)
       {
          paintingMedium = medium;
       }
       public getPaintingPrice()
       {
          return paintingPrice;
       }   
       public void setPaintingPrice(int price)
       {
          paintingPrice = price;
       }     
    }
    Last edited by Neurotic Kasper; September 28th, 2014 at 08:39 AM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Need help ASAP

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

    Indicating urgency often has a result opposite that desired.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help ASAP

    Sorry it was like 2am when I posted that and was in a hurry to get to bed. I fixed the post, thanks for the tip.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Need help ASAP

    Tell us where or why you're stumped. Frankly, it looks like it got late, and you just got tired of working on it, weary in general, and frustrated. How does it look this morning? Pick back up with where you left off (the describe() method?) and keep going. Something to look back at is you might consider whether ints are appropriate types for variables or results that may contain decimal values.

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help ASAP

    These are the parts I'm stuck on right now. I'm not sure I did the first part right and for the second I'm not sure how to start it. Online classes suck for getting help effectively and a text book can re-explain things so I can understand them.

    Create a field to hold the gallery commission. This field cannot be set from outside the class. It is computed as 20% of the price, and should be set whenever the price is set. Put the code to calculate and set the commission in the setPrice() method.

    Create a method called describe() that returns a String that contains the title, artist, medium, price, and commission of the painting in a presentable format. Each attribute should be clearly labeled, and the price and commission values should be displayed appropriately.

  6. #6
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: Need help ASAP

    Create a new instance in the main class of Painting then use its methods accordingly, however look into how to use scanner too...

    Java.util.Scanner.next() Method Example

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Need help ASAP

    Since the instruction say specifically that, " . . . the gallery commission. This field cannot be set from outside the class," you are to conclude that: the field should be private, AND there are no mutator methods for this field. And then, since the commission is "computed as 20% of the price," the commission "should be set whenever the price is set," so include that in the setPrice() method.

    The describe() method is similar to a toString() method. Simple return a String from describe() that provides the required information in a useful format. You might do something like:

    Painting title: (title)
    Painting artist: (artist's full name)
    Medium: (medium)
    Price: (price)
    Commission: (commission)

    Try adding those to your program and come back when you need help.

Similar Threads

  1. I need your help ASAP :/
    By Exal in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 20th, 2012, 09:12 AM
  2. NEED HELP ASAP PLEASE
    By jaisan72980 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 13th, 2011, 10:29 AM
  3. Need help!!! Asap PLEASE!!!!
    By choloboy in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 11th, 2011, 05:28 AM
  4. Need help ASAP!!!!
    By Swiper in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 12th, 2011, 06:41 PM
  5. NEED HELP ASAP!!
    By JavaStudent_09 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 18th, 2010, 07:33 PM