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

Thread: can't solve this assignment

  1. #1
    Junior Member
    Join Date
    Jan 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default can't solve this assignment

    1-An airline company allows travelers to carry a specified weight. The program should calculate the ticket
    price according to the added weight in kilogram (the weight should always be less than 70 kilos):
     If the weight is less than 30 kilos the System generates a new facture with 8% discount.
     If the weight is between 30 and 50, the system says “Pass”.
     Otherwise, the program generates the overloaded weight and he should pay $ 20 per kilo.
    a) Define a double method called weightPrice that takes two integers as parameter; the weight and the
    ticket price then it should returns the new ticket price according to the entered values.
    b) Write a test program (main) that asks the user to enter the name, desired weight and the ticket price
    of each traveler and displays the ticket price for each one by invoking (calling) the weightPrice
    method.
    Sample Run:
    Enter the name of traveler: Rima
    Enter the ticket price and the weight: $1053 52
    Dear Rima you are overloaded by 2 kilo your new balance is:
    $1093


    2-We need to create a problem that states whether the lines are "parallel, perpendicular" the program asks
    the user to enter reads the coordinates (x,y) for four points 1, 2, 3 and 4 then finds the slops ():
    Hint:
     Two lines are parallel if they have the same slop.
     Two lines are perpendicular if the product of slops equals -1.

    Sample Run:
    Enter the coordinates (x,y) for point 1: 1 -1
    Enter the coordinates (x,y) for point 2: 4 5
    Enter the coordinates (x,y) for point 3: 3 2
    Enter the coordinates (x,y) for point 4: 5 6

    Slop of Line (AB) =2.0
    Slop of Line (CD) = 2.0
    Lines are parallel

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't solve this assignment

    What have you tried?
    Do you have any specific questions about the assignment?

    Please be sure to wrap all posted code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can't solve this assignment

    for question 1 I used this method :
    public static double weightoverticket (double ticket) {
    double weight = 0 ;
    double ticket1 = ticket + weight ;
    return ticket1;

    --- Update ---

    this all i did for question 1 :
    public static void main(String[] args) {
    Scanner input = new Scanner (System.in);
    System.out.println("Enter the name of traveler: ");
    String = sc.next ;

    System.out.println("enter ticket price and the weight: ");
    double ticket = input.nextDouble();
    double weight = input.nextDouble();

    for (weight < 30 ){
    double price =
    }



    }
    public static double weightoverticket (double ticket) {
    double weight = 0 ;
    double ticket1 = ticket + weight ;
    return ticket1;
    }
    }

    --- Update ---

    for question 2
    public static void main(String[] args) {
    Scanner input = new Scanner (System.in);
    System.out.println(" enter the coordinates (x, y) for point 1:");
    int x1 , y1 = input.nextInt();

    System.out.println(" enter the coordinates (x, y) for point2 :");
    int x2 , y2 = input.nextInt();

    System.out.println(" enter the coordinates (x, y) for point 3 ");
    int x3, y3 = input.nextInt();

    System.out.println(" enter the coordinates (x, y) for point 4 ");
    int x4 , y4 = input.nextInt();

    double S1 = ((y2 - y1) / (x2 - x1));
    double S2 = ((y4 - y3) / (x4 - x3));

    System.out.println("slop of line (AB) = " + S1);
    System.out.println(" Slop of line (CD) = " + S2);

    if(S1 == S2) { System.out.println("lines are perpendicular");
    }


    else if ((S1 * S2) = -1) ;{
    System.out.println("Lines are parallel"); }

    else { System.out.println("Lines aren't perpendicular or parallel");


    }
    }

    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't solve this assignment

    Do you have any specific java programming questions?
    Take each of the sentences that describe a feature of the program and include it in the program as a comment. Then work through them, writing the required code for that feature.

    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 answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jan 2024
    Posts
    40
    Thanks
    0
    Thanked 1 Time in 1 Post

    Lightbulb Re: can't solve this assignment

    Here are the solutions to both problems:

    Problem 1:

    ```java
    import java.util.Scanner;

    public class AirlineTicket {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    System.out.print("Enter the name of traveler: ");
    String name = scanner.nextLine();

    System.out.print("Enter the ticket price and the weight: ");
    double ticketPrice = scanner.nextDouble();
    int weight = scanner.nextInt();

    double newPrice = weightPrice(weight, ticketPrice);

    System.out.println("Dear " + name + ", your new balance is: $" + newPrice);
    }

    public static double weightPrice(int weight, double ticketPrice) {
    if (weight < 30) {
    double discount = 0.08 * ticketPrice;
    return ticketPrice - discount;
    } else if (weight >= 30 && weight <= 50) {
    return ticketPrice;
    } else {
    double extraWeight = weight - 50;
    double extraCost = 20 * extraWeight;
    return ticketPrice + extraCost;
    }
    }
    }
    ```

    Problem 2:

    ```java
    import java.util.Scanner;

    public class LineChecker {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    System.out.println("Enter the coordinates (x,y) for point 1:");
    int x1 = scanner.nextInt();
    int y1 = scanner.nextInt();

    System.out.println("Enter the coordinates (x,y) for point 2:");
    int x2 = scanner.nextInt();
    int y2 = scanner.nextInt();

    System.out.println("Enter the coordinates (x,y) for point 3:");
    int x3 = scanner.nextInt();
    int y3 = scanner.nextInt();

    System.out.println("Enter the coordinates (x,y) for point 4:");
    int x4 = scanner.nextInt();
    int y4 = scanner.nextInt();

    double slopeAB = calculateSlope(x1, y1, x2, y2);
    double slopeCD = calculateSlope(x3, y3, x4, y4);

    System.out.println("Slope of Line (AB) = " + slopeAB);
    System.out.println("Slope of Line (CD) = " + slopeCD);

    if (slopeAB == slopeCD) {
    System.out.println("Lines are parallel");
    } else if (slopeAB * slopeCD == -1) {
    System.out.println("Lines are perpendicular");
    } else {
    System.out.println("Lines are neither parallel nor perpendicular");
    }
    }

    public static double calculateSlope(int x1, int y1, int x2, int y2) {
    return (double) (y2 - y1) / (x2 - x1);
    }
    }
    ```

    These programs should address the problems as described. If you help with Java assignment and any further issues or need more clarification, feel free to ask There are resources online where you can find guidance for programming tasks, such as the one you're facing. You might consider exploring various programming forums or seeking help from online assignment help platforms like ProgrammingHomeworkHelp.com to navigate through your challenges effectively.

Similar Threads

  1. Behaviour of shortcut assignment and normal assignment for float
    By rakeshkr2 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 20th, 2014, 02:54 AM
  2. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  3. Solve Them Please
    By omath in forum Java Theory & Questions
    Replies: 1
    Last Post: December 25th, 2010, 04:26 PM
  4. solve it plz
    By tillu in forum Java Theory & Questions
    Replies: 4
    Last Post: December 17th, 2010, 01:45 PM
  5. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM