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: Java Program Help.

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Java Program Help.

    I'm on chapter 9(Inheritance and Polymorphism) of this textbook that teaches java. It's supposed to be a basic program but I am so lost with this. I need to see how this program should be written:

    Create Personal Acct and BusinessAcct classes that inherit the Account class presented Chapter 8(Classes and Object Oriented Development). A Personal account requires a minimum balance of $100. If the balance falls below this amount then $2.0 is charged(withdrawn) to the account. A business account requires a minimum balance of $500, otherwise the account is charged $10. Create Client Code to test the classes.


    I tried using strings and I messed it up, everytime I ran my program it would say I have an issue with how I connected them. could you show me how it could be done using strings correctly? Keep in mind, it might be easy for you but I started doing java only a couple of months ago so I learn a lot with trial and error and comparing to whatever I can spew out lol.

    Thanks so much everyone!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Program Help.

    Please post your code and the full text of the error messages you are getting and your questions.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Program Help.

    I'm at home right now and I don't have my program on me(it's on my school files). I'm planning on comparing them tomorrow.


    It's asking for this:


    "Create Personal Acct and BusinessAcct classes that inherit the Account class presented Chapter 8(Classes and Object Oriented Development). A Personal account requires a minimum balance of $100. If the balance falls below this amount then $2.0 is charged(withdrawn) to the account. A business account requires a minimum balance of $500, otherwise the account is charged $10. Create Client Code to test the classes."

    I suspected strings should work but it said something about them not connecting properly for this sequence. I'm not that good but I'm doing these practice problems daily but the way this book is so far, it's practically all basics but obviously i'm still a beginner. A really bad one at that lol.
    Last edited by thisguyrighthere; June 10th, 2012 at 09:36 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Program Help.

    Which thread do you want to use for this question? Select one to avoid confusion.

    Also posted at http://www.javaprogrammingforums.com...html#post68454
    and http://www.java-forums.org/new-java/...lp-please.html


    Your last post doesn't give any more information than the first one.
    Last edited by Norm; June 10th, 2012 at 09:51 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Program Help.

    I guess I'll use this thread? Like I said I don't have the code on me at the moment because it's on my school file, I won't have access to these forums tomorrow which I why I asked if someone knows how to write this and how it would be written. I want to compare them for tomorrow and see what I did wrong. I'm using JDK 5.0, I am not taking a class for this but trying to do self-learning anyways we do have accesible java programs in the labs and my computer has problems using jcreator or eclipse. Some mistakes that I remember it said I got were: Unused private methods, which I don't understad how. Something about how my methods not working. I think there was something about the imports too..
    I'm literally going from memory and I could have some things wrong.

  6. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java Program Help.

    I used strings in the program Exercise 1, which looks like this:

    01 import java.util.*;
    02 import java.lang.*;
    03
    04 public class Chapter_9_1 {
    05
    06 public static void main(String[] args) {
    07
    08 Scanner input = new Scanner(System.in);
    09 String answer;
    10 String Group1 = "Science Department:\nMembers: John - 1337H4X\n Jessica - 8192354\n Dick - 1102934\n"
    11 + " Bill - L291A72\n Sally - 88NG109";
    12 String Group2 = "English Department:\nMembers: Tyler - 81U03MW\n Gregory - 902RE76\n Tim - AA465D3\n"
    13 + " Frank - 876EH93\n Krystal - KF00UE1";
    14
    15 do{
    16 System.out.print("Enter a Faculty or an employee number or 'List' to see groups and members or 'quit' to quit: ");
    17 answer = input.nextLine();
    18 answer.trim();
    19 if(answer.equalsIgnoreCase("sciencedepartment") || answer.equalsIgnoreCase("science department")){
    20 System.out.println(Group1);
    21 }else if(answer.equalsIgnoreCase("englishdepartment") || answer.equalsIgnoreCase("englishdepartment")){
    22 System.out.println(Group2);
    23 }else if(answer.equalsIgnoreCase("list")){
    24 System.out.println(Group1);
    25 System.out.println(Group2);
    26 }else if(answer.equals("1337H4X")){
    27 System.out.println("John, Salary: $35,000, Department: Science, Job Title: Teacher");
    28 }else if(answer.equals("8192354")){
    29 System.out.println("Jessica, Salary: $35,000, Department: Science, Job Title: Teacher");
    30 }else if(answer.equals("1102934")){
    31 System.out.println("Dick, Salary: $15,000, Department: Science, Job Title: Part-time Teacher");
    32 }else if(answer.equals("L291A72")){
    33 System.out.println("Bill, Salary: $50,000, Department: Science, Job Title: Department Head/Teacher");
    34 }else if(answer.equals("81U03MW")){
    35 System.out.println("Tyler, Salary: $15,000, Department: English, Job Title: Part-time Librarian");
    36 }else if(answer.equals("902RE76")){
    37 System.out.println("Gregory, Salary: $35,000, Department: English, Job Title: Teacher");
    38 }else if(answer.equals("AA465D3")){
    39 System.out.println("Tim, Salary: $50,000, Department: English, Job Title: Department Head");
    40 }else if(answer.equals("876EH93")){
    41 System.out.println("Frank, Salary: $35,000, Department: English, Job Title: Teacher");
    42 }else if(answer.equals("KF00UE1")){
    43 System.out.println("Krystal, Salary: $35,000, Department: English, Job Title: Teacher");
    44 }else if(answer.equals("88NG109")){
    45 System.out.println("Sally, Salary: $35,000, Department: Science, Job Tital: Teacher");
    46 }
    47 System.out.println("");
    48 }while( !(answer.equalsIgnoreCase("quit")) );
    49
    50
    51
    52 }
    53 }



    This was the first exercise in Chap 9, I'm doing self learning so I don't really know where I'm going with it and I've only recently started. I suspected that I should use strings like the program above. (I haven't sent myself my corrupted code for the one I'm doing right now because my computer at home has problems running jcreator pro or eclipse, so I do everything in school. I want to see how this is done so I can compare it in the lab(I don't have a java class for this I'm literally trying to learn this for fun) and I can't access forums there so I was trying to get it tonight to compare tomorrow. Now I need help with exercise 2 which I'm guessing needs strings or me to extend classes.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Program Help.

    Please edit your post and remove the numbers from the first column. Also wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting.

    If you are getting error messages, please copy and paste the full text here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. how to run a java program..when the program using jar
    By miriyalasrihari in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2012, 10:04 AM
  2. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  3. My first Java Program
    By Creeeds in forum Java Theory & Questions
    Replies: 1
    Last Post: March 15th, 2011, 08:36 AM
  4. Help with this java program
    By Nemphiz in forum Object Oriented Programming
    Replies: 3
    Last Post: April 13th, 2010, 03:09 AM
  5. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 10:18 PM