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

Thread: java begginner homework help

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

    Default java begginner homework help

    I have to make 3 different programs to compile and the are the instructions.

    Instructions:
    Part One: Code a for loop to print the Celsius temperatures from 0-100 and the corresponding Fahrenheit temperature, and the approximate Fahrenheit temperature (2*Celsius + 32). Output should be in a table format:
    Celsius Fahrenheit Approximate Fahrenheit
    0 32.0 32.0
    1 33.8 34.0
    2 … …
    Part Two: Code a while loop to read in and total any number of positive numbers terminated with a 999 as a sentinel. If the user types in a negative number, do not add it to the total, just go on to the next number. Print the total, once, after the loop is finished. Run twice with different values and different number of values. Use easy numbers that I can add in my head but be sure to add some negative numbers!
    Part Three: Code a do while loop to ask a user to guess a number between 1-10, which has been randomly generated by the computer. After each guess, with an if statement, tell the user whether his guess was too high or too low and allow him to guess again until he guesses the correct number. Run twice.







    This is what I have, I'm really bad at programming so any help will be appreciated

    1. import java.util.Scanner;
    public class lab4a
    {

    public static void main(String[] args)
    {
    for(int celsius = 0; celsius<= 100; celsius++)
    {
    false = 9.0/5.0*celsius + 32;
    approximate = 2*celsius + 32;
    System.out.println(celsius + "\t" + false + "\t" + approximate);

    System.out.println("celsius \t Fahrenheit \t approximate Fahrenheit");
    while (condidtion);
    int i = 1;
    while(1 =10);
    {
    System.out.println(i);
    }
    }



    2. import java.util.Scanner;
    public class lab4b
    {

    public static void main(String[] args)
    {
    final int SENTINEL = 999;
    int n,amount = 0;
    System.out.println("Type in a number or 999 to stop");
    n = Scan.nextInt();
    while(n != SENTINEL)
    {
    if(n > 0)
    total = n;
    System.out.println("Type in a number or 999 to stop");
    n = Scanner.nextInt();
    }
    System.out.println(total);
    }


    3. import java.util.Scanner;
    public class lab4c
    {

    public static void main(String[] args)
    {
    int number;
    Scanner Scan = new Scanner(System.in);

    do
    {
    System.out.println("Enter number between 1 and 10");
    number = Scan.nextInt();
    }
    while(number < 1 || number > 10);
    System.out.println("right number");
    }
    }


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: java begginner homework help

    Do you have a question?

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: java begginner homework help

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Please post your code correctly per the above link and ask a specific question.

  4. #4
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: java begginner homework help

    I'm really bad at programming
    Do not put yourself down like that - the fact that you can write code in any form
    means you can program, and you are understanding the basic features of the
    language. Everyone has to start somewhere - no body is born gifted at anything.
    We were all beginners at one point

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

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

    Default Re: java begginner homework help

    [QUOTE=kiba;156317]I have to make 3 different programs to compile and the are the instructions.

    Instructions:
    Part One: Code a for loop to print the Celsius temperatures from 0-100 and the corresponding Fahrenheit temperature, and the approximate Fahrenheit temperature (2*Celsius + 32). Output should be in a table format:
    Celsius Fahrenheit Approximate Fahrenheit
    0 32.0 32.0
    1 33.8 34.0
    2 … …
    Part Two: Code a while loop to read in and total any number of positive numbers terminated with a 999 as a sentinel. If the user types in a negative number, do not add it to the total, just go on to the next number. Print the total, once, after the loop is finished. Run twice with different values and different number of values. Use easy numbers that I can add in my head but be sure to add some negative numbers!
    Part Three: Code a do while loop to ask a user to guess a number between 1-10, which has been randomly generated by the computer. After each guess, with an if statement, tell the user whether his guess was too high or too low and allow him to guess again until he guesses the correct number. Run twice.







    This is what I have, I'm really bad at programming so any help will be appreciated

     import java.util.Scanner;
      public class lab4a
      {
     
      public static void main(String[] args)
       {
          for(int celsius = 0; celsius<= 100; celsius++)
          {
             false = 9.0/5.0*celsius + 32;
             approximate = 2*celsius + 32;
             System.out.println(celsius + "\t" + false + "\t" + approximate);
     
             System.out.println("celsius \t Fahrenheit \t approximate Fahrenheit");
             while (condidtion);
             int i = 1;
             while(1 =10);
             {
                System.out.println(i);
             }
    }

     import java.util.Scanner;
    public class lab4b
    {
     
    public static void main(String[] args)
    {
    final int SENTINEL = 999;
    int n,amount = 0;
    System.out.println("Type in a number or 999 to stop");
    n = Scan.nextInt();
    while(n != SENTINEL)
    {
    if(n > 0)
    total = n;
    System.out.println("Type in a number or 999 to stop");
    n = Scanner.nextInt();
    }
    System.out.println(total);
    }


     import java.util.Scanner;
    public class lab4c
    {
     
    public static void main(String[] args)
    {
    int number;
    Scanner Scan = new Scanner(System.in);
     
     do
     {
     System.out.println("Enter number between 1 and 10");
     number = Scan.nextInt();
     }
     while(number < 1 || number > 10);
     System.out.println("right number");
    }
    }

  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: java begginner homework help

    Can you explain what problems you are having or ask some specific questions about the programs?

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

Similar Threads

  1. Please help am Begginner
    By KilasaMJ in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 7th, 2013, 08:41 AM
  2. Replies: 8
    Last Post: February 12th, 2013, 05:45 AM
  3. I am new to Java and a begginner
    By rjohn1997 in forum Member Introductions
    Replies: 1
    Last Post: February 18th, 2012, 09:07 AM
  4. [SOLVED] (Total begginner) simple GUI program nt displayin
    By moneyman021 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: January 10th, 2012, 06:26 PM
  5. Guessing Game begginner question
    By okupa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 20th, 2010, 07:31 AM