Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Activity 1 Create a class named Coin with the following fields & methods - sideU

ID: 3672378 • Letter: A

Question

Activity 1

Create a class named Coin with the following fields & methods -

sideUp – an instance variable indicating the face value of the coin (e.g., “Heads” or “Tails”)

coinValue – an instance variable holding the actual coin value – $0.25 (quarter,) $0.10 (dime) and $0.05 (nickel)

Coin() –

A no-arg constructor

randomly assign the side of the coin that is facing up (“Heads” or “Tails”)

initialize it as a quarter

Coin(amount) –

constructor to set the coin value as quarter, dime or nickel

randomly assign the side of the coin that is facing up

Coin(amount, face) –

constructor to set the coin as quarter, dime or nickel

set its sideUp to the face value

toss()

tossing the coin

getSideUp() –

getter function

returns the value of the sideUp field

getCoinValue()

Activity 2

Design & implement a Java class named Uber (taxi-like service) with the following features -Schedule a pickup service by specifying

Name of customer

Pickup date & time

Number of passengers (to be picked up)

Distance (destination in term of miles, to make the class easier to implement)

Compute the total cost of a trip and display cost to console

$2 per mile for the 1st two passengers

$5 per additional passenger (starting with the 3rd passenger)

Activity 3

Implement a Driver class with the following functionalities –main()Menu-driven application allowing an user to –Toss a coin for a specified number of times & display its outcome

For example, an user could choose to toss a coin for 20 times

display the actual outcome: 12 “heads” & 8 “tails” (this is an example only)

Play the “Price-is-Right” gameStart a game with $0 in a jackpot as the game begins

Simulate a randomly tossing one of three coins (quarter, dime & nickel)

Add the value of the selected coin to the jackpot (e.g., $0.05, $0.10 or $0.25)

Repeat this process until

A maximum of 4 tosses has occurred (game over)

Total of more than $0.75 (User won!)

Schedule a ride for one of three Uber cars (4, 5 & 6 passengers)

A car can only be scheduled if it’s available

Display scheduled info to console once a car has been scheduled

Allow user to continue using this program for as long as they choose to

In general, students should also consider including & utilizing -

additional fields, methods, constructors, getters & setters to a class (if needed)

output formats, such as currency for any dollar amounts (values)

Scanner or JOptoinPane class for inputs

methods to make overall coding easy to read. main() should be calling others to perform tasksinput validations.

Explanation / Answer

Activity 1:

public class Coin
{
public static void main (String[] Args){
Scanner sc = new Scanner (System.in);
System.out.print("Enter a number");
int i = sc.nextInt();
}
public int q = 25;
public int d = 10;
public int n = 5;
public int p = 1;
public int quarters()
{
int quarters = (i/q);
return (quarters);
}
public int dimes()
{
int dimes = i - quarters()*25/d;
return (dimes);
}
public int nickels()
{
int nickels = i - (quarters()*25) - (dimes()*10)/n;
return (nickels);
}
public int pennies()
{
int pennnies = i - (quarters()*25) - (dimes()*10) - (nickels()*5)/p;
return (pennies);
System.out.println ("Your amount contain the following");
System.out.println ("quarters: " + quarters());
System.out.println ("dimes: " + dimes());
System.out.println ("nickels: " + nickels());
System.out.println ("pennies: " + pennies());
}}

Activity 2:

package taxi;

import java.util.LinkedList;

public class uberTaxi {

    private static final boolean begin = false;

    LinkedList<uberTaxi> taxi = new LinkedList<>();

    private String id;

    private Place dest;

    private Passenger current;

    public void setId(String id) {

        this.id = id;

    }

    public uberTaxi(String id)

{

        this.id = id;

    }

     

    public String toString()

{

        return id;

    }

     

    public void beginTrip(Place dest)

{

        boolean booked = true;

        for(uberTaxi i : taxi)

{

            if(this.begin == true)

                booked = true;

            else

                booked = false;

        }

    }

     

    public void terminateTrip()

{

        this.begin = false;

    }

    public String getId()

{

        return id;

    }

    public boolean equals(Object o)

{

         

        if(o == null ) return false;

        if( o instanceof uberTaxi)

{

uberTaxi other = (uberTaxi)o;

            return this.id == other.id;

        }

        return false;

    }

    public String getDest()

{

        return dest.toString();

    }

    public String getCurrent() {

        return current.toString();

    }

}

Activity 3:

public class Cab {

        private double companyTotalFare = 0.0;

        private double rate = 1.95;

        private double taxiTotalFare;

        private double tripFare;

        private int tripCounter;

        private int cabID;

        public Cab(int cabID) {

            this.cabID = cabID;

        }

        public void pickUp(double weight, boolean front) {

            if (front == true && weight < 40) {

                System.out.print("PASSENGER SEAT AIRBAG IS OFF IN CAB " + cabID);

            }

        }

        public void dropOff(int minutes) {

            tripFare = minutes * rate;

            taxiTotalFare = taxiTotalFare + tripFare;

            tripCounter++;

        }

        public void endOfShift() {

            companyTotalFare = companyTotalFare + taxiTotalFare;

        }

        public void displayStats() {

            System.out.print("Cab " + cabID + " had " + tripCounter + " trips and brought in $" + taxiTotalFare + " from the days $" + companyTotalFare);

        }

    }

    public class Passenger {

        private double weight;

        private boolean front;

        public Passenger(double weight, boolean front) {

            this.weight = weight;

            this.front = front;

        }

        public double getWeight() {

            return weight;

        }

        public boolean getFront() {

            return front;

        }

    }

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        Cab cab1 = new Cab();

        Cab cab2 = new Cab();

        while (true) {

            System.out.print("Cab ID (1111 or 2222): ");

            int cabID = input.nextInt();

            if (cabID != 1111 || cabID != 2222) {

                break;

            }

            System.out.print("Passenger weight: ");

            int weight = input.nextInt();

            System.out.print("Sitting in front seat (1 = YES, 0 = NO): ");

            boolean front = input.nextBoolean();

             

            pickUp(weight, front);

            System.out.print("How many minutes: ");

            int minutes = input.nextInt();

            dropOff(minutes);

            break;

        }

        cab1.endOfShift();

        cab2.endOfShift();

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote