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 9 of 9

Thread: Homework for class, teacher's not helping

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Homework for class, teacher's not helping

    my code is looks like this:
    import java.util.*;
    public class PojectConvert{
     
    public void showFeet(double meters){
    double feet = meters * 3.281;
    System.out.println(meters+" meters is "+feet+" feet");
    }
    public void showMeter(double feet){
    double meters = feet * 0.3048;
    System.out.println(feet +" feet is "+ meters +" meters.");
    }
    public void showKilograms(double pounds){
    double kilograms = pounds * 0.454;
    System.out.println(pounds +" pounds is "+kilograms+" kilograms");
    }
    public void showPounds(double kilograms){
    double pounds = kilograms * 2.2808;
    System.out.println(kilograms+" kilograms is "+pounds+" pounds");
    }
    public void showGallons(double liters){
    double gallons = liters * 3.7854;
    System.out.println(liters+" liters is "+gallons+" gallons");
    }
    public void showLiters(double gallons){
    double liters = gallons * 0.26417;
    System.out.println(gallons+" gallons is "+liters+" liters");
    }
     
    public void menu(){
    System.out.print("Unit converter \n");
    System.out.println("1 Convert Length");
    System.out.println("2 Convert Weight");
    System.out.println("3 Convert volume");
    System.out.println("Enter in amount to convert: ");
    Scanner scan=new Scanner(System.in);
    double m=scan.nextDouble();
    boolean quit = false;
     
     
    do{
    System.out.println();
    System.out.println("1. Meters to feet");
    System.out.println("2. Feet to meters");
    System.out.println("3. pounds to kilograms");
    System.out.println("4. kilograms to pounds");
    System.out.println("5. Gallons to liters");
    System.out.println("6. Liters to gallons");
    System.out.println("7. I give up, I can't go on!");
    System.out.println();
    System.out.print("Enter your choice: ");
    int menu = scan.nextInt();
    switch(menu) {
    case 1:
    showFeet(m);
    break;
    case 2:
    showMeter(m);
    break;
    case 3:
    showKilograms(m);
    break;
    case 4:
    showPounds(m);
    break;
    case 5:
    showGallons(m);
    break;
    case 6:
    showLiters(m);
    break;
    case 7:
    quit = true;
    System.out.println("We lost another one.");
    break;
    default:
    System.out.println("Invalid Entry!");
    }
    }
     
     
    while (!quit);
     
    }
    public static void main(String[]args){
    PojectConvert convert=new PojectConvert();
    convert.menu();
    }
    }


    she wants it to be able to do this


    1. first you should ask the user what type of conversion he wants (1. length, 2. wight, 3. volume)
    int t=scan.nextInt();

    2. then you should use a switch statement to display only the units corresponding to that type of conversion:
    switch (t) {
    case 1:
    System.out.println("1. Meters to feet");
    System.out.println("2. Feet to meters");
    break;
    case 2:
    System.out.println("1. pounds to kilograms");
    System.out.println("2. kilograms to pounds");
    break;
    case 3:
    System.out.println("1. Gallons to liters");
    System.out.println("2. Liters to gallons");
    break;
    }

    3. Then you should ask for the conversion direction
    int direction= scan.nextInt();

    4. And then you should ask for the value to be converted:
    int m = scan.nextInt();

    5. Now you have all the info you need, you can write another switch statement to do the conversion:
    switch (t) {
    case 1: if (direction==1) showFeet(m);
    else showMeter(m);
    break;
    case 2:if (direction==1) showKilograms(m);
    else showPounds(m);
    break;
    case 3:....
    }

    The other thing you need to do is: every time you ask the user to make a selection, you have to make sure he enters a valid value.

    For example, when asking for the type of conversion (step 1 above) you have to make sure the value entered is 1, 2 or 3.
    So you need to use a loop:
    int t;
    do {
    System.out.println(....);
    t=scan.nextInt();
    } while (t!=1 && t!=2 && t!=3); // as long as t is different from 1, 2 and 3 the user will be asked to entered a value again

    i have no idea how to change my program to make all that work. can anyone help me out?


  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: Homework for class, teacher's not helping

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    Be sure the code has proper indentations for nested statements. All statements should not start in the first column.

    how to change my program to make all that work
    What does the program currently do?

    Take the items in the list one at a time.
    What problem do you have with the first one?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Homework for class, teacher's not helping

    It converts measurements.
    volume, length, weight.
    she wants it to be able to do this:h.jpg

  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: Homework for class, teacher's not helping

    You missed this part:
    Be sure the code has proper indentations for nested statements. All statements should not start in the first column.
    Unformatted code is hard to read and understand.

    What items on the list have you done?
    What is the next item on the list you are working on? What specific questions do you have about that item?

    It's not possible to read the image.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Homework for class, teacher's not helping

    its supposed to ask the user what type of converson does he/she want: 1. length, 2. weight, 3. volume. user chooses one then its suppoed to ask whether or not its should be, lets say user chooses 1, it will ask if the user wants to convert feet to meters or meters to feet. after that it'll ask user to enter how much to convert. enter in amount and then it'll show how much then it'll ask the user if he wants to perform another conversion or not.
    ive done the conversion parts and that works fine but i dont have it asking user all these things and i don't know how too. i'm very new at java programming, well programming in general.

  6. #6
    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: Homework for class, teacher's not helping

    Which one item are you working on now? Do them one at a time.


    You missed this part: You need to edit the code and fix the formatting.
    Be sure the code has proper indentations for nested statements. All statements should not start in the first column.
    Unformatted code is hard to read and understand.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Homework for class, teacher's not helping

    im working on setting up the user interface to it. and i dont know what you mean its hard to read. i read it just fine.

  8. #8
    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: Homework for class, teacher's not helping

    If you are the only one that will read it, then you can have it anyway you want.
    There are formatting standards that most of us follow and we'd like any code we work with to follow those standards.
    Code Conventions for the Java Programming Language: Contents

    im working on setting up the user interface
    What specific questions do you have?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Homework for class, teacher's not helping

    how do i change my format to match hers

  10. #10
    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: Homework for class, teacher's not helping

    Can you post the outputs from both programs so they can be compared? The image you posted was not readable.
    If all you have to worry about is making a pretty print out, you must be close to having the program working.
    I usually leave making the print out pretty until after I've got the logic and computations worked out.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Helping Understanding???
    By SuperDad in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2012, 06:53 PM
  2. gain of helping someone
    By luka316 in forum Member Introductions
    Replies: 1
    Last Post: February 6th, 2012, 07:53 AM
  3. The Rational Class Program [HOMEWORK HELP]
    By FCarlton24 in forum Object Oriented Programming
    Replies: 1
    Last Post: October 18th, 2011, 12:31 PM
  4. [Homework] Rational Class
    By burger king in forum Object Oriented Programming
    Replies: 2
    Last Post: January 13th, 2011, 09:15 PM